Consider the differential equation of the following linear oscillator:
x ¨ + 1 0 0 x = 0 ; x ( 0 ) = 1 ; x ˙ = 0
Compute the analytical solution to this equation. Following this, numerically integrate the above equation using the following two methods:
Method 1: Explicit Euler x ˙ ( k + 1 ) = x ˙ ( k ) + h x ¨ ( k ) x ( k + 1 ) = x ( k ) + h x ˙ ( k )
Method 2: Modified Euler x ˙ ( k + 1 ) = x ˙ ( k ) + h x ¨ ( k ) x ( k + 1 ) = x ( k ) + h x ˙ ( k + 1 )
Here k denotes the time index. Numerical integrate for two seconds. Let the analytical solution be x a , the explicit Euler solution be x e x p and the modified Euler solution be x m o d . At the time instant t = 2 compute the following expressions:
∣ x m o d − x a ∣ ∣ x e x p − x a ∣
Enter the result with a smaller magnitude as your answer. Take the time step h = 0 . 0 1 .
Bonus: Which numerical method would you prefer and why? Also, inspect the derivative signals of x and state your conclusions.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
@Karan Chatrath Mind if I post the stability follow-up to this?
Log in to reply
Thanks for the solution. I don't mind. Looking forward to the follow up
Log in to reply
It's up now. By the way, which would you choose as the favorite?
Log in to reply
@Steven Chase – Thanks. I will attempt it later today.
While I do appreciate the simplicity of explicit Euler, I prefer the modified algorithm. It is higher-order accurate and it is not very hard to program as well. The plot in the solution shows a remarkable difference between the two algorithms. This observation is primarily why I chose to make a problem out of it.
For oscillating systems such as this, I would suggest the Runge-Kutta family of methods are amazing. The problem with the Explicit Euler method is extremely apparent in oscillatory systems, where the energy increases very visibly, even with smaller time-steps.
In that way, every single numerical solving method for differential equations is better than Explicit Euler!
Problem Loading...
Note Loading...
Set Loading...
Simulation code and results are below. The modified Euler technique is more accurate because the position is updated based on the first and second derivatives from the previous time step, whereas the explicit Euler position is updated only with the first derivative. For the given time step, the performance difference is dramatic (see plot).
Note that for small time steps (ex: 1 0 − 5 ), all three methods agree closely. In practice, almost everything I program is for non-real-time applications in which speed is not important. So I generally prefer to run explicit Euler with a very small time step, due to the simplicity of the method. To check the results, I typically do multiple runs with time steps spanning two or three orders of magnitude, and if the results are the same each time, I am satisfied with the answer. In real-time or performance-sensitive applications, we could consider more sophisticated integration methods.
Another thing I want to look at is the numerical stability of the modified Euler method given the input signal x = A e α t . Given that input signal and a particular time step, what is the α region in the complex plane for which the method is stable? And how does that region compare to the explicit Euler stability region?