You are on page 1of 5

# Matlab Assignment

Math 222-003
Professor Choi

Equation:

Y=2x/(y+x2y) , y(0)=-2

Results:
x
0.5
1
1.5
2

Exact
h=0.1
h=0.05
h=0.025
2.10862 -2.0897 -2.0993
-2.104
2.32084 -2.3009 -2.3111
-2.316
2.52137 -2.5062
-2.514 -2.5177
2.6868 -2.6759 -2.6815 -2.6842

Codes:
X=0.5 with step size 0.1
x=zeros(5,1);
y=zeros(5,1);
x(1) = 0;
y(1) = -2;
for i=1:5
x(i+1) = x(i) +.1;
y(i+1) = y(i) +.1*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]
X=0.5 with step size 0.05
x=zeros(10,1);
y=zeros(10,1);
x(1) = 0;
y(1) = -2;
for i=1:10
x(i+1) = x(i) +.05;
y(i+1) = y(i) +.05*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]

## X=0.5 with step size 0.025

x=zeros(20,1);
y=zeros(20,1);
x(1) = 0;
y(1) = -2;
for i=1:20
x(i+1) = x(i) +.025;
y(i+1) = y(i) +.025*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]

## X=1.0 with step size 0.1

x=zeros(10,1);
y=zeros(10,1);

x(1) = 0;
y(1) = -2;
for i=1:10
x(i+1) = x(i) +.1;
y(i+1) = y(i) +.1*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]
X=1.0 with step size 0.05
x=zeros(20,1);
y=zeros(20,1);
x(1) = 0;
y(1) = -2;
for i=1:20
x(i+1) = x(i) +.05;
y(i+1) = y(i) +.05*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]

## X=1.0 with step size 0.025

x=zeros(40,1);
y=zeros(40,1);
x(1) = 0;
y(1) = -2;
for i=1:40
x(i+1) = x(i) +.025;
y(i+1) = y(i) +.025*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]

## X=1.5 with step size 0.1

x=zeros(15,1);

y=zeros(15,1);
x(1) = 0;
y(1) = -2;
for i=1:15
x(i+1) = x(i) +.1;
y(i+1) = y(i) +.1*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]
X=1.5 with step size 0.05
x=zeros(30,1);
y=zeros(30,1);
x(1) = 0;
y(1) = -2;
for i=1:30
x(i+1) = x(i) +.05;
y(i+1) = y(i) +.05*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]
X=1.5 with step size 0.025
x=zeros(60,1);
y=zeros(60,1);
x(1) = 0;
y(1) = -2;
for i=1:60
x(i+1) = x(i) +.025;
y(i+1) = y(i) +.025*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]

## X=2 with step size 0.1

x=zeros(20,1);

y=zeros(20,1);
x(1) = 0;
y(1) = -2;
for i=1:20
x(i+1) = x(i) +.1;
y(i+1) = y(i) +.1*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]
X=2 with step size 0.05
x=zeros(40,1);
y=zeros(40,1);
x(1) = 0;
y(1) = -2;
for i=1:40
x(i+1) = x(i) +.05;
y(i+1) = y(i) +.05*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]
X=2 with step size 0.025
x=zeros(80,1);
y=zeros(80,1);
x(1) = 0;
y(1) = -2;
for i=1:80
x(i+1) = x(i) +.025;
y(i+1) = y(i) +.025*(2*x(i)./(y(i)+x(i).^(2)*y(i)));
end
[x,y]