0

I have a non-linear differential system :

  • (1) f''(t)=r(f(t)) and
  • (2) g''(t)=s(f(t),g(t))

where s(f(t),g(t)) may be s(f(t),g(t))=f(t)*g(t) or s(f(t),g(t)) = cos(f(t))*sin(g(t)) ... and we know g and s. I want to solve this system with Python but I don't know how. The first equation can be easily solved with scipy.integrate.odeint but I don't know how to solve the whole system.

sanyassh
  • 8,100
  • 13
  • 36
  • 70
Zhao
  • 1
  • 2
  • I think you mean that `r` and `s` are known? How did you define the first order system for the first equation and why was that not applicable to the extended system? – Lutz Lehmann May 18 '19 at 20:15

1 Answers1

1

If you have given r and s as functions, then you can build the system as

def derivs(t,u): f,g, df, dg = u; return [ df, dg, r(f), s(f,g) ]

and

u = odeint(derivs, u0, t_array, tfirst=True)

f,g, df, dg = u.T
plt.plot(t_array,f, t_array,g)

or whatever you want to do with the solution.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • Thank you for your answer. Can you tell me please what is the order of the initial conditions ? Is u0=[f(t_array[0]),g(t_array[0]),df(t_array[0]),dg(t_array[0])] ? – Zhao May 18 '19 at 21:27
  • Yes, exactly that. Of course, you could chose a different order of components, you just have to do it consistently everywhere. – Lutz Lehmann May 18 '19 at 21:57