MATLAB: My Euler Method Error

my euler method

Question:
Consider the initial value problem: dy/dt= eāˆ’t āˆ’ 3y, y(āˆ’1) = 0.
Part a: Use the MATLAB program myeuler.m from Chapter 8 to compute the Euler Method approximation to y(t) with step size h = 0.5 and n = 4 steps. The program will generate a list of ordered pairs (ti, yi). Use plot to graph the piecewise linear function connecting the points (ti, yi). Repeat with h = 0.2 and n = 10.
Code:
f = @(t,y) exp(-t)-3*y;
[t, y] = myeuler(f,-1,0,1,4);
plot(t,y)
[t, y] = myeuler(f,-1,0,1,10)
plot(t,y)

Best Answer

Your code executes without error when I try it without change.
Make sure that the code you posted for myeuler is saved in myeuler.m and that the directory it is saved in is on your MATLAB path (for example if you are cd'd to the same directory)