A. Use Eulers method with step size 0.1 to estimate y(0.5) where y(x) is the solution to the initial value problem

, y(0)=1
y' = f(x,y) = 2 y
2 x
h= 0.1
yn+1= yn + h. f(xn,yn)
y(0)=1 ==> x0 = 0 and y0 = 1
n=0 ==> y1= y0 + h. f(x0,y0) ==> y1 =y(0.1)= 1 + 0 = 1
n=1 ==> y2= y1 + h. f(x1,y1) ==> y2 =y(0.2)= 1 + 0.1*2*(0.1) (1)2 = 1.02
n=2 ==> y3= y2 + h. f(x2,y2) ==> y3 =y(0.3)= 1.02 + 0.1*2*(0.2) (1.02)2 = 1.06162
n=3 ==> y4= y3 + h. f(x3,y3) ==> y4 =y(0.4)= 1.06162 + 0.1*2*(0.3) (1.06162)2 = 1.129624
n=4 ==> y5= y4 + h. f(x4,y4) ==> y5 =y(0.5)= 1.129624 + 0.1*2*(0.3) (1.129624)2 = 1.23125
HENCE y(0.5)= 1.23125 with step size h= 0.1
MATLAB programming:
%% % euler rule
clear
euler
h=0.1 ;
x(1)= 0;
y(1)= 1;
tmax=0.5;
n=(tmax-x(1)) /h;
tout=x(1);
yout=y(1).';
disp(
' n x numerical ')
disp(
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
for
i=1:(n + 1 )
x(i+1) = x(1)+ i*h;
k1 = h*f(x(i), y(i));
y(i+1) = y(i) + k1 ;
%
tout=[tout;x(i)];
yout=[yout,y(i).'] ;
if rem(i-1 ,1) ==0 %
fprintf(
'%5.0f%15.2f%17.7f\n',i-1 ,x(i), y(i) );
end
end
plot(tout,yout,
'r'),grid
xlabel(
't')
ylabel(
'y(t)')
-----------------------------------------
function
yt= f(x,y)
yt= 2*x*y^2;
>> euler
n x numerical
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 0.00 1.0000000
1 0.10 1.0000000
2 0.20 1.0200000
3 0.30 1.0616160
4 0.40 1.1292377
5 0.50 1.2312519 SAME ANSWER
B. repeat part A with step size 0.05
>> euler
n x numerical
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 0.00 1.0000000
1 0.05 1.0000000
2 0.10 1.0050000
3 0.15 1.0151002
4 0.20 1.0305567
5 0.25 1.0517976
6 0.30 1.0794546
7 0.35 1.1144112
8 0.40 1.1578782
9 0.45 1.2115054
10 0.50 1.2775540 y(0.5) = 1.2775540 with step size h= (0.1) / 2 = 0.05

, y(0)=1
dy /dx = 2 y2 x
y-2 dy= 2x dx intgerate both sides
-1/y = x2 +C
y(x) = -1 / ( x2 +C)
y(0)=1 ==> 1= -1 /C ==> C= -1
y(x) =
y(0) = -1/ (0-1) =1 == y(0.5) = 1.33333 EXACT value
y(0.5) = 1.33333 EXACT value
y(0.5)= 1.23125 with step size h= 0.1
y(0.5) = 1.2775540 with step size h= (0.1) / 2 = 0.05