Consider the following wellposed IVP t1 M 1 sts 2 1 y1 2 wit
Solution
Solution:
Using Taylor\'s method of order 2: See the code below:
-------------------------------------------
%solution of initial value problem using Taylor\'s method of order 2
%y is function of t.
%Given
a=1; %lower limit for t
b=2; %upper limit for t
alpha=2; %value of function y at a
h = [0.2 0.1 0.05]; %vector of step sizes
%function y
function yt = y(t)
yt = t*log(t)+2*t;
end
%function for first derivative of y - y\'
function ydash_t = ydash(t)
ydash_t=1+y(t)/t;
end
%function for second derivative of y - y\'\'
function ydashdash_t = ydashdash(t)
ydashdash_t=1/t;
end
%first taylor term
omega0=alpha;
for step = h
printf(\"\ For step size:%f\ \",step);
time = a:step:b;
printf(\"Using Taylor\'s method:\ \");
printf(\"%.2f \",omega0);
omega_prev=omega0;
for i = time
omega_i=omega_prev+step*ydash(i)+((step^2)/2)*ydashdash(i); %calculation of Taylor\'s term
printf(\"%.2f \",omega_i);
omega_prev=omega_i;
end
printf(\"\ For exact soloution:\ \");
for i = time
yt_i=y(i);
printf(\"%.2f \",yt_i);
end
end
-------------------------------
Output:
-------------------------------
For step size:0.200000
Using Taylor\'s method:
2.00 2.62 3.27 3.95 4.66 5.39 6.14
For exact soloution:
2.00 2.62 3.27 3.95 4.66 5.39
For step size:0.100000
Using Taylor\'s method:
2.00 2.30 2.62 2.94 3.27 3.61 3.95 4.30 4.66 5.02 5.39 5.76
For exact soloution:
2.00 2.30 2.62 2.94 3.27 3.61 3.95 4.30 4.66 5.02 5.39
For step size:0.050000
Using Taylor\'s method:
2.00 2.15 2.30 2.46 2.62 2.78 2.94 3.11 3.27 3.44 3.61 3.78 3.95 4.13 4.30 4.48 4.66 4.84 5.02 5.20 5.39 5.57
For exact soloution:
2.00 2.15 2.30 2.46 2.62 2.78 2.94 3.11 3.27 3.44 3.61 3.78 3.95 4.13 4.30 4.48 4.66 4.84 5.02 5.20 5.39
------------------------------------------

