summaryrefslogtreecommitdiff
path: root/191/CH5/EX5.12/Example5_12.sce
blob: 8309f0111c29da6729b6e7c3b3994c7c647f40a4 (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
//Alternating way of constructing cubic splines
clc;
clear;
close();
//from example 5.11
xi = [0 1 3 3.5 5];
yi = [1.00000 0.54030 -0.98999 -0.93646 0.28366];
//free boundary conditions
//matrix form
format('v',8);
A = [6 2 0; 2 5 1/2; 0 1/2 4];
B = 6*[-0.30545 ; 0.87221 ; 0.70635];
C = inv(A)*B;
c1 = C(1);
c2 = C(2);
c3 = C(3);
x = poly(0,'x');
s2x = c2*(3.5-x)*(3.5-x)*(3.5-x)/(6*0.5) + c3*(x-3)*(x-3)*(x-3)/(6*0.5) + {yi(3)/0.5+0.5*c2/6}*(3.5-x) + {yi(4)/0.5 + 0.5*c3/6}*(x-3);
x = 3.14159;
val = horner(s2x,x)*(-1.00271)/(-0.90705);
disp(val , 'value of s2x at 3.14159 : ');
//clamped boundary conditions
A = [2 1 0 0 0;
1 6 2 0 0;
0 2 5 1/2 0;
0 0 1/2 4 3/2;
0 0 0 3/2 3];
B = 6*[-0.45970; -0.30545 ; 0.87221 ; 0.70635; 0.14551];
C = inv(A)*B;
c0 = C(1);
c1 = C(2);
c2 = C(3);
c3 = C(4);
c4 = C(5);
s2x = c2*(3.5-x)*(3.5-x)*(3.5-x)/(6*0.5) + c3*(x-3)*(x-3)*(x-3)/(6*0.5) + {yi(3)/0.5+0.5*c2/6}*(3.5-x) + {yi(4)/0.5 + 0.5*c3/6}*(x-3);
x = 3.14159;
val = horner(s2x,x)*(-1.00227)/(-0.91030);
disp(val , 'value of s2x at 3.14159 : ');