Solving a set of nonlinear DEs using Runge-Kutta

859 Views Asked by At

I have a series of differential equations similar to the form below

$\frac{d^2y}{dt^2}=C_1\frac{dy}{dt}+C_2y+C_3\frac{dx}{dt}+C_4x-C_5\sin(y)+C_6z$

$\frac{d^2x}{dt^2}=C_7\frac{dx}{dt}+C_8x+C_9\frac{dy}{dt}+C_{10}y-C_{11}\sin(x)$

$\frac{dz}{dt}=C_{12}z+C_{13}\frac{dy}{dt}+C_{14}v$

where the variables

$x(t),y(t),z(t),v(t)$

are all functions of time. I want to solve these sets of equations iteratively using something like a Runge-Kutta method to calculate $x(t)$ in response to $v(t)$. To my knowledge, the first step is to set up a series of first order DEs similar to

$y=x_1,~y'=x_2,~x=x_3,~x'=x_4,~z=x_5,~v=x_6$

$f_1(t,x_1,x_2,x_3,x_4,x_5,x_6) = \frac{dx_1}{dt}=x_2$

$f_2(t,x_1,x_2,x_3,x_4,x_5,x_6) = \frac{dx_3}{dt}=x_4$

$f_3(t,x_1,x_2,x_3,x_4,x_5,x_6) = \frac{dx_2}{dt}=C_1x_2+C_2x_1 + C_3x_4+C_4x_3-C_5\sin(x_1)+C_6x_5$

$f_4(t,x_1,x_2,x_3,x_4,x_5,x_6) = \frac{dx_4}{dt}=C_7x_4+C_8x_3+C_9x_2+C_{10}x_1-C_{11}\sin(x_3)$

$f_5(t,x_1,x_2,x_3,x_4,x_5,x_6) = \frac{dx_5}{dt}=C_{12}x_5+C_{13}x_2+C_{14}x_6$

and then assuming I have a known $v(t)$ input, I can solve these sets of equations iteratively.

I'm still a bit of a rookie to this stuff so bare with me. My first concern is, does it matter that I don't have a dynamical expression in terms of $\frac{dv}{dt} = \frac{dx_6}{dt} =~...$ ? If not, then have I set up my system properly such that I could apply a Runge-Kutta method to solve it for $x(t)$ ?

From here I would imagine applying Runge-Kutta would go something like

$x_{1,n+1} = x_{1,n}+\frac{h}{6}(k_1+2k_2+2k_3+k_4)$

$x_{2,n+1} = x_{2,n}+\frac{h}{6}(l_1+2l_2+2l_3+l_4)$

$x_{3,n+1} = x_{3,n}+\frac{h}{6}(p_1+2p_2+2p_3+p_4)$

$x_{4,n+1} = x_{4,n}+\frac{h}{6}(m_1+2m_2+2m_3+m_4)$

$x_{5,n+1} = x_{5,n}+\frac{h}{6}(q_1+2q_2+2q_3+q_4)$

$k_1 = f_1(t_n,x_{1,n},x_{2,n},x_{3,n},x_{4,n},x_{5,n},x_{6,n})$

$l_1 = f_2...$

$k_2 = f_1(t_n+\frac{h}{2},x_{1,n}+\frac{h}{2}k_1,x_{2,n}+\frac{h}{2}l_1,x_{3,n}+\frac{h}{2}p_1,x_{4,n}+\frac{h}{2}m_1,x_{5,n}+\frac{h}{2}q_1,x_{6,n}+?)$

$l_2 = ...$

I'm not sure how $v(t) = x_6$ fits into all of this. Any help is appreciated :) Sorry if I butcher some notation, maths isn't my forte.


EDIT

$y=x_1,~y'=x_2,~x=x_3,~x'=x_4,~z=x_5$

$f_1(t,x_1,x_2,x_3,x_4,x_5) = \frac{dx_1}{dt}=x_2$

$f_2(t,x_1,x_2,x_3,x_4,x_5) = \frac{dx_3}{dt}=x_4$

$f_3(t,x_1,x_2,x_3,x_4,x_5) = \frac{dx_2}{dt}=C_1x_2+C_2x_1 + C_3x_4+C_4x_3-C_5\sin(x_1)+C_6x_5$

$f_4(t,x_1,x_2,x_3,x_4,x_5) = \frac{dx_4}{dt}=C_7x_4+C_8x_3+C_9x_2+C_{10}x_1-C_{11}\sin(x_3)$

$f_5(t,x_1,x_2,x_3,x_4,x_5) = \frac{dx_5}{dt}=C_{12}x_5+C_{13}x_2+C_{14}v(t)$

RK method

set $x_1(0),x_2(0),x_3(0),x_4(0),x_5(0)$

$x_{1,n+1} = x_{1,n}+\frac{h}{6}(k_1+2k_2+2k_3+k_4)$

$x_{2,n+1} = x_{2,n}+\frac{h}{6}(l_1+2l_2+2l_3+l_4)$

$x_{3,n+1} = x_{3,n}+\frac{h}{6}(p_1+2p_2+2p_3+p_4)$

$x_{4,n+1} = x_{4,n}+\frac{h}{6}(m_1+2m_2+2m_3+m_4)$

$x_{5,n+1} = x_{5,n}+\frac{h}{6}(q_1+2q_2+2q_3+q_4)$

$k_1 = f_1(t_n,x_{1,n},x_{2,n},x_{3,n},x_{4,n},x_{5,n})$

$l_1 = f_2...$

$k_2 = f_1(t_n+\frac{h}{2},x_{1,n}+\frac{h}{2}k_1,x_{2,n}+\frac{h}{2}l_1,x_{3,n}+\frac{h}{2}p_1,x_{4,n}+\frac{h}{2}m_1,x_{5,n}+\frac{h}{2}q_1)$

$l_2 = ...$