You are on page 1of 1

syms x y

format short
clc
f=(x+y+1)^2-(x+y-1)^2;
f1=diff(f,x)+diff(f,y)*f;
f2=inline(f);
f3=inline(f1);
n=1000;
xo=0;
x1=2;
yo=7/4;
h=(x1-xo)/n;
iter=1;
disp('---i------------x---------------y---');
fprintf('%4.0f %14.4f %14.4f\n',iter,xo,yo);

for i=h+xo:h:x1
y=yo+h*f2(xo,yo)+(h^2/2)*f3(xo,yo);
xo=i;
yo=y;
iter=iter+1;
fprintf('%4.0f %14.4f %14.4f\n',iter,xo,yo);
end

You might also like