Implement the Eulers method in MATLAB and solve the problem
Implement the Euler’s method in MATLAB and solve the problem y\'=x^2+y^2; y(0) = 4, using different steps for the approximation. Plot the results.
Step Sizes: .1,.05,.025.01
Solution
[1]
h=0.1; % step\'s size
N=10; % number of steps
y(1)=4;
x(1)=4;
for n=1:N
y(n+1)= y(n)+ h*(y(n).^2 + x(n).^2);
x(n+1)= x(n).^2 + h;
end
plot(x,y)
[2]
h=0.05; % step\'s size
N=10; % number of steps
y(1)=4;
x(1)=4;
for n=1:N
y(n+1)= y(n)+ h*(y(n).^2 + x(n).^2);
x(n+1)= x(n).^2 + h;
end
plot(x,y)
[3]
h=0.25; % step\'s size
N=10; % number of steps
y(1)=4;
x(1)=4;
for n=1:N
y(n+1)= y(n)+ h*(y(n).^2 + x(n).^2);
x(n+1)= x(n).^2 + h;
end
plot(x,y)
[4]
h=0.01; % step\'s size
N=10; % number of steps
y(1)=4;
x(1)=4;
for n=1:N
y(n+1)= y(n)+ h*(y(n).^2 + x(n).^2);
x(n+1)= x(n).^2 + h;
end
plot(x,y)

