Skip to content
Advertisement

How to plot the graph obtained after using solve_ivp from scipy package to solve a set of differential equations in python

I’m using solve_ivp in python to solve a set of differential equations in state-space form.My code is as follows:

JavaScript

It shows error while using the normal plt.plot(t,X) command. How do I plot the graph between X and t? Please help

Advertisement

Answer

It’s a bit unclear what’s being calculated here, but checking solve_ivp‘s documentation, it seems the return value (sol in this case) has a number of fields. sol.t is the list of time points. sol.y are the calculated values for each of the 4 components of X, corresponding to each value of sol.t.

Here is a way to plot each of the 4 components (they all start at 0 because X0=(0,0,0,0)). The interpretation depends on the exact problem being solved.

JavaScript

resulting plot

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement