won't run euler method

3 views (last 30 days)
Louis
Louis on 17 Mar 2014
Commented: Louis on 18 Mar 2014
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

Accepted Answer

Sara
Sara on 17 Mar 2014
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
  1 Comment
Louis
Louis on 18 Mar 2014
Thanks, I can finally finish my project!!!!

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 17 Mar 2014
In your statement
f(x(i),y(i))= -2*y(i)+2-e^(-4*x(i))
you have not defined "i".
If you are trying to define a function, that is not the correct syntax.
You could use
f = @(x,y) -2*y + 2 - exp(-4*);

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!