summaryrefslogtreecommitdiff
path: root/964/CH18/EX18.9/18_9.sce
blob: c87c3d6a8e06dae6da8d07623966766a0c5824eb (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
//clc()
x = [3,4.5,7,9];
fx = [2.5,1,2.5,0.5];
p = 4;
n = 3;
uk = n*(p-1);
c = 2*n - 2;
//20.25*a1 + 4.5*b1 + c1 = 1
//20.25*a2 + 4.5*b2 + c2 = 1
//49*a2 + 7*b2 + c2 = 2.5
//49*a3 + 7*b3 + c3 = 2.5
//9a1 + 3b1 + c1 = 2.5
//81*a3 + 9*b3 + c3 = 0.5
//9*a1 + b1 = 9*a2 + b2
//14a2 + b2 = 14 *a3 + b3
a1 = 0;
//thus we have above 9 equations and 9 unknowns a1,a2,a3,b1,b2,b3,c1,c2,c3
//thus we get
A = [20.25,4.5,1,0,0,0,0,0,0;0,0,0,20.25,4.5,1,0,0,0;0,0,0,49,7,1,0,0,0;0,0,0,0,0,0,49,7,1;9,3,1,0,0,0,0,0,0;0,0,0,0,0,0,81,9,1;9,1,0,-9,-1,0,0,0,0;0,0,0,14,1,0,-14,-1,0;1,0,0,0,0,0,0,0,0];
disp(A,"A = ")
B = [1;1;2.5;2.5;2.5;0.5;0;0;0];
disp(B,"B =")
X = inv(A)*B;
a1 = det(X(1,1));
b1 = det(X(2,1));
c1 = det(X(3,1));
a2 = det(X(4,1));
b2 = det(X(5,1));
c2 = det(X(6,1));
a3 = det(X(7,1));
b3 = det(X(8,1));
c3 = det(X(9,1));
disp(a1,"a1 = ")
disp(b1,"b1 = ")
disp(c1,"c1 = ")
disp(a2,"a2 = ")
disp(b2,"b2 = ")
disp(c2,"c2 = ")
disp(a3,"a3 = ")
disp(b3,"b3 = ")
disp(c3,"c3 = ")
//thus,f1(x) = -x + 5.5                         3 < x < 4.5
//f2(x) = 0.64*x^2 -6.76*x + 18.46              4.5 < x < 7
//f3(x) = -1.6*x^2 + 24.6*x - 91.3              7 < x < 9
x1 = 3:0.1:4.5;
x2 = 4.5:0.1:7;
x3 = 7:0.1:9;
plot2d(x1,-x1 + 5.5);
plot2d(x2,0.64*x2^2 -6.76*x2+ 18.46);
plot2d(x3,-1.6*x3^2 + 24.6*x3 - 91.3);
xtitle("f(x) vs x","x","f(x)")
x = 5;
fx = 0.64*x^2 -6.76*x + 18.46;
disp(fx,"The value at x = 5 is")