summaryrefslogtreecommitdiff
path: root/964/CH18
diff options
context:
space:
mode:
Diffstat (limited to '964/CH18')
-rwxr-xr-x964/CH18/EX18.1/18_1.sce18
-rwxr-xr-x964/CH18/EX18.10/18_10.jpegbin0 -> 25006 bytes
-rwxr-xr-x964/CH18/EX18.10/18_10.sce24
-rwxr-xr-x964/CH18/EX18.2/18_2.sce19
-rwxr-xr-x964/CH18/EX18.3/18_3.sce29
-rwxr-xr-x964/CH18/EX18.4/18_4.sce22
-rwxr-xr-x964/CH18/EX18.5/18_5.sce27
-rwxr-xr-x964/CH18/EX18.6/18_6.sce12
-rwxr-xr-x964/CH18/EX18.7/18_7.sce13
-rwxr-xr-x964/CH18/EX18.8/18_8.jpegbin0 -> 25110 bytes
-rwxr-xr-x964/CH18/EX18.8/18_8.sce16
-rwxr-xr-x964/CH18/EX18.9/18_9.jpegbin0 -> 26585 bytes
-rwxr-xr-x964/CH18/EX18.9/18_9.sce54
13 files changed, 234 insertions, 0 deletions
diff --git a/964/CH18/EX18.1/18_1.sce b/964/CH18/EX18.1/18_1.sce
new file mode 100755
index 000000000..d59260cd3
--- /dev/null
+++ b/964/CH18/EX18.1/18_1.sce
@@ -0,0 +1,18 @@
+//clc()
+//f1(x) = f0(x) +(f(x1) - f(x0) *(x - x0)/ (x1 - x0)
+x = 2;
+x0 = 1;
+x1 = 6;
+m = 1.791759;
+n = 0;
+r = log(2);
+f = 0 + (m - n) * (x - x0) / (x1 - x0);
+disp(f,"value of ln2 for interpolation region 1 to 6 =")
+e = (r - f) * 100/r;
+disp("%",e,"error by interpolation for interval[1,6] =")
+x2 = 4;
+p = 1.386294;
+f = 0 + (p - n) * (x - x0) / (x2 - x0);
+disp(f,"value of ln2 for interpolation region 1 to 6 =")
+e = (r - f) * 100/r;
+disp("%",e,"error by interpolation for interval[1,6] =")
diff --git a/964/CH18/EX18.10/18_10.jpeg b/964/CH18/EX18.10/18_10.jpeg
new file mode 100755
index 000000000..11d9a7059
--- /dev/null
+++ b/964/CH18/EX18.10/18_10.jpeg
Binary files differ
diff --git a/964/CH18/EX18.10/18_10.sce b/964/CH18/EX18.10/18_10.sce
new file mode 100755
index 000000000..cd216b1f7
--- /dev/null
+++ b/964/CH18/EX18.10/18_10.sce
@@ -0,0 +1,24 @@
+//clc()
+x = [3,4.5,7,9];
+fx = [2.5,1,2.5,0.5];
+//we get the following equations for cubic splines
+//8*f"(4.5) + 2.5*f"(7) = 9.6
+//2.5*f"(4.5) + 9*f"(7) = -9.6
+//above two equations give
+m = 1.67909;//(m = f"(4.5))
+n = -1.53308;//(n = f"(7))
+//this values can be used to yield the final equation
+//f1(x) = 0.186566 * (x - 3)^3 + 1.66667*(4.5 - x) + 0.246894*(x - 3)
+//in similar manner other equations can be found too
+//f2(x) = 0.111939(7 - x)^3 - 0.102205*(x - 4.5)^3 - 0.299621 * (7 - x) + 1.638783 * (x - 4.5)
+//f3(x) = -0.127757*(9 - x)^3 + 1.761027 *(9 - x) + 0.25*(x - 7)
+x1 = 3:0.1:4.5;
+x2 = 4.5:0.1:7;
+x3 = 7:0.1:9;
+plot2d(x1,0.186566 * (x1 - 3)^3 + 1.66667*(4.5 - x1) + 0.246894*(x1 - 3));
+plot2d(x2,0.111939*(7 - x2)^3 - 0.102205*(x2 - 4.5)^3 - 0.299621 * (7 - x2) + 1.638783 * (x2 - 4.5));
+plot2d(x3,-0.127757*(9 - x3)^3 + 1.761027 *(9 - x3) + 0.25*(x3 - 7));
+xtitle("f(x) vs x","x","f(x)")
+x = 5;
+fx = 0.111939*(7 - x)^3 - 0.102205*(x - 4.5)^3 - 0.299621 * (7 - x) + 1.638783 * (x - 4.5);
+disp(fx,"The value at x = 5 is")
diff --git a/964/CH18/EX18.2/18_2.sce b/964/CH18/EX18.2/18_2.sce
new file mode 100755
index 000000000..c756ff3d6
--- /dev/null
+++ b/964/CH18/EX18.2/18_2.sce
@@ -0,0 +1,19 @@
+//clc()
+x = 2;
+x0 = 1;
+m = 0;
+x1 = 4;
+n = 1.386294;
+x2 = 6;
+p = 1.791759;
+b0 = m;
+b1 = (n - m)/(x1 - x0);
+b2 = ((p - n)/(x2 - x1) - (n - m)/(x1 - x0))/(x2 - x0);
+disp(b0,"b0 = ")
+disp(b1,"b1 = ")
+disp(b2,"b2 = ")
+f = b0 + b1*(x - x0) + b2*(x - x0)*(x - x1);
+disp(f,"f(2) = ")
+r = log(2);
+e = (r -f)*100/r;
+disp("%",e,"error = ")
diff --git a/964/CH18/EX18.3/18_3.sce b/964/CH18/EX18.3/18_3.sce
new file mode 100755
index 000000000..9ac650f7d
--- /dev/null
+++ b/964/CH18/EX18.3/18_3.sce
@@ -0,0 +1,29 @@
+//clc()
+x = 2;
+x0 = 1;
+m = 0;
+x1 = 4;
+n = 1.386294;
+x3 = 5;
+p = 1.609438;
+x2 = 6;
+o = 1.791759;
+f01 = (m - n)/(x0 - x1);
+f12 = (n - o)/(x1 - x2);
+f23 = (p - o)/(x3 - x2);
+f210 = (f12 - f01)/(x2 - x0);
+f321 = (f23 - f12)/(x3 - x1);
+f0123 = (f321 - f210) / (x3 - x0);
+b0 = m;
+b1 = f01;
+b2 = f210;
+b3 = f0123;
+disp(b0,"b0 = ")
+disp(b1,"b1 = ")
+disp(b2,"b2 = ")
+disp(b3,"b3 = ")
+f = b0 + b1*(x - x0) + b2*(x - x0)*(x - x1) + b3*(x - x0)*(x - x1)*(x - x2);
+disp(f,"f(2) = ")
+r = log(2);
+e = (r -f)*100/r;
+disp("%",e,"error = ")
diff --git a/964/CH18/EX18.4/18_4.sce b/964/CH18/EX18.4/18_4.sce
new file mode 100755
index 000000000..cac514243
--- /dev/null
+++ b/964/CH18/EX18.4/18_4.sce
@@ -0,0 +1,22 @@
+//clc()
+x = 2;
+x0 = 1;
+m = 0;
+x1 = 4;
+n = 1.386294;
+x3 = 5;
+p = 1.609438;
+x2 = 6;
+o = 1.791759;
+f01 = (m - n)/(x0 - x1);
+f12 = (n - o)/(x1 - x2);
+f23 = (p - o)/(x3 - x2);
+f210 = (f12 - f01)/(x2 - x0);
+f321 = (f23 - f12)/(x3 - x1);
+f0123 = (f321 - f210) / (x3 - x0);
+b0 = m;
+b1 = f01;
+b2 = f210;
+b3 = f0123;
+R2 = b3 * (x - x0) * (x - x1)*(x-x2);
+disp(R2,"error R2 = ")
diff --git a/964/CH18/EX18.5/18_5.sce b/964/CH18/EX18.5/18_5.sce
new file mode 100755
index 000000000..09b35ff9b
--- /dev/null
+++ b/964/CH18/EX18.5/18_5.sce
@@ -0,0 +1,27 @@
+clc;
+clear;
+x=[1 4 6 5 3 1.5 2.5 3.5];
+y=[0 1.3862944 1.7917595 1.6094379 1.0986123 0.4054641 0.9162907 1.2527630];
+n=8;
+for i=1:n
+ fdd(i,1)=y(i);
+end
+for j=2:n
+ for i=1:n-j+1
+ fdd(i,j)=(fdd(i+1,j-1)-fdd(i,j-1))/(x(i+j-1)-x(i));
+ end
+end
+xterm=1;
+yint(1)=fdd(1,1);
+
+for order=2:n
+ xterm=xterm*(2-x(order-1));
+ yint2=yint(order-1)+fdd(1,order)*xterm;
+ Ea(order-1)=yint2-yint(order-1);
+ yint(order)=yint2;
+
+end
+disp(yint,"F(x)=")
+disp(Ea,"Ea=")
+
+
diff --git a/964/CH18/EX18.6/18_6.sce b/964/CH18/EX18.6/18_6.sce
new file mode 100755
index 000000000..42f75071d
--- /dev/null
+++ b/964/CH18/EX18.6/18_6.sce
@@ -0,0 +1,12 @@
+//clc()
+x = 2;
+x0 = 1;
+m = 0;
+x1 = 4;
+n = 1.386294;
+x2 = 6;
+p = 1.791759;
+f1 = (x - x1)*m/((x0 - x)) + (x- x0) * n/(x1 - x0);
+disp(f1,"first order polynomial f1(2) = ")
+f2 = (x - x1)*(x - x2)*m/((x0 - x1)*(x0 - x2)) + (x - x0)*(x - x2)*n/((x1-x0)*(x1-x2)) + (x - x0)*(x - x1)*p/((x2 - x0)*(x2 - x1));
+disp(f2,"second order polynomial f2(2) = ")
diff --git a/964/CH18/EX18.7/18_7.sce b/964/CH18/EX18.7/18_7.sce
new file mode 100755
index 000000000..f4139fb5d
--- /dev/null
+++ b/964/CH18/EX18.7/18_7.sce
@@ -0,0 +1,13 @@
+//clc()
+z = 10;
+x =[1,3,5,7,13];
+v = [800,2310,3090,3940,4755];
+f1 = (z - x(5)) * v(4) / (x(4) - x(5)) + (z - x(4)) * v(5) / (x(5) - x(4));
+f2 = (z - x(4))*(z - x(5)) *v(3)/((x(3) - x(4))*(x(3) - x(5)))+(z - x(3))*(z - x(5)) *v(4)/((x(4) - x(3))*(x(4) - x(5)))+(z - x(4))*(z - x(3)) *v(5)/((x(5) - x(4))*(x(5) - x(3)));
+f3 = (z - x(3))*(z - x(4))*(z - x(5)) *v(2)/((x(2) - x(4))*(x(2) - x(5))*(x(2) - x(3)))+(z - x(4))*(z - x(2))*(z - x(5)) *v(3)/((x(3) - x(2))*(x(3) - x(5))*(x(3) - x(4)))+(z - x(2))*(z - x(3))*(z - x(5)) *v(4)/((x(4) - x(3))*(x(4) - x(2))*(x(4) - x(5)))+ (z - x(3))*(z - x(4))*(z - x(2)) *v(5)/((x(5) - x(4))*(x(5) - x(2))*(x(5) - x(3)));
+f4 = (z - x(2))*(z - x(3))*(z - x(4))*(z - x(5)) *v(1)/((x(1) - x(2))*(x(1) - x(4))*(x(1) - x(5))*(x(1) - x(3)))+ (z - x(1))*(z - x(3))*(z - x(4))*(z - x(5)) *v(2)/((x(2) - x(1))*(x(2) - x(4))*(x(2) - x(5))*(x(2) - x(3)))+(z - x(1))*(z - x(4))*(z - x(2))*(z - x(5)) *v(3)/((x(3) - x(1))*(x(3) - x(2))*(x(3) - x(5))*(x(3) - x(4)))+(z - x(1))*(z - x(2))*(z - x(3))*(z - x(5)) *v(4)/((x(4) - x(1))*(x(4) - x(3))*(x(4) - x(2))*(x(4) - x(5)))+ (z - x(1))*(z - x(3))*(z - x(4))*(z - x(2)) *v(5)/((x(5) - x(1))*(x(5) - x(4))*(x(5) - x(2))*(x(5) - x(3)));
+disp(f1,"Velocity at 10 sec by first order interpolation = ")
+disp(f2,"Velocity at 10 sec by second order interpolation = ")
+disp(f3,"Velocity at 10 sec by third order interpolation = ")
+disp(f4,"Velocity at 10 sec by fourth order interpolation = ")
+
diff --git a/964/CH18/EX18.8/18_8.jpeg b/964/CH18/EX18.8/18_8.jpeg
new file mode 100755
index 000000000..f39266a90
--- /dev/null
+++ b/964/CH18/EX18.8/18_8.jpeg
Binary files differ
diff --git a/964/CH18/EX18.8/18_8.sce b/964/CH18/EX18.8/18_8.sce
new file mode 100755
index 000000000..5467b8bad
--- /dev/null
+++ b/964/CH18/EX18.8/18_8.sce
@@ -0,0 +1,16 @@
+//clc()
+x = [3,4.5,7,9];
+fx = [2.5,1,2.5,0.5];
+m1 = (fx(2) - fx(1))/(x(2) - x(1));
+m2 = (fx(3) - fx(2))/(x(3) - x(2));
+m3 = (fx(4) - fx(3))/(x(4) - x(3));
+x1 = [3,4.5];
+x2 = [4.5,7];
+x3 = [7,9];
+plot2d(x1,m1*x1+5.5);
+plot2d(x2,m2*x2-1.7);
+plot2d(x3,m3*x3+9.5);
+xtitle("f(x) vs x","x","f(x)")
+r = 5
+z = m2*r -1.7;
+disp(z,"The value at x = 5 is")
diff --git a/964/CH18/EX18.9/18_9.jpeg b/964/CH18/EX18.9/18_9.jpeg
new file mode 100755
index 000000000..3bbb59253
--- /dev/null
+++ b/964/CH18/EX18.9/18_9.jpeg
Binary files differ
diff --git a/964/CH18/EX18.9/18_9.sce b/964/CH18/EX18.9/18_9.sce
new file mode 100755
index 000000000..c87c3d6a8
--- /dev/null
+++ b/964/CH18/EX18.9/18_9.sce
@@ -0,0 +1,54 @@
+//clc()
+x = [3,4.5,7,9];
+fx = [2.5,1,2.5,0.5];
+p = 4;
+n = 3;
+uk = n*(p-1);
+c = 2*n - 2;
+//20.25*a1 + 4.5*b1 + c1 = 1
+//20.25*a2 + 4.5*b2 + c2 = 1
+//49*a2 + 7*b2 + c2 = 2.5
+//49*a3 + 7*b3 + c3 = 2.5
+//9a1 + 3b1 + c1 = 2.5
+//81*a3 + 9*b3 + c3 = 0.5
+//9*a1 + b1 = 9*a2 + b2
+//14a2 + b2 = 14 *a3 + b3
+a1 = 0;
+//thus we have above 9 equations and 9 unknowns a1,a2,a3,b1,b2,b3,c1,c2,c3
+//thus we get
+A = [20.25,4.5,1,0,0,0,0,0,0;0,0,0,20.25,4.5,1,0,0,0;0,0,0,49,7,1,0,0,0;0,0,0,0,0,0,49,7,1;9,3,1,0,0,0,0,0,0;0,0,0,0,0,0,81,9,1;9,1,0,-9,-1,0,0,0,0;0,0,0,14,1,0,-14,-1,0;1,0,0,0,0,0,0,0,0];
+disp(A,"A = ")
+B = [1;1;2.5;2.5;2.5;0.5;0;0;0];
+disp(B,"B =")
+X = inv(A)*B;
+a1 = det(X(1,1));
+b1 = det(X(2,1));
+c1 = det(X(3,1));
+a2 = det(X(4,1));
+b2 = det(X(5,1));
+c2 = det(X(6,1));
+a3 = det(X(7,1));
+b3 = det(X(8,1));
+c3 = det(X(9,1));
+disp(a1,"a1 = ")
+disp(b1,"b1 = ")
+disp(c1,"c1 = ")
+disp(a2,"a2 = ")
+disp(b2,"b2 = ")
+disp(c2,"c2 = ")
+disp(a3,"a3 = ")
+disp(b3,"b3 = ")
+disp(c3,"c3 = ")
+//thus,f1(x) = -x + 5.5 3 < x < 4.5
+//f2(x) = 0.64*x^2 -6.76*x + 18.46 4.5 < x < 7
+//f3(x) = -1.6*x^2 + 24.6*x - 91.3 7 < x < 9
+x1 = 3:0.1:4.5;
+x2 = 4.5:0.1:7;
+x3 = 7:0.1:9;
+plot2d(x1,-x1 + 5.5);
+plot2d(x2,0.64*x2^2 -6.76*x2+ 18.46);
+plot2d(x3,-1.6*x3^2 + 24.6*x3 - 91.3);
+xtitle("f(x) vs x","x","f(x)")
+x = 5;
+fx = 0.64*x^2 -6.76*x + 18.46;
+disp(fx,"The value at x = 5 is")