**Differential equations**

Differential equations are quite important in engineering and natural sciences such as physics. At university students learn how to handle differential equations analytically but usually we have to use numerical methods to solve them. We can use Euler’s method and Runge-Kutta method. The latter yields better results, it is more accurate.

This is the usual form of a first order differential equation. How to handle these equations? We are able to approximate the derivative, we just have to use the concrete definitian of finite difference:

This formula is quite helpful. We are able to get rid of the derivative and find a method to be able to approximate the solution of the differential equation. We just have to use this iterative method:

What’s very important is that we need an initial condition. For example **x=0**, **y=1** which means **y(0)=1**. It is a valid initial condition.

**Euler’s method**

So far we have discussed how to handle differential numerically. We just have to apply the finite difference approach. It is basically the Euler’s method. So we have to start with the initial condition **y(0)=1** in our example. We have to define a **h** step size. We keep incrementing **x** by this **h** parameter. On every iteration we use the iterative formula to calculate the **y** value for this given **x**. Let’s solve the **dy(x)/dx=y** differential equation:

In this case we set the** h=2**. That’s why the **x** values have the values **0, 2, 4, 6**. What about the **y** values? We have to use the iterative formula above the table to get the values accordingly. What about the derivative? We know that** dy/dx=y**, so in this case it is the same as **y**.

**Source code**

As you can see, implementing the Euler’s method is quite simple. We just have to use the iterative formula we have been discussing. We have the initial conditions: thats why **x=0** and **y=1**. The step size in this case is the **dx**. What is the problem with Euler’s method? It is not accurate. A better approach is the Runge-Kutta method.