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.

Answers (1)

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 Comments

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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 28 Jul 2017

Commented:

on 29 Jul 2017

Community Treasure Hunt

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

Start Hunting!