1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
//Example 5.21
//Newton's Forward Difference Formula
//Page no. 145
clc;close;clear;
printf(' x\t f(x)\t\t 1st\t\t 2nd\t\t 3rd\t\t\n\t\t\tdifference\tdifference\tdifference\t')
printf('\n---------------------------------------------------------------------------------------------------')
h=1;
z=[0,-4;1,-1;2,2;3,11;4,32;5,71]
deff('y=f1(x,p)','y=z(x,2)+p*z(x,3)+p*(p-1)*z(x,4)/2+p*(p-1)*(p-2)*z(x,5)/6')
x01=0;x11=6;
x02=2;x12=2.5
for i=3:7
for j=1:8-i
z(j,i)=z(j+1,i-1)-z(j,i-1)
end
end
printf('\n')
for i=1:6
for j=1:5
if z(i,j)==0 & i~=1 then
printf(' \t')
else
if j==1 then
printf(' %.1f\t',z(i,j))
else
printf('%.7f\t',z(i,j))
end
end
end
printf('\n')
end
x=poly(0,'x')
l=z(1,2)+x*z(1,3)+x*(x-1)*z(1,4)/2+x*(x-1)*(x-2)*z(1,5)/6
disp(l,"The required equation is :")
p=(x11-x01)/h;
disp(f1(1,p),"fp (6) =");
p=(x12-x02)/h;
disp(f1(3,p),"fp (2.5) =");
|