Comparing Analytic and Approximate Solutions Using Euler's Method in Matlab

Click For Summary

Discussion Overview

The discussion revolves around the use of Euler's Method to approximate the solution of a differential equation and the comparison of this approximate solution with the analytic solution, particularly focusing on the case when the parameter b is set to zero. Participants explore the implications of time step size on the accuracy of the approximation.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • The initial poster describes their implementation of Euler's Method and the expected overlap of the analytic and approximate solutions when b=0.
  • Some participants suggest trying a smaller time step to improve the approximation's accuracy.
  • One participant challenges the initial poster's understanding of their professor's statement regarding the relationship between time step size and the accuracy of the Euler method.
  • There is a suggestion to consider plotting the results on a logarithmic scale for better visualization of differences.

Areas of Agreement / Disagreement

Participants express differing views on the professor's statement about the analytic solution and the effects of time step size on the Euler method's accuracy. There is no consensus on the interpretation of the professor's claim or the implications of changing the time step.

Contextual Notes

Participants note that changing the time step in the Euler method can lead to different results, indicating that the accuracy of the approximation is dependent on this choice. The discussion does not resolve the misunderstanding regarding the professor's statement.

Bashyboy
Messages
1,419
Reaction score
5

Homework Statement


Hello, I am working on a problem involves my using the Euler Method to approximate the differential equation \displaystyle \frac{df}{dt} = af(t) - b[f(t)]^2, both when b=0 and when b is not zero; and I am to compare the analytic solution to the approximate solution when b=0.


Homework Equations





The Attempt at a Solution



Here is my code
Code:
f(1) = 1000;
t(1)= 0;
a = 10;
b = 0 ;
dt = 0.01;
Nsteps = 10/dt;

for i = 2:Nsteps
    t(i) = dt + t(i-1);
    %f(i) = f(i-1)*(1 + dt*(a - b*f(i-1)));
    f(i) = f(i-1)*(1 + a*dt); 
end

plot(t,f,'r-')

hold on

fa= a*exp(a*t)

plot(t,fa,'bo')

When b=0, the solution to the differential equation is f(t) = c e^{at}. When I apply the initial condition, that f(0) = 1000, then the differential equation becomes f(t) = 1000 e^{at}. Now, my professor said that a differential equation has an analytic solution, no matter what time step you use, the graph of analytic solution and the approximation (Euler's Method) will coincide. So, I expected the two graphs to overlap. I attached a picture of what I got.

Why did this occur? In order to get the graphs to overlap, I changed 1000 to 10, which is a, just for the heck of it. When I did this, the two overlapped. I don't understand. What am I doing incorrectly?
 

Attachments

  • !.png
    !.png
    1.3 KB · Views: 523
Physics news on Phys.org
Have you tried a smaller time step?
 
Yes, lewando. I actually just tried it, and it made the approximation closer to the analytic solution. Thank you for the suggestion.
 
You should have a chat with that professor then... :wink:
 
Bashyboy said:
Now, my professor said that a differential equation has an analytic solution, no matter what time step you use, the graph of analytic solution and the approximation (Euler's Method) will coincide.

I think you misunderstood what your professor said. That quote is so wrong that it's very hard to believe it is what your prof actually meant.

If you change the time step in the Euler method you are using, you will definitely get different results. As somebody else said, try a smaller step size.

Also, it might be better to plot the y-axis of your graphs on a log scale.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K