i am being asked to solve a problem by eulers method

URGENT HELP NEEDED
given y'=y, and y(0)=2 on [0,1], exact sulution: y=2*exp(x) i was told to plot the exact solution vs Eulers solution on the same graph. Use a while loop to determine the value of n(number of intervals) to guarantee the maximum error between the exact solution and Euler is less than 10^-2.

Réponses (1)

James Tursa
James Tursa le 28 Juil 2017
Modifié(e) : James Tursa le 28 Juil 2017
See Euler's Method here:
https://en.wikipedia.org/wiki/Euler_method
Look at the examples. An outline to get you going on the basic method is:
n = number of intervals <-- you fill this in
h = some stepsize <-- you fill this in
y = zeros(1,n+1);
t = zeros(1,n+1);
y(1) = some initial value <-- you fill this in
t(1) = some initial value <-- you fill this in
for k=2:n+1
y(k) = y(k-1) + SOMETHING; <-- you fill in the SOMETHING
t(k) = t(k-1) + SOMETHING; <-- you fill in the SOMETHING
end
Then plot the results against the exact solution.

2 commentaires

the problem is finding n(the number of intervals). it says to use a while loop to determine that.
Get the basic Euler's method working first. Then you can worry about wrapping the code up in a while loop to determine n per the desired tolerance.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by