what is wrong with this euler method code?

1 visualización (últimos 30 días)
Louis
Louis el 18 de Mzo. de 2014
Respondida: Sagar Damle el 18 de Mzo. de 2014
x=0;
y=0;
a=0;
b=5;
h=.01;
n=(b-a)/h;
for i=1:n
x(i)=a+(i-1)*h;
x(i+1)=a+i*h;
f = y(i)-5-exp(x(i)/2)sin*(5*x(i))+5*exp(x(i)/2)cos*(5*x(i));
y(i+1)=y(i)+h*f;
end
plot(x,y)
hold on
BTW how do I find exact solution and percent error?

Respuestas (1)

Sagar Damle
Sagar Damle el 18 de Mzo. de 2014
I think there is an error in line
f = y(i)-5-.........
Try this line instead-
f = y(i)-5*exp(x(i)/2)*sin(5*x(i))+5*exp(x(i)/2)*cos(5*x(i));

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by