summaryrefslogtreecommitdiff
path: root/845/CH6/EX6.16/Ex6_16.sce
diff options
context:
space:
mode:
Diffstat (limited to '845/CH6/EX6.16/Ex6_16.sce')
-rwxr-xr-x845/CH6/EX6.16/Ex6_16.sce30
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:")