summaryrefslogtreecommitdiff
path: root/1670/CH5/EX5.38/5_38.sce
diff options
context:
space:
mode:
Diffstat (limited to '1670/CH5/EX5.38/5_38.sce')
-rwxr-xr-x1670/CH5/EX5.38/5_38.sce29
1 files changed, 29 insertions, 0 deletions
diff --git a/1670/CH5/EX5.38/5_38.sce b/1670/CH5/EX5.38/5_38.sce
new file mode 100755
index 000000000..3a8ea0257
--- /dev/null
+++ b/1670/CH5/EX5.38/5_38.sce
@@ -0,0 +1,29 @@
+//Example 5.38
+//Lagranges Interpolation Method
+//Page no. 178
+clc;close;clear;
+
+x=[1,2,3,4,7]
+y=[2,4,8,16,128]
+x0=5
+printf('\tx\ty=f(x)\n-----------------------\n')
+for i=1:5
+ printf('x%i\t%i\t %i\n',i-1,x(i),y(i))
+end
+p=1;p1=1;i=1;
+for k=1:5
+ for j=1:5
+ if k~=j then
+ p=p*(x0-x(j))
+ p1=p1*(x(k)-x(j))
+ end
+end
+L(k)=p/p1
+p=1;p1=1;
+end
+p=0;
+for i=1:5
+ printf('\n L%i (x) = %g\n',i-1,L(i))
+ p=p+L(i)*y(i)
+end
+disp(p,"P(5) = ") \ No newline at end of file