# Numerical Analysis: Using Forward Euler to approximate a system of Differential Equations

I'm giving the following system of ODE's: \begin{array} d \begin{bmatrix} x^{'}(t) \\ y^{'}(t) \end{bmatrix} & = & \begin{bmatrix} 7 & -1\\-1 & 2 \end{bmatrix}\cdot \begin{bmatrix} x(t)\\ y(t) \end{bmatrix} \end{array} with an arbitrary initial condition of $\vec{x}(0) = \vec{x}_0$.

We are asked to solve the linear system using the Forward Euler Method using MATLAB and then plotting our solution.

Now I am familiar with how to solve the closed form of this IVP using Fundamental Theorem of Linear Systems and Spectural Decomposition. However, we are asked to solve the problem numerically using Forward Euler.

• The Forward Euler Method is derived using the forward difference approximation. In this case since we are dealing with matrices and vectors:

\begin{eqnarray} \frac{\vec{x}_{n+1}-\vec{x}_n}{\Delta t} \approx A\vec{x}_n \end{eqnarray} which can be rewritten as \begin{eqnarray} \vec{x}_{n+1} = \vec{x}_n + \Delta t A\vec{x}_n \end{eqnarray}

In order to advance time steps, the second equation stated above is recursively applied as

\begin{eqnarray} \vec{x}_{1} &=& \vec{x}_0 + \Delta t A\vec{x}_0\\ \vec{x}_{2} &=& \vec{x}_1 + \Delta t A\vec{x}_1\\ \vec{x}_{3} &=& \vec{x}_2 + \Delta t A\vec{x}_2\\ &\vdots&\\ \vec{x}_{n} &=& \vec{x}_{n-1}+ \Delta t A\vec{x}_{n-1}\\ \end{eqnarray}

This is where I am stuck. I am not familiar with MATLAB so I am not sure how to go about coding the problem to do what I desire. Especially when I don't have a set initial condition. (I should add that I do know how to create matrices, vectors, and do some calculations in MATLAB, but nothing of this level... yet).

I am familiar with core basics of programming languages like C++ and Python and I am roughly familiar with the meta-language Mathematica; therefore, I am sure I will catch on right away. I can more a less guess that my algorithm will require defining my starting point, my $2\times 2$ matrix $A$, the number of iterations, my time step, and my starting and ending value for $t$. (The professor didn't specify on the assignment so I am just going to say an interval from $0$ to $10$ should do). I would then apply a loop (most probably a for-loop) to recursively apply forward Euler for $n$th number of times. I would assume I would need to create a dynamical array to store all the values as I go along, that way I can eventually call them up when I decide to plot my data points.

I was wondering if someone could give me an idea and how to start the code.

Thank You for taking the time to read my post. I greatly appreciate any suggestions, comments, or feedback. Have a wonderful day.

## 1 Answer

for i=1:n
x(n+1) = x(n)+dt*A*x(n)
end


should do the trick, you need of course initialize the vectors and matrices.