Home > Enterprise >  How to know the middle trajectory of ode solver in python
How to know the middle trajectory of ode solver in python

Time:11-16

I am using Python package to solve ODE equation. However, I need to know the middle state or in other words the trajectory of ode solver in python.

from scipy.integrate import odeint
   solution = odeint(fun,initial_values,tspan)

Here the output just gives me me the final state, not the middle steps, How can I get the middle steps?

Thanks

I have tried this

   solution = odeint(fun,initial_values,tspan)

The output gives me the initial values and the final output. How can I know the steps between the initial values and the final output?

[[ 0.5 -0.5] [5 5]]

CodePudding user response:

The third parameter of odeint is the set of time values at which you want the solution to be returned. In your case, put the desired times in your tspan argument. E.g. tspan = np.linspace(0, 1, 101) will get you the solution at t=0.0, 0.01, 0.02, ..., 0.99, 1.0. Take another look at the example in the docstring, where it shows the plot of a solution that was generated with t = np.linspace(0, 10, 101).

  • Related