Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value. It is an explicit method for solving initial value problems (IVPs), as described in [[wp:Euler method|the wikipedia page]].
The ODE has to be provided in the following form:
:::
with an initial value
:::
To get a numeric solution, we replace the derivative on the LHS with a finite difference approximation:
:::
then solve for :
:::
which is the same as
:::
The iterative solution rule is then:
:::
where is the step size, the most relevant parameter for accuracy of the solution. A smaller step size increases accuracy but also the computation cost, so it has always has to be hand-picked according to the problem at hand.
'''Example: Newton's Cooling Law'''
Newton's cooling law describes how an object of initial temperature cools down in an environment of temperature :
:::
or
:::
It says that the cooling rate of the object is proportional to the current temperature difference to the surrounding environment.
The analytical solution, which we will compare to the numerical approximation, is
:::
;Task:
Implement a routine of Euler's method and then to use it to solve the given example of Newton's cooling law with it for three different step sizes of:
:::* 2 s
:::* 5 s and
:::* 10 s
and to compare with the analytical solution.
;Initial values:
:::* initial temperature shall be 100 °C
:::* room temperature shall be 20 °C
:::* cooling constant shall be 0.07
:::* time interval to calculate shall be from 0 s ──► 100 s
A reference solution ([[#Common Lisp|Common Lisp]]) can be seen below. We see that bigger step sizes lead to reduced approximation accuracy.
[[Image:Euler_Method_Newton_Cooling.png|center|750px]]