grimster
- 39
- 0
this is the classic euler's method, but i'd like to modify it so that it can handle two-dimensional systems on the form
x'=...
y'=...
what needs to be done?
function [X,Y] = euler1(x,y,x1,n)
h=(x1-x)/n;
X=x;
Y=y;
for i=1:n
y=y+h*f(x,y);
x=x+h;
X=[X;x];
Y=[Y;y];
end
X
Y
plot(X,Y,x,y)
function yp = f(x,y)
yp=y*sin(x);
x'=...
y'=...
what needs to be done?
function [X,Y] = euler1(x,y,x1,n)
h=(x1-x)/n;
X=x;
Y=y;
for i=1:n
y=y+h*f(x,y);
x=x+h;
X=[X;x];
Y=[Y;y];
end
X
Y
plot(X,Y,x,y)
function yp = f(x,y)
yp=y*sin(x);