MATLAB: Won’t run euler method

eulereuler methodnot working

x=0
y=1
a=0
b=5
h=0.1
n=(b-a)/h;
f(x(i),y(i))= -2*y(i)+2-e^(-4*x(i))
for i=1:n
x(i)=a+(i-1)*h
x(i+1)=a+i*h
y(i+1)=y(i)+h*f(x(i),y(i))
end
plot(x,y)
hold on

Best Answer

Is this what you were looking for?
x=0;
y=1;
a=0;
b=5;
h=0.1;
n=(b-a)/h;
for i=1:n
x(i)=a+(i-1)*h;
x(i+1)=a+i*h;
f = -2*y(i)+2-exp(-4*x(i));
y(i+1)=y(i)+h*f;
end
plot(x,y)
hold on