0

I want to solve a system of differential equations using the RK4 method, like given below. enter image description here

So for this case, I've to solve 3 differential equations-

d/dt(x0) = -2*x1

d/dt(x1) = -2* x0 -8* x1 -2√2*x2 and

d/dt(x2) = -2√2*x1 -14 *x2

Initial condition at t=0: x0, x1, x2 are -0.00076896, -0.01033249, -0.06899846 respectively.

Here, I am using M-matrix dimension 3x3 as an example. But for my actual problem, the dimension of the M matrix can be 100x100(M is a tridiagonal matrix). I can solve two coupled differential equations using this process but with this many equations, I have no idea how to even define them properly and solve using RK4.

Can someone help me? Thanks

JSCOY
  • 21
  • 2
  • 1
    numpy provides matrix and vector operations, use these, see for instance https://stackoverflow.com/a/65085500/3088138. In an advanced version, use scipy.sparse. Then use any RK4 integrator with a standard interface, like in https://stackoverflow.com/a/53650879/3088138 to get the numerical solution. – Lutz Lehmann Sep 21 '21 at 20:53
  • 1
    Or complete with time variable https://stackoverflow.com/questions/47711186/rk4-python-explanation/47719747#47719747 – Lutz Lehmann Sep 21 '21 at 21:01
  • Thank you for your comment. I have used this for function definition `def f(u): f0,f1,f2 = u return (np.dot(M,u))` It is solving for small dimensions, but what should I do for 100x100 case ? – JSCOY Sep 22 '21 at 04:41
  • 1
    You do not need the first statement, no need to unpack `u`, as the individual components are not used. Then changing the dimension is no problem. – Lutz Lehmann Sep 22 '21 at 05:17
  • Oh, I understood. Thank you very much for all your help! – JSCOY Sep 22 '21 at 06:22

0 Answers0