Solving a system of coupled differential equations using scipy odeint

I am a little confused with odeint .

I found one example below to solve y"=ay + by' . So it seems that y[0] is a function, y[1] is the first derivative.

So, the following expression means y[1] =y' and y'[1]= a*y[0]+b*y[1] ?

If it were y[2], a*y[0]+b*y[1] , what would it mean?

I am a bit confused as the expression does not say the left side of the equation.

I also met expressions like [a(y[0], y[1]), b(y[0], y[1])] , but did not have the concept of a differential equation.

Here is one example:

 from scipy.integrate import odeint from pylab import * # for plotting commands def deriv(y,t): # return derivatives of the array y a = -2.0 b = -0.1 return array([ y[1], a*y[0]+b*y[1] ]) time = linspace(0.0,10.0,1000) yinit = array([0.0005,0.2]) # initial values y = odeint(deriv,yinit,time) figure() plot(time,y[:,0]) xlabel('t') ylabel('y') show() 
+4
source share
2 answers

Use Y in deriv instead of Y so that the rest of the answer is clear:

 def deriv(Y,t): # return derivatives of the array Y a = -2.0 b = -0.1 return array([ Y[1], a*Y[0]+b*Y[1] ]) 

The deriv function takes Y = [y, y'] as an input.

And he must derive his derivatives ( [y', y''] ).

y' = Y[1]

y'' = a*Y[0]+b*Y[1]

+1
source

Read the odeint documentation. It requires the following equation as an input equation:

dy / dt = func (y, t0, ...)

As far as I understand, the first element is array([ y[1], a*y[0]+b*y[1] ]) , i.e. y[1] is placed as y in dy/dt , which gives dy[1]/dt = y[2] . The second element, i.e. a*y[0]+b*y[1] , serves as func(y,t0,...)

+1
source

Source: https://habr.com/ru/post/1395070/


All Articles