# Is there a way to solve differential equation $\dot x = f(x,u)$ with linear algebra?

I'm going to solve a ODE system on the form: $$\dot x(t) = f(x(t),u(t))$$

Where an example of the system migth look like:

$$(\dot x_1(t) ,\dot x_2(t) ,\dot x_3(t))= a x_1(t) + b x_2 (t) + c x_3 (t) + d u(t) e x_2 (t) + f u(t) g x_1(t) + h sin(x_3(t))$$

The parameters $$a,b,c,d,e,f,g,h$$ are known and $$x_1,x_2,x_3,\dot x_1,\dot x_2,\dot x_3$$ are known for $$t = 0$$ and $$u$$ are known $$\forall t$$. Also $$u$$ is constant $$\forall t$$.

So is there a way to to find $$x_1,x_2,x_3$$ by using linear algebra? I just got started with Armadillo and C++, then I realize that Armadillo does not have and ODE solver. But Armadillo is optimized for linear algebra.

• The example system seems to be written incorrectly. On the left, you should have $(x_1'(t), x_2'(t), x_3'(t))$. You could implement your own ODE solver (using a method like RK4), or alternatively you could probably find a C++ library that provides an ODE solver that you can use. Here's a thread with some library suggestions: stackoverflow.com/questions/7622286/… – littleO Dec 17 '18 at 0:12
• I'm used to write the x_1 with dots above. Is Euler better? – Daniel Mårtensson Dec 17 '18 at 0:14
• The issue is not with the dots, it's that on the left you've written a sum $x_1'(t) + x_2'(t) + x_3'(t)$ rather than a vector $(x_1'(t), x_2'(t), x_3'(t))$. If I understand correctly, $x$ is a vector-valued function with component functions $x_1, x_2$, and $x_3$. The dot notation is fine. – littleO Dec 17 '18 at 0:16
• Okej! Maybe I should change. Who is fastest to compute, Euler or RK4? – Daniel Mårtensson Dec 17 '18 at 0:19
• Euler's method is easier to implement, but RK4 is much more accurate. I suspect that RK4 will be faster because you will be able to use a larger stepsize to achieve the same accuracy. There are more sophisticated methods such as RK45 that use adaptive stepsizes, and also implicit methods that are useful for "stiff" ODEs (for which explicit methods like Euler or RK4 might fail). You can implement RK4 pretty easily, but, using an ODE library is probably a good way to go. – littleO Dec 17 '18 at 0:31