You can call evalf() on the expression before lambdifying to reduce the numbers to floating point numbers.
Aaron Meurer On Tue, Dec 6, 2016 at 4:53 PM, Dabitto <[email protected]> wrote: > > Hi , > > The ODE solver gives me the following answer: > > > > If I try to evaluate that with lambdify is impossible because values too > large. How can I tell to the solver to reduce the fraction ? > > Thank you for your support. > > Dabitto. > > > The script is below: > > import pylab > import numpy as np > import serial > import time > import struct > import csv > import sys > import datetime > > import sympy as sym > > from IPython.display import display > > sym.init_printing() #pretty print > > t = sym.symbols('t',real=True) > m = sym.symbols('m',real=True) > k = sym.symbols('k',real=True) > v = sym.symbols('v',real=True) > q = sym.symbols('q',real=True) > y = sym.Function('y') > a0, b0 = sym.symbols('a0, b0', real=True) > > mass = 10.0 > friction = 2.0 > spring = 40.1 > final = 0.0 > position_init = -0.1 > speed_init = 2.0 > > Eq2 =sym.Eq(sym.diff(y(t),t,2)+sym.diff(y(t),t,1)*friction/ > mass+y(t)*spring/mass,final) > print('') > print('ODE:') > display(Eq2) > > print('Generic solution:') > y_sl0=sym.dsolve(Eq2, y(t)).rhs # take only right hand side > display(sym.Eq(y(t), y_sl0)) > > # Initial conditions: > cnd0 = sym.Eq(y_sl0.subs(t, 0), position_init) # y(0) = a0 > cnd1 = sym.Eq(y_sl0.diff(t).subs(t, 0), speed_init) # y'(0) = b0 > > # Solve for C1, C2: > C1, C2 = sym.symbols("C1, C2") # generic constants > C1C2_sl = sym.solve([cnd0, cnd1], (C1, C2)) > > # Substitute back into solution: > y_sl1 = sym.simplify(y_sl0.subs(C1C2_sl)) > print("Solution with initial conditions:") > display(sym.Eq(y(t), y_sl1)) > > > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/sympy/8f8bb29b-6d5e-42b4-8ca2-c80eda1997ad%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/8f8bb29b-6d5e-42b4-8ca2-c80eda1997ad%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6KkDNvFhWhvDO0F_a4DPTB9_mR8TBEmaS6XLJS4t5Zc4g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
