summaryrefslogtreecommitdiff
path: root/260/CH10/EX10.3/10_3.sce
blob: 5c341492e167128f54ce32558d25d29f7b83164b (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Eg-10.3
//pg-434

clear
clc
close()

// A = (x-xn)/h = (x-x3)/h = (0.05*x-5)
//A is the greek alphabet 'alpha'

Y = [205;201;195;190];

X = [40;60;80;100];

T = zeros(4,4);

T(:,1) = Y;

for(j = 2:4)
    for(i = 1:4+1-j)
        T(i,j) = T(i+1,j-1) - T(i,j-1);
    end
end

//disp(T)

//from equation [14], the interpolating polunomial is 

//p3 = f(x3) + A*Df(x3) + A*(A+1)/2!*D2f(x3) + A*(A+1)*(A+2)/3!*D3f(x3)

//note that A is used in place of 'alpha' and D in place of 'delta'

// The above expression p3 can also be written as 

//p3 = f(x3) + A * [ Df(x3) + D2f(x3)/2 + 1/3*D3f(x3) ] + A^2 * [ D2f(x3)/2 + 1/2*D3f(x3)] + A^3/6 * D3f(x3)..............call this expression 1

f = T(4,1);
Df = T(3,2);
D2f = T(2,3);
D3f = T(1,4);

//Substituting the values of D,D2,D3 in the expression 1 we finally get

// p3 = a0 + a1*A + a2*A^2 + a3*A^3

a0 = f;
a1 = Df + D2f/2 + 1/3*D3f;
a2 = D2f/2 + 1/2*D3f;
a3 = 1/6*D3f;

//disp(a0,a1,a2,a3)

//Now taking A = 0.05*x - 5

//p3 = b0 + b1*x + b2*x^2 + b3*x^3

b0 = a0 -5*a1 +25*a2 - 125*a3;
b1 = 0.05*a1 - 0.5*a2 + 3.75*a3;
b2 = 0.0025*a2 - 0.0375*a3;
b3 =  12.5*10^(-5)*a3;

//disp(b3,b2,b1,b0)

printf('The polynomial is  p(T) = (%f)*T^3 + (%f)*T^2 + (%f)*T + (%f)\n',b3,b2,b1,b0)

deff('out = func(in)','out = b3*in^3 + b2*in^2 + b1*in + b0')


x = 40:100;
y = func(x);

plot(x,y)
plot(X,Y,'db')

legend('Interpolated polynomial','Experimental data points')
xlabel('Temperature')
ylabel('Energy')