diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /845/CH6/EX6.16 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '845/CH6/EX6.16')
-rwxr-xr-x | 845/CH6/EX6.16/Ex6_16.sce | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/845/CH6/EX6.16/Ex6_16.sce b/845/CH6/EX6.16/Ex6_16.sce new file mode 100755 index 000000000..5d3fb665a --- /dev/null +++ b/845/CH6/EX6.16/Ex6_16.sce @@ -0,0 +1,30 @@ +//Example 6.16
+
+clc
+clear
+
+x = [0 1 2 4];
+y = [1 1 2 5];
+
+n = length(x);
+del = %nan*ones(n,4);
+del(:,1) = y';
+for j = 2:4
+ for i = 1:n-j+1
+ del(i,j) = (del(i+1,j-1) - del(i,j-1)) / (x(i+j-1) - x(i));
+ end
+end
+del(:,1) = [];
+
+Y = 0;
+X = poly(0, "X");
+for i = 1:n
+ t = x;
+ t(i) = [];
+ p = 1;
+ for j = 1:length(t)
+ p = p * (X-t(j))/(x(i)-t(j));
+ end
+ Y = Y + p*y(i);
+end
+disp(round(Y*10^4)/10^4,"Interpolating polynomial:")
|