diff options
author | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
---|---|---|
committer | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
commit | 7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch) | |
tree | dbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /260/CH10/EX10.1/10_1.sce | |
parent | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff) | |
download | Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2 Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip |
initial commit / add all books
Diffstat (limited to '260/CH10/EX10.1/10_1.sce')
-rw-r--r-- | 260/CH10/EX10.1/10_1.sce | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/260/CH10/EX10.1/10_1.sce b/260/CH10/EX10.1/10_1.sce new file mode 100644 index 000000000..a040edd6e --- /dev/null +++ b/260/CH10/EX10.1/10_1.sce @@ -0,0 +1,62 @@ +//Eg-10.1
+//pg-430
+
+clear
+clc
+
+//Since the interpolating polynomial is of order 3 we have 4 unknown coefficients a0,a1,a2,a3.
+
+//The polynomial finally looks like a3x^3 + a2*x^2 + a1*x + a0 = f(x)
+
+x = [1;2;3;4];
+
+for(i = 1:4)
+ for(j = 1:4)
+ A(i,j) = x(i)^(j-1);
+ end
+end
+
+
+
+B = [2;3.5;3;4];
+
+T(1:4,1:4) = A;
+T(:,5) = B;
+
+
+
+//Gauss Elimination
+
+for(i = 2:4)
+ T(i,:) = T(i,:) - T(1,:)
+end
+
+for(i = 3:4)
+ T(i,:) = T(i,:) - T(i,2)/T(1,2)*(T(2,:));
+end
+
+
+T(4,:) = T(4,:) - T(4,3)/T(3,3)*(T(3,:));
+
+
+for(i=1:4)
+ T(i,:) = T(i,:)/T(i,i);
+end
+
+for(i = 1:3)
+ T(4-i,:) = T(4-i,:) - T(4,:)*T(4-i,4);
+
+end
+
+for(i = 1:2)
+ T(3-i,:) = T(3-i,:) - T(3,:)*T(3-i,3);
+end
+
+T(1,:) = T(1,:) - T(2,:);
+
+X = T(:,5);
+
+h = poly(X,'x',"coeff")
+
+disp(X)
+disp(h)
|