Scipy odeint (LSODA) gives inaccurate results; same code fine in MATLAB ode15s/ode23s

Christian Gollwitzer auriocus at gmx.de
Sat Nov 7 01:54:48 EST 2015


Am 06.11.15 um 23:01 schrieb Abhishek:
> I have code that runs perfectly well in MATLAB (using ode15s or
> ode23s) but falters with Scipy odeint. The MATLAB code is for a
> specific case of the generalized Python code. Here I have tried to
> reproduce the specific case in Python. The logic in the code is
> airtight and the algorithm is sound. I have also specified small rtol
> and atol values, as well as a large mxstep.
>
> My code is below:
>
> [...Python code...]

>
> Why am I getting a "stiff-looking" graph in Python

What does "stiff-looking" mean? I only know stiff differential 
equations, but this leads to noisy results. Your plots are smooth.

> (http://i.stack.imgur.com/UGWSH.png), when MATLAB gives me a proper
> one (http://i.stack.imgur.com/F2jzd.jpg)? I would like to understand
> where the problem lies and how to solve it.

It is very hard to analyze such a problem, unless you also post the 
Matlab code and plot both solutions into a single graph.

What I can see at first is that the initial conditions can't be the 
same. Your Python graph starts around 10^7, while the Matlab graph 
starts at 10^5. WHat happens if you integrate a simpler system - say 
does it make sense to set some of the coefficients to zero and if you 
still get the same difference, can you simplify the program to expose 
the problem? How do you know that the Matlab code produces the correct 
answer?

	Christian



More information about the Python-list mailing list