I have come across a system of ODE's that are written on vector/Matrix format such that; $Ax'=b$
For simplicity, say the system of ODE's has a vector $x'$ containing first order derivatives of 2-variables: $x$ and $y$ with respect to $t$ such that $x' = [x1' x2']^T $ with given initial conditions on $x1(0)=a0$ and $x2(0)=b0$. Vector $b$ and Matrix $A$ contain dependent variables of $x1, x2, t$ . How would you generally input such a system in Runge-Kutta 4 to solve for $x1$ and $x2$. A general method that will be applicable for a larger ODE system as well. I am using matlab.
For an actual example; suppose
$$\pmatrix{1+x1^2& t-x2\\2x1x2&1}\pmatrix{x1'\\x2'}=\pmatrix{3x1^2x2^2+7x2-4\\x1-x2t+x2}$$
For the given initial conditions $x1(0)=10$ and $x2(0)=20$
How do I input such a format of ODE's into Runge-Kutta-4th order to solve in Matlab, a way that will be general for any larger bigger size of ODEs in a format $Ax'=b$
Thank you very much for your help in advance
If you have procedures
A(t,x)andb(t,x)that return the system matrix and rhs vector (this is just as placeholders, one can construct these also in-place), then you can do (using python syntax)and use the usual RK4 step
etc.
Similarly in matlab
and the usual RK4 step
etc. There is also an
ode4procedure available in the Matlab studios (? Mathworks side with examples and tutorial videos), but it is for scalar examples, needs to be adapted for systems, mainly in growing the results array.