0% found this document useful (0 votes)
75 views13 pages

Bao Cao

This document contains the solutions to four exercises using Taylor's method of order two and four to approximate the solutions of initial value problems. The exercises involve using MATLAB code to apply Taylor's method to differential equations with given initial conditions and step sizes, and presenting the results. The document lists the MATLAB code for each problem and displays the corresponding output tables of the independent and dependent variable values.

Uploaded by

Gia Khánh Lâm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views13 pages

Bao Cao

This document contains the solutions to four exercises using Taylor's method of order two and four to approximate the solutions of initial value problems. The exercises involve using MATLAB code to apply Taylor's method to differential equations with given initial conditions and step sizes, and presenting the results. The document lists the MATLAB code for each problem and displays the corresponding output tables of the independent and dependent variable values.

Uploaded by

Gia Khánh Lâm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Commented [TN1]:

Commented [TN2]: `

HO CHI MINH
UNIVERSITY OF TECHNOLOGY

Numerical Analysis

Instuctor: Lê Thái Thanh

Group: 09
Member in group:
Nguyễn Minh Thông (1652584)
Nguyễn Công Thành (1652555)
Đinh Trung Kiên (1652330)
Nguyễn Trung Cang (1652064)
Huỳnh Hoàng Nam (1652395 )

HCM, June 4, 2019


Question 1. State the section 5.3: “Higher-Order Taylor Methods” In textbook,
page 276; and do the exercise set from 1 to 4 (page 281).
Exercise 1: Use Taylor’s method of order two to approximate the solutions for
each of the following initial-value problems.
a. 𝑦 ′ = 𝑡ⅇ 3𝑡 − 2𝑦 , 0 ≤ t ≤ 1, y(0) = 0, with h = 0.5
Code matlab:
function Cau1a y1=subs(y1,t,X(i-1));
clc; y1=subs(y1,y,Y(i-1));
format short f1=subs(f1,t,X(i-1));
syms t x y w real f1=subs(f1,y,Y(i-1));
h=0.5; T(i)=y1+h/2*f1;
a=0; Y(i)=Y(i-1)+h*T(i);
b=1; end
n=((b-a)/h); X
Y(1)=0; Y
T(1)=0;X(1)=0; End
X(n+1)=b; Answer:
for i= 2:n +1 X=
f=int(t*exp(3*t)-2*y,t); 0 0.5000 1.0000
dy=t*exp(3*t)-2*f; Y=
y1=t*exp(3*t)-2*y; 0 0.1250 2.0232
f1=diff(dy,t);
X(i-1)=(i-2)*h+a;

b. 𝑦 ′ = 1 + (𝑡 − 𝑦)2 , 2 ≤ t ≤ 3, y(2) = 1, with h = 0.5


Code matlab:
function Cau1b X(i-1)=(i-2)*h+a;
clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
h=0.5; f1=subs(f1,y,Y(i-1));
a=2; T(i)=y1+h/2*f1;
b=3; Y(i)=Y(i-1)+h*T(i);
n=((b-a)/h); end
Y(1)=1; X
T(1)=0;X(1)=a; Y
X(n+1)=b; end
for i= 2:n +1 Answer:
f=int(1+(t-y).^2,t);
dy=1+(t-f).^2; X = 2.0000 2.5000 3.0000
y1=1+(t-y).^2;
f1=diff(dy,t); Y = 1.0000 1.8333 2.3628
𝑦
c. 𝑦 ′ = 1 + , 1 ≤ t ≤ 2, y(1) = 2, with h = 0.25
𝑡

Code matlab:

function Cau1c X(i-1)=(i-2)*h+a;


clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
h=0.25; f1=subs(f1,y,Y(i-1));
a=1; T(i)=y1+h/2*f1;
b=2; Y(i)=Y(i-1)+h*T(i);
n=((b-a)/h); end
Y(1)=2; X
T(1)=0;X(1)=a; Y
X(n+1)=b; end
for i= 2:n +1 Answer:
f=int(1+y/t,t); X = 1.0000 1.2500 1.5000 1.7500 2.0000
dy=1+f/t;
y1=1+y/t; Y = 2.0000 2.8125 3.6687 4.5604 5.4824
f1=diff(dy,t);

d. 𝑦 ′ = 𝑐𝑜𝑠 2𝑡 + 𝑠𝑖𝑛 3𝑡, 0 ≤ t ≤ 1, y(0) = 1, with h = 0.25


code matlab:
function Cau1d X(i-1)=(i-2)*h+a;
clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
h=0.25; f1=subs(f1,y,Y(i-1));
a=0; T(i)=y1+h/2*f1;
b=1; Y(i)=Y(i-1)+h*T(i);
n=((b-a)/h); end
Y(1)=1; X
T(1)=0;X(1)=a; Y
X(n+1)=b; end
for i= 2:n +1 Answer:
f=int(cos(2*t)+sin(2*
t),t);
X = 0 0.2500 0.5000 0.7500 1.0000
dy=cos(2*t)+sin(2*t);
y1=cos(2*t)+sin(2*t);
Y = 1.0000 1.3125 1.6766 2.0033 2.2124
f1=diff(dy,t);
Exercise 2: Use Taylor’s method of order two to approximate the solutions for
each of the following initial-value problems.
a. 𝑦 ′ = ⅇ 𝑡−𝑦 , 0 ≤ t ≤ 1, y(0) = 1, with h = 0.5
Code matlab
function Cau2a X(i-1)=(i-2)*h+a;
clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
h=0.5; f1=subs(f1,y,Y(i-1));
a=0; T(i)=y1+h/2*f1;
b=1; Y(i)=Y(i-1)+h*T(i);
n=((b-a)/h); end
Y(1)=1; X
T(1)=0;X(1)=a; Y
X(n+1)=b; end
for i= 2:n +1 Answer:
f=int(exp(t-y),t); X= 0 0.5000 1.0000
dy=exp(t-f);
y1=exp(t-y); Y = 1.0000 1.2386 1.5443
f1=diff(dy,t);

1+𝑡
b. 𝑦 ′ = , 1 ≤ t ≤ 2, y(1) = 2, with h = 0.5
1+𝑦

code matlab:
function Cau2b y1=subs(y1,y,Y(i-1));
clc; f1=subs(f1,t,X(i-1));
format short f1=subs(f1,y,Y(i-1));
syms t x y w real T(i)=y1+h/2*f1;
h=0.5; Y(i)=Y(i-1)+h*T(i);
a=1; end
b=2; X
n=((b-a)/h); Y
Y(1)=2; End
T(1)=0;X(1)=a; Answer:
X(n+1)=b; X=
for i= 2:n +1
f=int((1+t)/( 1+y),t);
1.0000 1.5000 2.0000
dy=(1+t)/( 1+f);
y1=(1+t)/( 1+y);
Y=
f1=diff(dy,t);
X(i-1)=(i-2)*h+a;
y1=subs(y1,t,X(i-1));
2.0000 2.3483 2.7239
1
c. 𝑦 ′ = −𝑦 + 𝑡𝑦 2, 2 ≤ t ≤ 3, y(2) = 2, with h = 0.25
code matlab:
function Cau2c y1=subs(y1,t,X(i-1));
clc; y1=subs(y1,y,Y(i-1));
format short f1=subs(f1,t,X(i-1));
syms t x y w real f1=subs(f1,y,Y(i-1));
h=0.25; T(i)=y1+h/2*f1;
a=2; Y(i)=Y(i-1)+h*T(i);
b=3; end
n=((b-a)/h); X
Y(1)=2; Y
T(1)=0;X(1)=a; End
X(n+1)=b; Answer:
for i= 2:n +1 X = 2.0000 2.2500 2.5000 2.7500 3.0000
f=int(-y+t*y.^0.5,t);
dy=-f+t*f.^(1/2); Y = 2.0000 + 0.0000i 2.1812 + 0.0099i 2.4315 + 0.0127i
y1=-y+t*y.^0.5;
f1=diff(dy,t); 2.7531 + 0.0300i 3.1512 + 0.0616i
X(i-1)=(i-2)*h+a;

d. 𝑦 ′ = 𝑡 −2 (𝑠𝑖𝑛 2𝑡 − 2𝑡𝑦), 1 ≤ t ≤ 2, y(1) = 2, with h = 0.25


code matlab:
function Cau2d y1=subs(y1,y,Y(i-1));
clc; f1=subs(f1,t,X(i-1));
format short f1=subs(f1,y,Y(i-1));
syms t x y w real T(i)=y1+h/2*f1;
h=0.25; Y(i)=Y(i-1)+h*T(i);
a=1; end
b=2; X
n=((b-a)/h); Y
Y(1)=2; End
T(1)=0;X(1)=a; Answer:
X(n+1)=b; X=
for i= 2:n +1
f=int(t.^(-2)*(sin(2*t)-2*t*y),t);
1.0000 1.2500 1.5000 1.7500 2.0000
dy=t.^(-2)*(sin(2*t)-2*t*f);
y1=t.^(-2)*(sin(2*t)-2*t*y);
Y=
f1=diff(dy,t);
X(i-1)=(i-2)*h+a;
y1=subs(y1,t,X(i-1));
2.0000 1.3337 0.9122 0.6253 0.4211
3. Repeat Exercise 1 using Taylor’s method of order four.
a. 𝑦 ′ = 𝑡ⅇ 3𝑡 − 2𝑦 , 0 ≤ t ≤ 1, y(0) = 0, with h = 0.5
code matlab:
function Cau3a X(i-1)=(i-2)*h+a;
clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
h=0.5; f1=subs(f1,y,Y(i-1));
a=0; f2=subs(f2,t,X(i-1));
b=1; f2=subs(f2,y,Y(i-1));
n=((b-a)/h); f3=subs(f3,t,X(i-1));
Y(1)=0; f3=subs(f3,y,Y(i-1));
T(1)=0;X(1)=0; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
X(n+1)=b; Y(i)=Y(i-1)+h*T(i);
for i= 2:n+1 end
f=int(t*exp(3*t)- X
2*y,t); Y
dy=t*exp(3*t)-2*f; End
y1=t*exp(3*t)-2*y; Answer:
f1=diff(dy,t); X = 0 0.5000 1.0000
f11=subs(f1,y,f);
f2=diff(f11,t);
f22=subs(f2,y,f);
f3=diff(f22,t); Y= 0 0.2578 3.0553

b. 𝑦 ′ = 1 + (𝑡 − 𝑦)2 , 2 ≤ t ≤ 3, y(2) = 1, with h = 0.5


code matlab:
function Cau3b y1=subs(y1,t,X(i-1));
clc; y1=subs(y1,y,Y(i-1));
format short f1=subs(f1,t,X(i-1));
syms t x y w real f1=subs(f1,y,Y(i-1));
h=0.5; f2=subs(f2,t,X(i-1));
a=2; f2=subs(f2,y,Y(i-1));
b=3; f3=subs(f3,t,X(i-1));
n=((b-a)/h); f3=subs(f3,y,Y(i-1));
Y(1)=1; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
T(1)=0;X(1)=a; Y(i)=Y(i-1)+h*T(i);
X(n+1)=b; end
for i= 2:n+1 X
f=int(1+(t-y).^2,t); Y
dy=1+(t-f).^2; end
y1=1+(t-y).^2; Answer:
f1=diff(dy,t);
f11=subs(f1,y,f); X = 2.0000 2.5000 3.0000
f2=diff(f11,t);
f22=subs(f2,y,f); Y = 1.0000 1.7650 2.3871
f3=diff(f22,t);
X(i-1)=(i-2)*h+a;
𝑦
c. 𝑦 ′ = 1 + , 1 ≤ t ≤ 2, y(1) = 2, with h = 0.25
𝑡

code matlab:
function Cau3c X(i-1)=(i-2)*h+a;
clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
f1=subs(f1,y,Y(i-1));
h=0.25; f2=subs(f2,t,X(i-1));
a=1; f2=subs(f2,y,Y(i-1));
b=2; f3=subs(f3,t,X(i-1));
n=((b-a)/h); f3=subs(f3,y,Y(i-1));
Y(1)=2; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
T(1)=0;X(1)=a; Y(i)=Y(i-1)+h*T(i);
X(n+1)=b;
for i= 2:n+1 end
f=int(1+y/t,t); X
dy=1+f/t; Y
y1=1+y/t; end
f1=diff(dy,t); Answer:
f11=subs(f1,y,f);
f2=diff(f11,t); X = 1.0000 1.2500 1.5000 1.7500 2.0000
f22=subs(f2,y,f);
f3=diff(f22,t); Y = 2.0000 2.8127 3.6667 4.5554 5.4741

d. 𝑦 ′ = 𝑐𝑜𝑠 2𝑡 + 𝑠𝑖𝑛 3𝑡, 0 ≤ t ≤ 1, y(0) = 1, with h = 0.25


code matlab:
function Cau3d y1=subs(y1,t,X(i-1));
clc; y1=subs(y1,y,Y(i-1));
format short f1=subs(f1,t,X(i-1));
syms t x y w real f1=subs(f1,y,Y(i-1));
h=0.25; f2=subs(f2,t,X(i-1));
a=0; f2=subs(f2,y,Y(i-1));
b=1; f3=subs(f3,t,X(i-1));
n=((b-a)/h); f3=subs(f3,y,Y(i-1));
Y(1)=1; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
T(1)=0;X(1)=a; Y(i)=Y(i-1)+h*T(i);
X(n+1)=b; End
for i= 2:n+1 X
f=int(cos(2*t)+sin(2*t),t); Y
dy=cos(2*t)+sin(2*t); End
y1=cos(2*t)+sin(2*t); Answer:
f1=diff(dy,t);
f11=subs(f1,y,f); X= 0 0.2500 0.5000 0.7500 1.0000
f2=diff(f11,t);
f22=subs(f2,y,f); Y = 1.0000 1.3008 1.6503 1.9629 2.1621
f3=diff(f22,t);
X(i-1)=(i-2)*h+a;
4. Repeat Exercise 2 using Taylor’s method of order four
a. 𝑦 ′ = ⅇ 𝑡−𝑦 , 0 ≤ t ≤ 1, y(0) = 1, with h = 0.5
code matlab:
function Cau4a X(i-1)=(i-2)*h+a;
clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
h=0.5; f1=subs(f1,y,Y(i-1));
a=0; f2=subs(f2,t,X(i-1));
b=1; f2=subs(f2,y,Y(i-1));
n=((b-a)/h); f3=subs(f3,t,X(i-1));
Y(1)=1; f3=subs(f3,y,Y(i-1));
T(1)=0;X(1)=a; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
X(n+1)=b; Y(i)=Y(i-1)+h*T(i);
for i= 2:n+1 end
f=int(exp(t-y),t); X
dy=exp(t-f); Y
y1=exp(t-y); end
f1=diff(dy,t); Answer:
f11=subs(f1,y,f);
f2=diff(f11,t); X= 0 0.5000 1.0000
f22=subs(f2,y,f);
f3=diff(f22,t); Y = 1.0000 1.2361 1.5365

1+𝑡
b. 𝑦 ′ = , 1 ≤ t ≤ 2, y(1) = 2, with h = 0.5
1+𝑦

code matlab:
function Cau4b X(i-1)=(i-2)*h+a;
clc; y1=subs(y1,t,X(i-1));
format short y1=subs(y1,y,Y(i-1));
syms t x y w real f1=subs(f1,t,X(i-1));
h=0.5; f1=subs(f1,y,Y(i-1));
a=1; f2=subs(f2,t,X(i-1));
b=2; f2=subs(f2,y,Y(i-1));
n=((b-a)/h); f3=subs(f3,t,X(i-1));
Y(1)=2; f3=subs(f3,y,Y(i-1));
T(1)=0;X(1)=a; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
X(n+1)=b; Y(i)=Y(i-1)+h*T(i);
for i= 2:n+1 end
f=int((1+t)/( X
1+y),t); Y
dy=(1+t)/( 1+f); end
y1=(1+t)/( 1+y); Answer:
f1=diff(dy,t);
f11=subs(f1,y,f); X = 1.0000 1.5000 2.0000
f2=diff(f11,t);
f22=subs(f2,y,f); Y = 2.0000 2.3463 2.7212
f3=diff(f22,t);
1
c. 𝑦 ′ = −𝑦 + 𝑡𝑦 2, 2 ≤ t ≤ 3, y(2) = 2, with h = 0.25
code matlab:
function Cau4c y1=subs(y1,t,X(i-1));
clc; y1=subs(y1,y,Y(i-1));
format short f1=subs(f1,t,X(i-1));
syms t x y w real f1=subs(f1,y,Y(i-1));
h=0.25; f2=subs(f2,t,X(i-1));
a=2; f2=subs(f2,y,Y(i-1));
b=3; f3=subs(f3,t,X(i-1));
n=((b-a)/h); f3=subs(f3,y,Y(i-1));
Y(1)=2; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
T(1)=0;X(1)=a; Y(i)=Y(i-1)+h*T(i);
X(n+1)=b; end
for i= 2:n+1 X
f=int(-y+t*y.^0.5,t); Y
dy=-f+t*f.^(1/2); end
y1=-y+t*y.^0.5; Answer:
f1=diff(dy,t);
f11=subs(f1,y,f); X = 2.0000 2.2500 2.5000 2.7500 3.0000
f2=diff(f11,t);
f22=subs(f2,y,f); Y = 2.0000 + 0.0000i 2.1840 + 0.0114i 2.4369 +
f3=diff(f22,t);
X(i-1)=(i-2)*h+a; 0.0117i 2.7610 + 0.0255i 3.1610 + 0.0525i

d. 𝑦 ′ = 𝑡 −2 (𝑠𝑖𝑛 2𝑡 − 2𝑡𝑦), 1 ≤ t ≤ 2, y(1) = 2, with h = 0.25


code matlab:
function Cau4d y1=subs(y1,t,X(i-1));
clc; y1=subs(y1,y,Y(i-1));
format short f1=subs(f1,t,X(i-1));
syms t x y w real f1=subs(f1,y,Y(i-1));
h=0.25; f2=subs(f2,t,X(i-1));
a=1; f2=subs(f2,y,Y(i-1));
b=2; f3=subs(f3,t,X(i-1));
n=((b-a)/h); f3=subs(f3,y,Y(i-1));
Y(1)=2; T(i)=y1+(h/2)*f1+((h.^2)/6)*f2+((h.^3)/24)*f3;
T(1)=0;X(1)=a; Y(i)=Y(i-1)+h*T(i);
X(n+1)=b; end
for i= 2:n+1 X
f=int(t.^(-2)*(sin(2*t)-2*t*y),t); Y
dy=t.^(-2)*(sin(2*t)-2*t*f); end
y1=t.^(-2)*(sin(2*t)-2*t*y); Answer
f1=diff(dy,t);
f11=subs(f1,y,f);
f2=diff(f11,t);
X = 1.0000 1.2500 1.5000 1.7500 2.0000
f22=subs(f2,y,f);
f3=diff(f22,t); Y =2.0000 1.3305 0.9205 0.6392 0.4363
X(i-1)=(i-2)*h+a;
Question 2: You normally jog down a country road, and you want to determine
how far you run. Although the odometer on your car is broken, you can use the
speedometer to record the car’s velocity at 1-min intervals as you follow you
jogging rout:
Time, min 0 1 2 3 4 5 6 6.33
Velocity,mi/h 0 35 40 48 50 55 32 36
Use this data and natural cubic spline to determine how many miles you jog. Be
careful of units.
Solution:Code matlab:
function Cau2
clc;
format short
syms t x y real
T=[0 1 2 3 4 5 6 6.33];
V=[0 35 40 48 50 55 32 36];
for i=1:8
V(i)=V(i)/60;
End n=7;
for i=1:7
H(i) = T(i+1)-T(i);
end
A=zeros(n-1,n-1); B=zeros(n-1,1); M=zeros(n-1,1);
A(1,1)=2*(H(1)+H(2));
A(1,2)=H(2);
A(n-1,n-2)=H(n-1);
A(n-1,n-1)=2*(H(n-1)+H(n));
B(1,1)=(3*(V(3)-V(2))/H(2))-(3*(V(2)-V(1))/H(1));
B(n-1,1)=3*(V(n+1)-V(n))/H(n)-3*(V(n)-V(n-1))/H(n-1);
for i=2:5
A(i,i-1)=H(i);
A(i,i)=2*(H(i)+H(i+1));
A(i,i+1)=H(i+1);
B(i,1)=3*(V(i+2)-V(i+1))/H(i+1)-3*(V(i+1)-V(i))/H(i);
end
M=inv(A)*B;
for i= 1:6
Ck(i+1)=M(i,1);
end
Ck(1)=0;
Ck(8)=0;
for i=1:7
Ak(i)=V(i);
Bk(i)=(V(i+1)-V(i))/H(i)-1/3*H(i)*(Ck(i+1)+2*Ck(i));
Dk(i)=(Ck(i+1)-Ck(i))/(3*H(i));
Gk(i)=Ak(i)+Bk(i)*(x-T(i))+Ck(i)*(x-T(i)).^2;
end
KQ=subs(Gk(7),x,6.33)
End

Answer:
170947592173494608399/270215977642229760000 Or 0.6326
Question 3. Given the following boundary-value problem
′′
𝑦(𝑡) + (𝑡 2 + 1)𝑦 ′ (𝑡) − 8𝑦(𝑡) = (1 − 𝑡 2 )ⅇ −𝑡 , 0 ≤ 𝑡 ≤ 1

𝑦(0) = 1𝑦, (1) = 0


Use the finite difference method to solve the problem with h=0.02. plot the graph of y(t).
Solution: code MATLAB
function Cau3
clc;
format short
syms t x y real

a = 0; b = 1;
h = 0.02; ya = 1; yb = 0;
n = (b-a)/h;
px = t.^2+1;
qx = -8;
fx = (1-t.^2)*exp(-t) ;
Ax=1/(h.^2)-px/(2*h);
Bx=qx-2/(h.^2);
Cx=1/(h.^2)+px/(2*h);
x(1)=a;
x(n+1)=b;
for i = 2:n
x(i) = a + (i-1)*h;
end
n = round(n);
A = zeros(n-1);
B = zeros(n-1,1);
C = zeros(n-1,1);
A(1,1)=subs(Bx,t,x(2));
A(1,2)=subs(Cx,t,x(2));
A(n-1,n-2)=subs(Ax,t,x(n));
A(n-1,n-1)=subs(Bx,t,x(n));
B(1,1)=subs(fx,t,x(2))-subs(Bx,t,x(2)*ya);
B(n-1,1)=subs(fx,t,x(n))-subs(Cx,t,x(n)*yb);
for i = 2: n-2
A(i,i)=subs(Bx,t,x(i+1));
A(i,i+1)=subs(Cx,t,x(i+1));
A(i,i-1)=subs(Ax,t,x(i+1));
B(i,1)=subs(fx,t,x(i+1));
end
x
C=inv(A)*B
end
x=

[ 0, 1/50, 1/25, 3/50, 2/25, 1/10, 3/25, 7/50, 4/25, 9/50, 1/5, 11/50, 6/25, 13/50, 7/25, 3/10, 8/25, 17/50, 9/25,
19/50, 2/5, 21/50, 11/25, 23/50, 12/25, 1/2, 13/25, 27/50, 14/25, 29/50, 3/5, 31/50, 16/25, 33/50, 17/25, 7/10,
18/25, 37/50, 19/25, 39/50, 4/5, 41/50, 21/25, 43/50, 22/25, 9/10, 23/25, 47/50, 24/25, 49/50, 1]

Note: C is y(t)
C= -1.8826 -0.3957 0.3508
-1.7502 -0.3415 0.3899
-1.6255 -0.2894 0.4292
-1.5082 -0.2392 0.4687
-1.3975 -0.1907 0.5085
-1.2932 -0.1438 0.5487
-1.1947 -0.0982 0.5894
-1.1016 -0.0538 0.6307
-1.0136 -0.0106 0.6727
-0.9302 0.0317 0.7154
-0.8512 0.0732 0.7588
-0.7763 0.1141 0.8032
-0.7051 0.1543 0.8484
-0.6373 0.1941 0.8947
-0.5727 0.2335 0.9421
-0.5111 0.2727
-0.4522 0.3118

>>

You might also like