C++ Alternatives to Euler's Method for Solving ODEs
- Thread starter ChrisVer
- Start date
-
- Tags
- C++ Euler's method Method Odes
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 2K views
Discussion
Physics news on Phys.org
fluidistic
Gold Member
- 3,934
- 286
Yes there are. For example Runge-Kutta methods. https://en.wikipedia.org/wiki/Runge–Kutta_methods
Mentor
- 15,788
- 10,667
There are also variations on Euler's method that are good if the solution is periodic or not:
http://en.wikipedia.org/wiki/Linear_multistep_method
Others I've seen are euler-richardson and there are more listed here:
http://www.compadre.org/osp/document/ServeFile.cfm?ID=9373&DocID=1268&Attachment=1
http://en.wikipedia.org/wiki/Linear_multistep_method
Others I've seen are euler-richardson and there are more listed here:
http://www.compadre.org/osp/document/ServeFile.cfm?ID=9373&DocID=1268&Attachment=1
Science Advisor
- 3,372
- 465
I am not sure if that can be actually an answerable question, but I will give it a try...
Is it possible for the Euler method to give a deviation from the actual solution of around 0.5%
While the RK4 method gives a deviation of 0.8 *10^(-9) % ?
The correction seems enormous if you asked me...
I solved for the two methods the ODE:
[itex]\frac{dy(x)}{dx} = ay(x)[/itex]
which I know the exact solution: [itex]y(X)= y_0 e^{aX}[/itex]
For [itex]y_0=1[/itex] and [itex]a=1[/itex] and an interval [itex]X=1[/itex] this is just the value of e=2.71828...
Euler method for 100 steps gave me 2.70481 ( [itex]\frac{|e-2.70481|}{e} \approx 0.005[/itex] ) and the RungeKuta4 for 100 steps gave me 2.71828 ( [itex]\frac{|e-RK4|}{e} \approx 8 \times 10^{-12}[/itex]) -i got the last result by letting the program do the calculation of the deviation for me. Otherwise the values as given are indistinguishable.
Not to say that things get even worse for EulerMethod when I apply it for example at [itex]y(X)=10 e^{60}[/itex] where the EM gives almost double the actual value (86% off) while the RK4 keeps itself safe (10^-6 % off).
Is it possible for the Euler method to give a deviation from the actual solution of around 0.5%
While the RK4 method gives a deviation of 0.8 *10^(-9) % ?
The correction seems enormous if you asked me...
I solved for the two methods the ODE:
[itex]\frac{dy(x)}{dx} = ay(x)[/itex]
which I know the exact solution: [itex]y(X)= y_0 e^{aX}[/itex]
For [itex]y_0=1[/itex] and [itex]a=1[/itex] and an interval [itex]X=1[/itex] this is just the value of e=2.71828...
Euler method for 100 steps gave me 2.70481 ( [itex]\frac{|e-2.70481|}{e} \approx 0.005[/itex] ) and the RungeKuta4 for 100 steps gave me 2.71828 ( [itex]\frac{|e-RK4|}{e} \approx 8 \times 10^{-12}[/itex]) -i got the last result by letting the program do the calculation of the deviation for me. Otherwise the values as given are indistinguishable.
Not to say that things get even worse for EulerMethod when I apply it for example at [itex]y(X)=10 e^{60}[/itex] where the EM gives almost double the actual value (86% off) while the RK4 keeps itself safe (10^-6 % off).
Last edited:
Science Advisor
- 3,372
- 465
DrClaude said:The Euler method can be unstable and should be avoided.
I also tried the example wiki uses: [itex]y=1 \cdot e^{-2.3 X}[/itex] with 5 (as I see steps)...
The exact solution for X=5 is [itex]10^{-5}[/itex]
Euler gives a very bad result indeed [itex]=-3.71[/itex]...
RK4 gives a bad result as well [itex]0.0263[/itex]...
Things become better for RK4 at >20 steps...
Similar threads
Undergrad Solving Schrödinger's equation for a hydrogen atom with Euler's method
- Tuca
- · Replies 2 ·
- Quantum Physics
- Replies
- 2
MATLAB Euler's Method in MATLAB: Solving for dy/dt = cos(y)
- JCienfuegos
- · Replies 1 ·
- MATLAB, Maple, Mathematica, LaTeX
- Replies
- 1
Undergrad Real life application of Euler's method/numerical method
- ChanYoung Park
- · Replies 11 ·
- Differential Equations
- Replies
- 11
How Accurate is Euler's Method for Solving Differential Equations?
- karush
- · Replies 1 ·
- Calculus
- Replies
- 1
Undergrad On the approximate solution obtained through Euler's method
- psie
- · Replies 1 ·
- Differential Equations
- Replies
- 1
MATLAB Solving second-order ODEs with Euler's method in MATLAB
- vendtfan
- · Replies 3 ·
- MATLAB, Maple, Mathematica, LaTeX
- Replies
- 3
9.1.14 Use Euler's method to calculate
- karush
- · Replies 2 ·
- Calculus
- Replies
- 2
High School Euler's method for second order DE
- Karol
- · Replies 5 ·
- Differential Equations
- Replies
- 5
Euler's method for coupled ODE's
- gfd43tg
- · Replies 2 ·
- Calculus and Beyond Homework Help
- Replies
- 2
Euler's Method and Planetary Motion
- antintheagora
- · Replies 1 ·
- Introductory Physics Homework Help
- Replies
- 1