Sympy ODE solver doesn't work for initial conditions

115 views
Skip to first unread message

Denys

unread,
Jun 3, 2015, 8:14:58 AM6/3/15
to sy...@googlegroups.com

hi, I'm trying to solve this ODE with the SymPy:

dsolve(Eq(Derivative(f(x), x), ((1+3 * x**2) / (3 * f(x) + 6))), f(x), ics={f(0):1})


and it it prints out


             _________________                _________________

            /         3                      /         3

          \/  C1 + 6*x  + 6*x              \/  C1 + 6*x  + 6*x

[f(x) = - -------------------- - 2, f(x) = -------------------- - 2]

                   3                                3

...it doesn't eliminate the constant C1, it doesn't use the initial condition. Is it a bug or wrong usage?

Francesco Bonazzi

unread,
Jun 4, 2015, 10:49:41 AM6/4/15
to sy...@googlegroups.com
Hi, you may try something like this, as a stopgap replacement:


In [1]: sol = dsolve(Eq(Derivative(f(x), x), ((1+3 * x**2) / (3 * f(x) + 6))), f(x), ics={f(0):1})

In [2]: sol
Out[2]:
                   _____________                      _____________    
            ___  
/       3                    ___   /       3          
         
\/ 6 *\/  C1 + x  + x              \/ 6 *\/  C1 + x  + x      
[f(x) = - ---------------------- - 2, f(x) = ---------------------- - 2]
                   
3                                  3                

In [6]: C1 = symbols("C1")

In [7]: solve(sol[0].args[1].subs(x, 0) - 1, C1)
Out[7]: []

In [8]: solve(sol[1].args[1].subs(x, 0) - 1, C1)
Out[8]: [27/2]

In [10]: sol[1].subs(C1, _[0])
Out[10]:
                 _____________    
         ___    
/  3       27    
       
\/ 6 *  /  x  + x + --    
             
\/            2      
f
(x) = ----------------------- - 2
                 
3      

Manoj Kumar

unread,
Jun 17, 2015, 3:05:23 AM6/17/15
to sy...@googlegroups.com
Hi,

This will not work since initial conditions in the case of ode solvers have been implemented only when the hint is of type power_series explicitly (since it is a requirement to express the solution in the form a power series)

HTH
Reply all
Reply to author
Forward
0 new messages