You are on page 1of 5

907435010:

MATLAB

clc
clear all
n= input('Please input the number of data points = ');
for i=1:n
x=input('Please input x-Datas = ');
X(i)=x
end
for i=1:n
y=input('please input y-Datas= ');
Y(i)=y
end
syms x ;
T=0;
for i=1:n
Z=Y(i)
for j=1:n
if i~=j
Z=Z*(x-X(j))/(X(i)-X(j));
end
end
T=T+Z
end
ezplot(T,[X(1) X(n)])
grid on

problem-3
i
Xi
F(Xi)

1
0
0.9162

2
0.25
0.8109

3
0.5
0.6931

Please input the number of data points = 5


Please input x-Datas = 0
X=0
Please input x-Datas = .25
X = 0 0.2500
Please input x-Datas = .5
X = 0 0.2500 0.5000
Please input x-Datas = .75
X = 0 0.2500 0.5000 0.7500
Please input x-Datas = 1
X = 0 0.2500 0.5000 0.7500 1.0000
please input y-Datas= 0.9162
Y = 0.9162
please input y-Datas= 0.8109
Y = 0.9162 0.8109
please input y-Datas= 0.6931
Y = 0.9162 0.8109 0.6931

4
0.75
0.5596

5
1.0
0.4055

please input y-Datas= 0.5596


Y = 0.9162 0.8109 0.6931 0.5596
please input y-Datas= 0.4055
Y = 0.9162 0.8109 0.6931 0.5596 0.4055

T=-8/3*(-4581/1250*x+4581/5000)*(x-1/2)*(x-3/4)*(x-1)-21624/625*x*(x1/2)*(x-3/4)*(x-1)+27724/625*x*(x-1/4)*(x-3/4)*(x-1)-44768/1875*x*(x-1/4)*(x1/2)*(x-1)+1622/375*x*(x-1/4)*(x-1/2)*(x-3/4)

``````````````````````````````````````````````````````````````````````````````````````````````````````````````````

Problem-6
i
Xi
F(Xi)

0
0
0

1
/8
0.1502

2
/4
0.5551

Please input the number of data points = 5


Please input x-Datas = 0
X=0
Please input x-Datas = pi/8
X = 0 0.3927
Please input x-Datas = pi/4
X = 0 0.3927 0.7854
Please input x-Datas = 3*pi/8
X = 0 0.3927 0.7854 1.1781
Please input x-Datas = pi/2
X = 0 0.3927 0.7854 1.1781 1.5708
please input y-Datas= 0
Y= 0
please input y-Datas= 0.1502
Y = 0 0.1502
please input y-Datas= 0.5551
Y = 0 0.1502 0.5551

3
3/8
0.10879

4
/2
1.57

please input y-Datas= 0.10879


Y = 0 0.1502 0.5551 0.1088
please input y-Datas= 1.57
Y = 0 0.1502 0.5551 0.1088 1.5700
T = -192256/1875*x/pi^4*(x-1/4*pi)*(x-3/8*pi)*(x1/2*pi)+355264/625*x/pi^4*(x-1/8*pi)*(x-3/8*pi)*(x-1/2*pi)696256/9375*x/pi^4*(x-1/8*pi)*(x-1/4*pi)*(x-1/2*pi)+20096/75*x/pi^4*(x1/8*pi)*(x-1/4*pi)*(x-3/8*pi)

You might also like