diff options
Diffstat (limited to '1670/CH5')
36 files changed, 998 insertions, 0 deletions
diff --git a/1670/CH5/EX5.1/5_1.sce b/1670/CH5/EX5.1/5_1.sce new file mode 100755 index 000000000..f56be633a --- /dev/null +++ b/1670/CH5/EX5.1/5_1.sce @@ -0,0 +1,28 @@ +//Example 5.1
+//Backward Difference Formula
+//Page no. 124
+clc;close;clear;
+printf('\tx\t\ty\t1st Difference 2nd Difference 3rd Difference 4th Difference\n')
+printf('-------------------------------------------------------------------------------------------------')
+h=0.02;
+z=[-1;0;1;2;3;4;5]
+deff('y=f(x)','y=x^3-3*x^2+5*x-7')
+for i=1:7
+ z(i,2)=f(z(i,1))
+end
+for i=3:8
+ for j=1:9-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:7
+ for j=1:6
+ if z(i,j)==0 then
+ printf('\t%i\t',z(i,j))
+ else
+ printf('\t%i\t',z(i,j))
+ end
+ end
+ printf('\n')
+end
\ No newline at end of file diff --git a/1670/CH5/EX5.11/5_11.sce b/1670/CH5/EX5.11/5_11.sce new file mode 100755 index 000000000..8cc3cd2d0 --- /dev/null +++ b/1670/CH5/EX5.11/5_11.sce @@ -0,0 +1,16 @@ +//Example 5.11
+//Finite Differences
+//Page no. 136
+clc;close;clear;
+printf(' x\t f(x)\tdf(x) d2f(x) d3f(x) d4f(x)\n')
+printf('------------------------------------------------------------------------------------------')
+x=[0,-5;1,1;2,9;3,25;4,55;5,105]
+for i=3:6
+ for j=1:8-i
+ x(j,i)=x(j+1,i-1)-x(j,i-1)
+ end
+end
+disp(x)
+x1=poly(0,"x")
+fx=x(1,2)+x1*x(1,3)+(x1^2-x1)*x(1,4)/2+(x1^3-3*x1^2+2*x1)*x(1,5)/6
+disp("is the required polynomial",fx)
\ No newline at end of file diff --git a/1670/CH5/EX5.16/5_16.sce b/1670/CH5/EX5.16/5_16.sce new file mode 100755 index 000000000..9a7379a02 --- /dev/null +++ b/1670/CH5/EX5.16/5_16.sce @@ -0,0 +1,53 @@ +//Example 5.16
+//Finite Differences
+//Page no. 138
+clc;close;clear;
+
+printf(' x\tf(x)\tdf(x) d2f(x) d3f(x) d4f(x)\n')
+printf('----------------------------------------------\n')
+x=[0,1;1,-1;2,1;3,-1;4,1;5,0;6,0;7,0];
+for i=3:6
+ for j=1:8-i
+ if x(j+1,i-1)~=0 then
+ x(j,i)=x(j+1,i-1)-x(j,i-1)
+ end
+ end
+end
+k=-9;
+for i=1:8
+ printf(' ')
+ for j=1:6
+ if i==j+k then
+ break
+ elseif x(i,j)==0 & j~=1 & j~=2 then
+ printf('d%iy%i\t',j-1,i-1)
+ elseif x(i,j)==0 & i~=1
+ printf('y%i\t',i-1)
+ else
+ printf('%i\t',x(i,j))
+ end
+ end
+ printf('\n')
+ k=k+2
+end
+x1=poly(0,"x")
+fx=x(1,2)+x1*x(1,3)+(x1^2-x1)*x(1,4)/2+(x1^3-3*x1^2+2*x1)*x(1,5)/6
+for i=1:3
+ x(1+i,6)=16;
+ printf('\nd5y%i = 16',i)
+end
+printf('\nElements should be constant\n\n');
+i=1;k=2;
+for j=5:-1:2
+ while i<4
+ x(k+1,j)=x(k,j)+x(k,j+1);
+ if j>2 then
+ printf('\nd%iy%i = %i',j-1,k,x(k+1,j))
+ else
+ printf('\ny%i = %i',k,x(k+1,j))
+ end
+ k=k+1;
+ i=i+1;
+ end
+ i=1;k=k-2;
+end
\ No newline at end of file diff --git a/1670/CH5/EX5.17/5_17.sce b/1670/CH5/EX5.17/5_17.sce new file mode 100755 index 000000000..664edf681 --- /dev/null +++ b/1670/CH5/EX5.17/5_17.sce @@ -0,0 +1,21 @@ +//Example 5.17
+//Error Propagation
+//Page no. 140
+clc;close;clear;
+printf(' x\t y\t\tdy\td2y\t d3y\t d4y\t d5y\n')
+printf('------------------------------------------------------------------------------------------')
+x=[1,1;1.1,1.5191;1.2,2.0736;1.3,2.6611;1.4,3.2816;1.5,3.9375;1.6,4.6363;1.7,5.3771;1.8,6.1776;1.9,7.0471;2,8]
+for i=3:7
+ for j=1:13-i
+ x(j,i)=x(j+1,i-1)-x(j,i-1)
+ end
+end
+disp(x)
+for i=1:11
+ if abs(x(i,7))<10^-5 then
+ continue
+ else
+ break
+ end
+end
+printf("\n\Therefore the error is in the value corresponding to %g i.e. %g",x(i+5,1),x(i+5,2))
\ No newline at end of file diff --git a/1670/CH5/EX5.18/5_18.sce b/1670/CH5/EX5.18/5_18.sce new file mode 100755 index 000000000..63ecf0757 --- /dev/null +++ b/1670/CH5/EX5.18/5_18.sce @@ -0,0 +1,21 @@ +//Example 5.18
+//Error Propagation
+//Page no. 141
+clc;close;clear;
+printf(' x\t y\t\tdy\td2y\t d3y\t d4y\t d5y\n')
+printf('------------------------------------------------------------------------------------------')
+x=[0,2;1,5;2,8;3,17;4,38;5,75;6,140;7,233;8,362;9,533;10,752]
+for i=3:6
+ for j=1:13-i
+ x(j,i)=x(j+1,i-1)-x(j,i-1)
+ end
+end
+disp(x)
+for i=1:11
+ if abs(x(i,6))<10^-5 then
+ continue
+ else
+ break
+ end
+end
+printf("\n\Therefore the error is in the value corresponding to %g i.e. %g",x(i+4,1),x(i+4,2))
\ No newline at end of file diff --git a/1670/CH5/EX5.20/5_20.sce b/1670/CH5/EX5.20/5_20.sce new file mode 100755 index 000000000..bb3cf538c --- /dev/null +++ b/1670/CH5/EX5.20/5_20.sce @@ -0,0 +1,36 @@ +//Example 5.20
+//Newtons Forward Difference Formula
+//Page no. 144
+clc;close;clear;
+printf(' x\t sin x\t\t 1st\t\t 2nd\t\t 3rd\t\t 4th\t\t 5th\n\t\t\tdifference\tdifference\tdifference\tdifference\tdifference\t')
+printf('\n---------------------------------------------------------------------------------------------------')
+h=0.2;
+z=[0.5,0.47943;0.7,0.64422;0.9,0.78333;1.1,0.89121;1.3,0.96356;1.5,0.99749]
+deff('y=f(x,p)','y=z(x,2)+p*z(x,3)+p*(p+1)*z(x,4)/2+p*(p+1)*(p+2)*z(x,5)/6+p*(p+1)*(p+2)*(p+3)*z(x,6)/24')
+deff('y=f1(x,p)','y=z(x,2)+p*z(x,3)+p*(p-1)*z(x,4)/2+p*(p-1)*(p-2)*z(x,5)/6+p*(p-1)*(p-2)*(p-3)*z(x,6)/24+p*(p-1)*(p-2)*(p-3)*(p-4)*z(x,7)/120')
+x01=0.5;x11=0.54;
+x02=1.3;x12=1.36
+for i=3:7
+ for j=1:8-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:6
+ for j=1:7
+ if z(i,j)==0 then
+ printf(' \t')
+ else
+ if j==1 then
+ printf(' %.1f\t',z(i,j))
+ else
+ printf('%.7f\t',z(i,j))
+ end
+ end
+ end
+ printf('\n')
+end
+p=(x11-x01)/h;
+disp(f1(1,p),"fp (0.54) =");
+p=(x12-x02)/h;
+disp(f(5,p),"fp (1.36) =");
diff --git a/1670/CH5/EX5.21/5_21.sce b/1670/CH5/EX5.21/5_21.sce new file mode 100755 index 000000000..56aab357f --- /dev/null +++ b/1670/CH5/EX5.21/5_21.sce @@ -0,0 +1,38 @@ +//Example 5.21
+//Newton's Forward Difference Formula
+//Page no. 145
+clc;close;clear;
+printf(' x\t f(x)\t\t 1st\t\t 2nd\t\t 3rd\t\t\n\t\t\tdifference\tdifference\tdifference\t')
+printf('\n---------------------------------------------------------------------------------------------------')
+h=1;
+z=[0,-4;1,-1;2,2;3,11;4,32;5,71]
+deff('y=f1(x,p)','y=z(x,2)+p*z(x,3)+p*(p-1)*z(x,4)/2+p*(p-1)*(p-2)*z(x,5)/6')
+x01=0;x11=6;
+x02=2;x12=2.5
+for i=3:7
+ for j=1:8-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:6
+ for j=1:5
+ if z(i,j)==0 & i~=1 then
+ printf(' \t')
+ else
+ if j==1 then
+ printf(' %.1f\t',z(i,j))
+ else
+ printf('%.7f\t',z(i,j))
+ end
+ end
+ end
+ printf('\n')
+end
+x=poly(0,'x')
+l=z(1,2)+x*z(1,3)+x*(x-1)*z(1,4)/2+x*(x-1)*(x-2)*z(1,5)/6
+disp(l,"The required equation is :")
+p=(x11-x01)/h;
+disp(f1(1,p),"fp (6) =");
+p=(x12-x02)/h;
+disp(f1(3,p),"fp (2.5) =");
diff --git a/1670/CH5/EX5.22/5_22.sce b/1670/CH5/EX5.22/5_22.sce new file mode 100755 index 000000000..27c699e81 --- /dev/null +++ b/1670/CH5/EX5.22/5_22.sce @@ -0,0 +1,34 @@ +//Example 5.22
+//Newton's Forward Difference Formula
+//Page no. 147
+clc;close;clear;
+printf(' x\t y\t\t 1st\t\t 2nd\t\t 3rd\t\t\n\t\t\tdifference\tdifference\tdifference\t')
+printf('\n---------------------------------------------------------------------------------------------------')
+h=1;
+z=[0,-3;1,3;2,11;3,27;4,57;5,107]
+deff('y=f1(x,p)','y=z(x,2)+p*z(x,3)+p*(p-1)*z(x,4)/2+p*(p-1)*(p-2)*z(x,5)/6')
+x01=0;x11=6;
+x02=2;x12=2.5
+for i=3:7
+ for j=1:8-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:6
+ for j=1:5
+ if z(i,j)==0 & i~=1 then
+ printf(' \t')
+ else
+ if j==1 then
+ printf(' %.1f\t',z(i,j))
+ else
+ printf('%.7f\t',z(i,j))
+ end
+ end
+ end
+ printf('\n')
+end
+x=poly(0,'x')
+l=z(1,2)+x*z(1,3)+x*(x-1)*z(1,4)/2+x*(x-1)*(x-2)*z(1,5)/6
+disp(l,"The required equation is :")
\ No newline at end of file diff --git a/1670/CH5/EX5.23/5_23.sce b/1670/CH5/EX5.23/5_23.sce new file mode 100755 index 000000000..243cf2c42 --- /dev/null +++ b/1670/CH5/EX5.23/5_23.sce @@ -0,0 +1,35 @@ +//Example 5.23
+//Newton's Forward Difference Formula
+//Page no. 147
+clc;close;clear;
+printf(' x\t y\t d1\td2\td3\td4\t')
+printf('\n--------------------------------------------------------------------')
+h=5;
+z=[80,5026;85,5674;90,6362;95,7088;100,7854]
+deff('y=f(x,p)','y=z(x,2)+p*z(x-1,3)+p*(p+1)*z(x-2,4)/2+p*(p+1)*(p+2)*z(x-3,5)/6+p*(p+1)*(p+2)*(p+3)*z(x-4,6)/24')
+x01=100;x11=105;
+for i=3:7
+ for j=1:7-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:5
+ for j=1:6
+ if z(i,j)==0 then
+ printf(' \t')
+ else
+ if j==1 then
+ printf(' %i\t',z(i,j))
+ else
+ printf('%i\t',z(i,j))
+ end
+ end
+ end
+ printf('\n')
+end
+x=poly(0,'x')
+l=z(1,2)+x*z(1,3)+x*(x-1)*z(1,4)/2+x*(x-1)*(x-2)*z(1,5)/6
+disp(l,"The required equation is :")
+p=(x11-x01)/h;
+disp(f(5,p),"fp (105) =");
\ No newline at end of file diff --git a/1670/CH5/EX5.24/5_24.sce b/1670/CH5/EX5.24/5_24.sce new file mode 100755 index 000000000..c848c6060 --- /dev/null +++ b/1670/CH5/EX5.24/5_24.sce @@ -0,0 +1,28 @@ +//Example 5.24
+//Central Difference Derivatives
+//Page no. 160
+clc;close;clear;
+printf(' x\t\t y\t\t d\t\t d2\t\t d3\t\t d4\n')
+printf('---------------------------------------------------------------------------------------------')
+h=0.01;s=0.5;
+deff('y=f1(x,p)','y=z(x,2)+p*z(x,3)+p*(p-1)*(z(x,4)+z(x-1,4))/4')
+z=[0.01,98.4342;0.02,48.4392;0.03,31.7775;0.04,23.4492;0.05,18.4542];
+for i=3:6
+ for j=1:7-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:5
+ for j=1:6
+ if z(i,j)==0 then
+ printf(' \t')
+ else
+ printf('%.7f\t',z(i,j))
+ end
+ end
+ printf('\n')
+end
+x00=0.03;x01=0.0341;
+p=(x01-x00)/h
+printf('\n\nf(0.0341) = %g',f1(3,p))
\ No newline at end of file diff --git a/1670/CH5/EX5.27/5_27.sce b/1670/CH5/EX5.27/5_27.sce new file mode 100755 index 000000000..8869e662b --- /dev/null +++ b/1670/CH5/EX5.27/5_27.sce @@ -0,0 +1,24 @@ +//Example 5.27
+//Divided Difference Interpolation
+//Page no. 165
+clc;close;clear;
+
+x=[-4,-1,0,2,5]
+y=[1245,33,5,9,1335];
+y1=y;
+deff('yi=P(a,b,d,e)','yi=(b(d+1)-b(d))/(a(d+e)-a(d))') //function for finding polynomials
+for i=1:4
+ for j=1:5-i
+ z(j,i)=P(x,y,j,i)
+ y(j)=z(j,i)
+ end
+end
+z(6,1)=0;
+printf('x\ty f(x0,x1) f(x0,x1,x3) f(x0,x1,x2,x3) f(x0,x1,x2,x3,x4)\n')
+printf('---------------------------------------------------------------------------------\n')
+ for j=1:5
+ printf(' %i\t%i \t%i\t\t%i\t\t%i\t\t %i\n',x(1,j),y1(1,j),z(j,1),z(j,2),z(j,3),z(j,4))
+ end
+ x1=poly(0,'x')
+ fx=y1(1)+(x1-x(1))*z(1,1)+(x1-x(1))*(x1-x(2))*z(1,2)+(x1-x(1))*(x1-x(2))*(x1-x(3))*z(1,3)+(x1-x(1))*(x1-x(2))*(x1-x(3))*(x1-x(4))*z(1,4)
+ disp(fx,"The Required Equation = ")
\ No newline at end of file diff --git a/1670/CH5/EX5.28/5_28.sce b/1670/CH5/EX5.28/5_28.sce new file mode 100755 index 000000000..b8fd337ad --- /dev/null +++ b/1670/CH5/EX5.28/5_28.sce @@ -0,0 +1,24 @@ +//Example 5.28
+//Divided Difference Interpolation
+//Page no. 167
+clc;close;clear;
+
+x=[-1,0,3,6,7]
+y=[3,-6,39,822,1611];
+y1=y;
+deff('yi=P(a,b,d,e)','yi=(b(d+1)-b(d))/(a(d+e)-a(d))') //function for finding polynomials
+for i=1:4
+ for j=1:5-i
+ z(j,i)=P(x,y,j,i)
+ y(j)=z(j,i)
+ end
+end
+z(6,1)=0;
+printf('x\ty f(x0,x1) f(x0,x1,x3) f(x0,x1,x2,x3) f(x0,x1,x2,x3,x4)\n')
+printf('---------------------------------------------------------------------------------\n')
+ for j=1:5
+ printf(' %i\t%i \t%i\t\t%i\t\t%i\t\t %i\n',x(1,j),y1(1,j),z(j,1),z(j,2),z(j,3),z(j,4))
+ end
+ x1=poly(0,'x')
+ fx=y1(1)+(x1-x(1))*z(1,1)+(x1-x(1))*(x1-x(2))*z(1,2)+(x1-x(1))*(x1-x(2))*(x1-x(3))*z(1,3)+(x1-x(1))*(x1-x(2))*(x1-x(3))*(x1-x(4))*z(1,4)
+ disp(fx,"The Required Equation = ")
\ No newline at end of file diff --git a/1670/CH5/EX5.29/5_29.sce b/1670/CH5/EX5.29/5_29.sce new file mode 100755 index 000000000..b0a8d731a --- /dev/null +++ b/1670/CH5/EX5.29/5_29.sce @@ -0,0 +1,24 @@ +//Example 5.29
+//Divided Difference Interpolation
+//Page no. 167
+clc;close;clear;
+
+x=[4,5,7,10,11,13]
+y=[48,100,294,900,1210,2028];
+y1=y;
+deff('yi=P(a,b,d,e)','yi=(b(d+1)-b(d))/(a(d+e)-a(d))') //function for finding polynomials
+for i=1:6
+ for j=1:6-i
+ z(j,i)=P(x,y,j,i)
+ y(j)=z(j,i)
+ end
+end
+z(6,1)=0;
+printf('x\ty f(x0,x1) f(x0,x1,x3) f(x0,x1,x2,x3) f(x0,x1,x2,x3,x4)\n')
+printf('---------------------------------------------------------------------------------\n')
+ for j=1:5
+ printf(' %i\t%i \t%i\t\t%i\t\t%i\t\t %i %i\n',x(1,j),y1(1,j),z(j,1),z(j,2),z(j,3),z(j,4),z(j,5))
+ end
+ deff('y=f(x1)','y=y1(1)+(x1-x(1))*z(1,1)+(x1-x(1))*(x1-x(2))*z(1,2)+(x1-x(1))*(x1-x(2))*(x1-x(3))*z(1,3)')
+ printf('\n\nf(8) = %g',f(8))
+ printf('\n\nf(15) = %i',f(15))
\ No newline at end of file diff --git a/1670/CH5/EX5.3/5_3.sce b/1670/CH5/EX5.3/5_3.sce new file mode 100755 index 000000000..78764dbde --- /dev/null +++ b/1670/CH5/EX5.3/5_3.sce @@ -0,0 +1,29 @@ +//Example 5.3
+//Factorial Notation Method
+//Page no. 131
+clc;close;clear;
+
+h=0.00000001;h1=0000000.1
+deff('y=f(x)','y=x^3-2*x^2+x-1')
+deff('y=f1(x)','y=x*(x-1)*(x-2)')
+deff('y=f2(x)','y=x*(x-1)')
+for i=0:2
+ A(i+1,1)=f2(i);
+ A(i+1,2)=i;
+ A(i+1,3)=1
+ B(i+1,1)=f(i)-f1(i)
+end
+x=poly(0,'x')
+C=inv(A)*B
+disp(C(3),'+',C(2)*x,'+',C(1)*f2(x),'+',f(x))
+printf('\n\nf(x) = ')
+deff('y=f3(x)','y=C(3)+C(2)*x+C(1)*f2(x)+f(x)')
+disp(f3(x))
+deff('y=f4(x)','y=(f3(x+h)-f3(x))/h') //1st derivative
+disp(f4(x),'dx = ')
+deff('y=f5(x)','y=(f4(x+h1)-f4(x))/h1') //2nd derivative
+disp(f5(x),'d2x = ')
+deff('y=f6(x)','y=(f5(x+h1)-f5(x))/h1') //3rd derivative
+disp(f6(x),'d3x = ')
+deff('y=f7(x)','y=(f6(x+h1)-f6(x))/h1') //4th derivative
+disp(f7(x),'d4x = ')
\ No newline at end of file diff --git a/1670/CH5/EX5.30/5_30.sce b/1670/CH5/EX5.30/5_30.sce new file mode 100755 index 000000000..f08e49021 --- /dev/null +++ b/1670/CH5/EX5.30/5_30.sce @@ -0,0 +1,10 @@ +//Example 5.30
+//Maximum Error in Interpolation
+//Page no. 169
+clc;close;clear;
+s=1;
+for i=0:6
+ s=s*((5*%pi)/24-i*%pi/12)
+end
+s=s/factorial(7)
+printf('Maximum Error = %g',s)
\ No newline at end of file diff --git a/1670/CH5/EX5.32/5_32.sce b/1670/CH5/EX5.32/5_32.sce new file mode 100755 index 000000000..dd2d6d5d1 --- /dev/null +++ b/1670/CH5/EX5.32/5_32.sce @@ -0,0 +1,23 @@ +//Example 5.32
+//Divided Difference Interpolation
+//Page no. 170
+clc;close;clear;
+
+x=[0,1,2,4]
+y=[1,3,9,81];
+y1=y;
+deff('yi=P(a,b,d,e)','yi=(b(d+1)-b(d))/(a(d+e)-a(d))') //function for finding polynomials
+for i=1:4
+ for j=1:4-i
+ z(j,i)=P(x,y,j,i)
+ y(j)=z(j,i)
+ end
+end
+z(6,1)=0;
+printf('x\ty f(x0,x1) f(x0,x1,x3) f(x0,x1,x2,x3)\n')
+printf('-----------------------------------------------------------\n')
+ for j=1:3
+ printf(' %i\t%i \t%i\t\t%i\t\t%i\t\t\n',x(1,j),y1(1,j),z(j,1),z(j,2),z(j,3))
+ end
+ deff('y=f(x1)','y=y1(1)+(x1-x(1))*z(1,1)+(x1-x(1))*(x1-x(2))*z(1,2)+(x1-x(1))*(x1-x(2))*(x1-x(3))*z(1,3)')
+ printf('\n\nf(3) = %g',f(3))
\ No newline at end of file diff --git a/1670/CH5/EX5.36/5_36.sce b/1670/CH5/EX5.36/5_36.sce new file mode 100755 index 000000000..8d8e9ef96 --- /dev/null +++ b/1670/CH5/EX5.36/5_36.sce @@ -0,0 +1,29 @@ +//Example 5.36
+//Lagrange's Interpolation Method
+//Page no. 176
+clc;close;clear;
+
+x=[7,8,9,10]
+y=[3,1,1,9]
+x0=9.5
+printf('\tx\ty=f(x)\n-----------------------\n')
+for i=1:4
+ printf('x%i\t%i\t %i\n',i-1,x(i),y(i))
+end
+p=1;p1=1;i=1;
+for k=1:4
+ for j=1:4
+ 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:4
+ printf('\n L%i (x) = %g\n',i-1,L(i))
+ p=p+L(i)*y(i)
+end
+disp(p,"P(9.5) = ")
\ No newline at end of file diff --git a/1670/CH5/EX5.37/5_37.sce b/1670/CH5/EX5.37/5_37.sce new file mode 100755 index 000000000..121b25afe --- /dev/null +++ b/1670/CH5/EX5.37/5_37.sce @@ -0,0 +1,29 @@ +//Example 5.37
+//Lagranges Interpolation Method
+//Page no. 177
+clc;close;clear;
+
+x=[0,1,2,5]
+y=[2,3,12,147]
+x0=poly(0,'x')
+printf('\tx\ty=f(x)\n-----------------------\n')
+for i=1:4
+ printf('x%i\t%i\t %i\n',i-1,x(i),y(i))
+end
+p=1;p1=1;i=1;
+for k=1:4
+ for j=1:4
+ 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:4
+ disp(L(i),"L(x) = ")
+ p=p+L(i)*y(i)
+end
+disp(p,"P(x) = ")
\ No newline at end of file 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 diff --git a/1670/CH5/EX5.39/5_39.sce b/1670/CH5/EX5.39/5_39.sce new file mode 100755 index 000000000..551a9cfe6 --- /dev/null +++ b/1670/CH5/EX5.39/5_39.sce @@ -0,0 +1,31 @@ +//Example 5.39
+//Hermite Interpolation Method
+//Page no. 181
+clc;close;clear;
+
+x=[-1,0,1]
+y=[-10,-4,-2]
+y1=[10,3,2]
+x0=poly(0,'x')
+printf('\tx\ty=f(x)\n-----------------------\n')
+for i=1:3
+ printf('x%i\t%i\t %i\n',i-1,x(i),y(i))
+end
+p=1;p1=1;i=1;
+for k=1:3
+ for j=1:3
+ 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;
+L1=[-3/2,0,3/2]
+for i=1:3
+ disp(L(i),"L(x) = ")
+ p=p+(1-2*L1(i)*(x0-x(i)))*L(i)^2*y(i)+(x0-x(i))*((L(i))^2)*y1(i)
+end
+disp(p,"P(x) = ")
\ No newline at end of file diff --git a/1670/CH5/EX5.40/5_40.sce b/1670/CH5/EX5.40/5_40.sce new file mode 100755 index 000000000..9deb30297 --- /dev/null +++ b/1670/CH5/EX5.40/5_40.sce @@ -0,0 +1,31 @@ +//Example 5.40
+//Hermite Interpolation Method
+//Page no. 182
+clc;close;clear;
+
+x=[0,1,2]
+y=[1,3,21]
+y1=[0,6,36]
+x0=poly(0,'x')
+printf('\tx\ty=f(x)\n-----------------------\n')
+for i=1:3
+ printf('x%i\t%i\t %i\n',i-1,x(i),y(i))
+end
+p=1;p1=1;i=1;
+for k=1:3
+ for j=1:3
+ 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;
+L1=[-3/2,0,3/2]
+for i=1:3
+ disp(L(i),"L(x) = ")
+ p=p+(1-2*L1(i)*(x0-x(i)))*L(i)^2*y(i)+(x0-x(i))*((L(i))^2)*y1(i)
+end
+disp(p,"P(x) = ")
\ No newline at end of file diff --git a/1670/CH5/EX5.41/5_41.sce b/1670/CH5/EX5.41/5_41.sce new file mode 100755 index 000000000..490ad562a --- /dev/null +++ b/1670/CH5/EX5.41/5_41.sce @@ -0,0 +1,58 @@ +//Example 5.41
+//Piecewise Cubic Hermite Interpolation Method
+//Page no. 182
+clc;close;clear;
+
+x=[0,1]
+y=[1,3]
+y1=[0,6]
+x0=poly(0,'x')
+printf('\tx\ty=f(x)\n-----------------------\n')
+for i=1:2
+ printf('x%i\t%i\t %i\n',i-1,x(i),y(i))
+end
+p=1;p1=1;i=1;
+for k=1:2
+ for j=1:2
+ 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;
+L1=[-1,1]
+for i=1:2
+ disp(L(i),"L(x) = ")
+ p=p+(1-2*L1(i)*(x0-x(i)))*L(i)^2*y(i)+(x0-x(i))*((L(i))^2)*y1(i)
+end
+disp(p,"P2(x) = ")
+printf('\n\n\n\n\n')
+x=[1,2]
+y=[3,21]
+y1=[6,36]
+x0=poly(0,'x')
+printf('\tx\ty=f(x)\n-----------------------\n')
+for i=1:2
+ printf('x%i\t%i\t %i\n',i-1,x(i),y(i))
+end
+p=1;p1=1;i=1;
+for k=1:2
+ for j=1:2
+ 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;
+L1=[-1,1]
+for i=1:2
+ disp(L(i),"L(x) = ")
+ p=p+(1-2*L1(i)*(x0-x(i)))*L(i)^2*y(i)+(x0-x(i))*((L(i))^2)*y1(i)
+end
+disp(p,"P3(x) = ")
\ No newline at end of file diff --git a/1670/CH5/EX5.43/5_43.sce b/1670/CH5/EX5.43/5_43.sce new file mode 100755 index 000000000..4ecb2ccd2 --- /dev/null +++ b/1670/CH5/EX5.43/5_43.sce @@ -0,0 +1,50 @@ +//Example 5.43
+//Inverse Interpolation using Newton's Forward Difference Formula
+//Page no. 189
+clc;close;clear;
+printf(' \tx\ty\td\td2\td3\n')
+printf('\t-----------------------------------')
+h=1;
+z=[2,8;3,27;4,64;5,125];
+deff('y=f1(x,s)','y=(z(x,3)+(s-1/2)*z(x,4)+z(x,5)*(3*s^2-6*s+2)/6)/h')
+deff('y=f2(x,s)','y=(z(x,4)+z(x,5)*(s-1))/h^2')
+deff('y=f3(x,s)','y=z(x,5)/h^3')
+for i=3:5
+ for j=1:6-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:4
+ for j=1:5
+ if z(i,j)==0 then
+ printf(' \t')
+ else
+ printf('\t%g',z(i,j))
+ end
+ end
+ printf('\n')
+end
+fp=10;
+f0=z(1,2);x0=z(1,1);x=fp-f0;p=(z(2,1)-z(1,1))/h;y=0;k=1;p=1;
+for i=1:5
+ if i>3 then
+ l=3;
+ else
+ l=i;
+ end
+ for j=1:l
+ for k=j:-1:2
+ if k==j then
+ y=1;
+ end
+ y=y*(p-(k-1))
+ end
+ y=y*z(1,j+2)*p/factorial(j);
+ x=x-y;
+ end
+ p=(x)/z(1,3)
+ x=fp-f0;y=0;
+ printf('\n p%i = %g\n',i,p)
+end
+printf('\n\n Hence, x = x0+ph = %g ',x+p*h)
\ No newline at end of file diff --git a/1670/CH5/EX5.44/5_44.sce b/1670/CH5/EX5.44/5_44.sce new file mode 100755 index 000000000..0924efdc4 --- /dev/null +++ b/1670/CH5/EX5.44/5_44.sce @@ -0,0 +1,23 @@ +//Example 5.44
+//Inverse Interpolation using Everett Formula
+//Page no. 191
+clc;close;clear;
+printf(' \tx\td(log(x!)/dx)\t\td2\t d4\n')
+printf('\t----------------------------------------------------')
+x=[0.46,-0.0015805620,-0.0000888096,-0.000000396;0.47,0.0080664890,-0.0000872716,-0.0000000383];
+h=0.001
+for i=1:2
+ printf('\n')
+ for j=1:4
+ printf('\t%g',x(i,j))
+ end
+end
+p(1)=-(x(1,2))/(x(2,2)-x(1,2))
+for i=1:2
+ p(i+1)=(-x(1,2)-(p(i)^3-p(i))*x(1,3)/6-(-p(i)^3+3*p(i)^2-2*p(i))*x(1,3)/6)/(x(2,2)-x(1,2))
+end
+for i=1:3
+ printf('\n\n p(%i) = %g',i,p(i))
+end
+x=x(1,1)+p(3)*h
+printf('\n\n x = x0 + ph = %.8g',x);
\ No newline at end of file diff --git a/1670/CH5/EX5.45/5_45.sce b/1670/CH5/EX5.45/5_45.sce new file mode 100755 index 000000000..9cd8984df --- /dev/null +++ b/1670/CH5/EX5.45/5_45.sce @@ -0,0 +1,21 @@ +//Example 5.45
+//Inverse Lagrange Method
+//Page no. 192
+clc;close;clear;
+
+x=[30,34,38,42];
+y=[-30,-13,3,18];
+P=0;
+y1=0;
+for k=0:3
+ p=1
+ for j=0:3
+ if(j~=k)
+ p=p*((y1-y(j+1))/(y(k+1)-y(j+1)))
+ end
+ end
+ printf('\n L%i(f) = %g\n',k,p)
+ p=p*x(k+1)
+ P=P+p;
+end
+disp(P,'Inverse Lagrange interpolation x=')
\ No newline at end of file diff --git a/1670/CH5/EX5.46/5_46.sce b/1670/CH5/EX5.46/5_46.sce new file mode 100755 index 000000000..de9aab92a --- /dev/null +++ b/1670/CH5/EX5.46/5_46.sce @@ -0,0 +1,16 @@ +//Example 5.46
+//Newton's Divided Difference Interpolation
+//Page no. 192
+clc;close;clear;
+
+x=[3,3.6,3.8]
+y=[0.13515,0.83059,0.26253];
+deff('y=f1(x1,x2,y1,y2)','y=(y2-y1)/(x2-x1)');
+deff('y=f2(x1,x2,x3,y1,y2,y3)','y=(f1(x2,x3,y2,y3)-f1(x1,x2,y1,y2))/(x3-x1)');
+function [x]=f(x1,x2,x3,y1,y2,y3)
+ x=(x1+2*x2+x3)/4-(f1(x1,x2,y1,y2)+f1(x2,x3,y2,y3))/(4*f2(x1,x2,x3,y1,y2,y3))
+endfunction
+disp(f1(x(1),x(2),y(1),y(2)),' f(x1,x2) = ')
+disp(f1(x(2),x(3),y(2),y(3)),' f(x2,x3) = ')
+disp(f2(x(1),x(2),x(3),y(1),y(2),y(3)),' f(x1,x2,x3) = ')
+disp(f(x(1),x(2),x(3),y(1),y(2),y(3)),' x0 = ')
\ No newline at end of file diff --git a/1670/CH5/EX5.47/5_47.sce b/1670/CH5/EX5.47/5_47.sce new file mode 100755 index 000000000..53e4c570d --- /dev/null +++ b/1670/CH5/EX5.47/5_47.sce @@ -0,0 +1,51 @@ +//Example 5.47
+//Bessel Interpolation
+//Page no. 194
+clc;close;clear;
+
+deff('y=f(x)','y=x^3-15*x+4');
+h=0.02;p=1;
+for i=1:9
+ z(i,1)=0.22+(i-1)*h
+ z(i,2)=f(z(i))
+end
+printf(' x\t\t f(x) \t d\t\t d2\t\t d3\t\t d4\n')
+printf('--------------------------------------------------------------------------------------------')
+for i=3:6
+ for j=1:11-i
+ z(j,i)=z(j+1,i-1)-z(j,i-1)
+ end
+end
+printf('\n')
+for i=1:9
+ for j=1:6
+ if z(i,j)==0 then
+ printf(' \t')
+ else
+ printf('%.7f\t',z(i,j))
+ end
+ end
+ printf('\n')
+end
+for l=1:8
+ if abs(z(l+1,2))/z(l+1,2)~=abs(z(l,2))/z(l,2) then
+ break;
+ else
+ l=9;
+ end
+end
+function [y]=f1(x,p1)
+ if x==1 then
+ y=z(l,2)
+ elseif x==2
+ y=z(l,2)+(p1*(p1-1))/factorial(2)*((z(l-1,4)+z(l,4))/2)
+ elseif x==3
+ y=z(l,2)+(p1*(p1-1))/factorial(2)*((z(l-1,4)+z(l,4))/2)+(p1*(p1-1)*(p1-0.5))/factorial(3)*(z(l,5))
+ end
+endfunction
+for i=1:3
+ p=-(f1(i,p))/z(l,3)
+ printf('\n p%i = %g\n',i,p)
+end
+x=z(l,1)+p*h;
+printf(' \n\n x = x0 + ph = %g+(%g)(%g) = %g',z(l,1),p,h,x)
\ No newline at end of file diff --git a/1670/CH5/EX5.48/5_48.sce b/1670/CH5/EX5.48/5_48.sce new file mode 100755 index 000000000..82559ce04 --- /dev/null +++ b/1670/CH5/EX5.48/5_48.sce @@ -0,0 +1,11 @@ +//Example 5.48
+//Chebyshev Polynomial
+//Page no. 199
+clc;close;clear;
+
+deff('y=f(x)','y=4*x^3+2*x^2');
+n=4;
+for i=3:-1:0
+ x(i+1)=cosd(((2*i+1)*%pi)/(2*n))
+ printf('\n x(%i) = %g\n',i,x(i+1))
+end
\ No newline at end of file diff --git a/1670/CH5/EX5.5/5_5.sce b/1670/CH5/EX5.5/5_5.sce new file mode 100755 index 000000000..b1ccca848 --- /dev/null +++ b/1670/CH5/EX5.5/5_5.sce @@ -0,0 +1,14 @@ +//Example 5.5
+//Finite Differences
+//Page no. 132
+clc;close;clear;
+printf(' x\t f(x)\tdf(x)\t d2f(x)\td3f(x)\t d4f(x)\n')
+printf('------------------------------------------------------------------------------------------')
+x=[0,1;1,3;2,9;3,poly(0,"y3");4,81]
+for i=3:6
+ for j=1:7-i
+ x(j,i)=x(j+1,i-1)-x(j,i-1)
+ end
+end
+disp(x)
+disp(roots(x(1,6)),"y3 = ")
\ No newline at end of file diff --git a/1670/CH5/EX5.50/5_50.sce b/1670/CH5/EX5.50/5_50.sce new file mode 100755 index 000000000..7b59a67de --- /dev/null +++ b/1670/CH5/EX5.50/5_50.sce @@ -0,0 +1,13 @@ +//Example 5.50
+//Spline Interpolation
+//Page no. 204
+clc;close;clear;
+
+xi=[1,2,3];
+yi=[-1,4,21];
+x=poly(0,'x')
+deff('y=S(x0,x1)','y=(x-xi(x1))*yi(x0)/(xi(x0)-xi(x1))+(x-xi(x0))*yi(x1)/(xi(x1)-xi(x0))');
+S1=S(1,2);
+S2=S(2,3);
+printf('\n The required Spline is : \n')
+disp(S2,'S2 = ',S1,'S1 = ');
\ No newline at end of file diff --git a/1670/CH5/EX5.51/5_51.sce b/1670/CH5/EX5.51/5_51.sce new file mode 100755 index 000000000..cd099e876 --- /dev/null +++ b/1670/CH5/EX5.51/5_51.sce @@ -0,0 +1,34 @@ +//Example 5.51
+//Spline Interpolation
+//Page no. 204
+clc;close;clear;
+
+xi=[1,2,3];
+yi=[-6,-1,16];
+h=1;n=2;
+x=poly(0,'x')
+m(2)=(6*(yi(3)-2*yi(2)+yi(1)))/4
+m(1)=0;m(3)=0;
+function [y]=S(i,x)
+ y=m(i)*(xi(i+1)-x)^3/(6*h)
+ y=y+m(i+1)*(x-xi(i))^3/(6*h)
+ y=y+(yi(i)/h-(m(i)*h)/6)*(xi(i+1)-x)
+ y=y+(yi(i+1)/h-(m(i+1)*h)/6)*(-xi(i)+x)
+endfunction
+for i=1:2
+ S1(i)=S(i);
+end
+printf('\n The required Spline is : \n')
+disp(' ','2<x<=3',S1(2),'S2 = ',' ','1<=x<=2',S1(1),'S1 = ');
+x=1.5;
+if x>=1 & x<=2 then
+ i=1;
+else x>2 & x<=3
+ i=2;
+end
+disp(S(i,x),'y(1.5) = ')
+x=2;h1=0.01;
+for i=1:2
+ Sd(i,x)=(S(i,x+h1)-S(i,x))/h1
+end
+disp(Sd(2,2),Sd(1,2),'y`(2) = ')
\ No newline at end of file diff --git a/1670/CH5/EX5.52/5_52.png b/1670/CH5/EX5.52/5_52.png Binary files differnew file mode 100755 index 000000000..e719d4b98 --- /dev/null +++ b/1670/CH5/EX5.52/5_52.png diff --git a/1670/CH5/EX5.52/5_52.sce b/1670/CH5/EX5.52/5_52.sce new file mode 100755 index 000000000..d042b2201 --- /dev/null +++ b/1670/CH5/EX5.52/5_52.sce @@ -0,0 +1,40 @@ +//Example 5.52
+//Spline Interpolation
+//Page no. 205
+clc;close;clear;
+deff('y=S1(x)','y=18-(75*x)/2+26*x^2-11*x^3/2')
+deff('y=S2(x)','y=-70+(189*x)/2-(40*x^2)+(11*x^3)/2')
+x=2;h=0.01;
+S=[S1(x),S2(x)]
+for i=1:2
+ printf('\n S%i (%i) = %g\n',i-1,x,S(i))
+end
+deff('y=S3(x)','y=(S1(x+h)-S1(x))/h')
+deff('y=S4(x)','y=(S2(x+h)-S2(x))/h')
+S=[S3(x),S4(x)]
+for i=1:2
+ printf('\n S`%i (%i) = %g\n',i-1,x,S(i))
+end
+deff('y=S5(x)','y=(S3(x+h)-S3(x))/h')
+deff('y=S6(x)','y=(S4(x+h)-S4(x))/h')
+S=[S5(x),S6(x)]
+for i=1:2
+ printf('\n S``%i (%i) = %g\n',i-1,x,S(i))
+end
+printf('\n\n')
+for i=1:2
+ for j=1:3
+ if i==1 then
+ printf('\t%i',j)
+ elseif j<3
+ printf('\t%g',S1(j))
+ else
+ printf('\t%g',S2(j))
+ end
+ end
+ printf('\n')
+end
+x=[1:0.1:2]
+plot(x,S1(x))
+x=[2:0.1:3]
+plot(x,S2(x))
\ No newline at end of file diff --git a/1670/CH5/EX5.53/5_53.sce b/1670/CH5/EX5.53/5_53.sce new file mode 100755 index 000000000..431ce19bc --- /dev/null +++ b/1670/CH5/EX5.53/5_53.sce @@ -0,0 +1,34 @@ +//Example 5.53
+//Spline Interpolation
+//Page no. 206
+clc;close;clear;
+
+xi=[1,2,3];
+yi=[-3,4,23];
+h=1;n=2;
+x=poly(0,'x')
+m(2)=(6*(yi(3)-2*yi(2)+yi(1)))/4
+m(1)=0;m(3)=0;
+function [y]=S(i,x)
+ y=m(i)*(xi(i+1)-x)^3/(6*h)
+ y=y+m(i+1)*(x-xi(i))^3/(6*h)
+ y=y+(yi(i)/h-(m(i)*h)/6)*(xi(i+1)-x)
+ y=y+(yi(i+1)/h-(m(i+1)*h)/6)*(-xi(i)+x)
+endfunction
+for i=1:2
+ S1(i)=S(i);
+end
+printf('\n The required Spline is : \n')
+disp(' ','2<x<=3',S1(2),'S2 = ',' ','1<=x<=2',S1(1),'S1 = ');
+x=1.5;
+if x>=1 & x<=2 then
+ i=1;
+else x>2 & x<=3
+ i=2;
+end
+disp(S(i,x),'y(1.5) = ')
+x=1;h1=0.01;
+for i=1:1
+ Sd(i,x)=(S(i,x+h1)-S(i,x))/h1
+end
+disp(Sd(1,1),'y`(1) = ')
\ No newline at end of file diff --git a/1670/CH5/EX5.54/5_54.sce b/1670/CH5/EX5.54/5_54.sce new file mode 100755 index 000000000..6812d9e68 --- /dev/null +++ b/1670/CH5/EX5.54/5_54.sce @@ -0,0 +1,26 @@ +//Example 5.54
+//Spline Interpolation
+//Page no. 207
+clc;close;clear;
+
+xi=[0,1,2,3];
+yi=[1,-1,-1,0];
+h=1;n=3;
+x=poly(0,'x')
+m=[4,1;1,4];
+mb=[12;6];
+m=inv(m)*mb
+m(3)=m(2);
+m(2)=m(1);
+m(1)=0;m(4)=0;
+function [y]=S(i,x)
+ y=m(i)*(xi(i+1)-x)^3/(6*h)
+ y=y+m(i+1)*(x-xi(i))^3/(6*h)
+ y=y+(yi(i)/h-(m(i)*h)/6)*(xi(i+1)-x)
+ y=y+(yi(i+1)/h-(m(i+1)*h)/6)*(-xi(i)+x)
+endfunction
+for i=1:3
+ S1(i)=S(i);
+end
+printf('\n The required Spline is : \n')
+disp(' ',S1(3),'S3 = ',' ',S1(2),'S2 = ',' ',S1(1),'S1 = ');
\ No newline at end of file diff --git a/1670/CH5/EX5.6/5_6.sce b/1670/CH5/EX5.6/5_6.sce new file mode 100755 index 000000000..87ba9c325 --- /dev/null +++ b/1670/CH5/EX5.6/5_6.sce @@ -0,0 +1,14 @@ +//Example 5.6
+//Finite Differences
+//Page no. 132
+clc;close;clear;
+printf(' x\t f(x)\t df(x)\t d2f(x) d3f(x) d4f(x)\n')
+printf('------------------------------------------------------------------------------------------')
+x=[0,3;1,12;2,81;3,2000;4,100]
+for i=3:6
+ for j=1:7-i
+ x(j,i)=x(j+1,i-1)-x(j,i-1)
+ end
+end
+disp(x)
+disp(x(1,6),"d4 y(0) = ")
\ No newline at end of file |