diff options
Diffstat (limited to '260/CH10')
-rw-r--r-- | 260/CH10/EX10.1/10_1.sce | 62 | ||||
-rw-r--r-- | 260/CH10/EX10.10/10_10.sce | 53 | ||||
-rw-r--r-- | 260/CH10/EX10.11/10_11.sce | 13 | ||||
-rw-r--r-- | 260/CH10/EX10.12/10_12.sce | 13 | ||||
-rw-r--r-- | 260/CH10/EX10.2/10_2.sce | 77 | ||||
-rw-r--r-- | 260/CH10/EX10.3/10_3.sce | 77 | ||||
-rw-r--r-- | 260/CH10/EX10.4/10_4.sce | 7 | ||||
-rw-r--r-- | 260/CH10/EX10.5/10_5.sce | 39 | ||||
-rw-r--r-- | 260/CH10/EX10.6/10_6.sce | 54 | ||||
-rw-r--r-- | 260/CH10/EX10.7/10_7.sce | 19 | ||||
-rw-r--r-- | 260/CH10/EX10.8/10_8.sce | 22 | ||||
-rw-r--r-- | 260/CH10/EX10.9/10_9.sce | 25 |
12 files changed, 461 insertions, 0 deletions
diff --git a/260/CH10/EX10.1/10_1.sce b/260/CH10/EX10.1/10_1.sce new file mode 100644 index 000000000..a040edd6e --- /dev/null +++ b/260/CH10/EX10.1/10_1.sce @@ -0,0 +1,62 @@ +//Eg-10.1
+//pg-430
+
+clear
+clc
+
+//Since the interpolating polynomial is of order 3 we have 4 unknown coefficients a0,a1,a2,a3.
+
+//The polynomial finally looks like a3x^3 + a2*x^2 + a1*x + a0 = f(x)
+
+x = [1;2;3;4];
+
+for(i = 1:4)
+ for(j = 1:4)
+ A(i,j) = x(i)^(j-1);
+ end
+end
+
+
+
+B = [2;3.5;3;4];
+
+T(1:4,1:4) = A;
+T(:,5) = B;
+
+
+
+//Gauss Elimination
+
+for(i = 2:4)
+ T(i,:) = T(i,:) - T(1,:)
+end
+
+for(i = 3:4)
+ T(i,:) = T(i,:) - T(i,2)/T(1,2)*(T(2,:));
+end
+
+
+T(4,:) = T(4,:) - T(4,3)/T(3,3)*(T(3,:));
+
+
+for(i=1:4)
+ T(i,:) = T(i,:)/T(i,i);
+end
+
+for(i = 1:3)
+ T(4-i,:) = T(4-i,:) - T(4,:)*T(4-i,4);
+
+end
+
+for(i = 1:2)
+ T(3-i,:) = T(3-i,:) - T(3,:)*T(3-i,3);
+end
+
+T(1,:) = T(1,:) - T(2,:);
+
+X = T(:,5);
+
+h = poly(X,'x',"coeff")
+
+disp(X)
+disp(h)
diff --git a/260/CH10/EX10.10/10_10.sce b/260/CH10/EX10.10/10_10.sce new file mode 100644 index 000000000..b7313da96 --- /dev/null +++ b/260/CH10/EX10.10/10_10.sce @@ -0,0 +1,53 @@ +//Eg-10.10
+//pg-449
+
+clear
+clc
+
+x = [1 2 4];
+y = [5 8.6 3.1];
+
+//Refer to pg-448 for these conditions
+//condition 1 gives
+// 4a1 + 2b1 + c1 = 8.6
+//condition 2 gives
+// 16a1 + 4b1+c1 = 3.1
+//condition 3 gives
+// 4a0 + b0 = 4a1 + b1
+//condition 4 gives
+// a0 = 0
+
+A = [2 1 0 0 0;0 0 4 2 1;1 1 0 0 0;0 0 16 4 1;1 0 -4 -1 0];
+B = [8.6;8.6;5;3.1;0];
+
+//The above conditions repesented in matrix equation form Ax = B can be solved for x as
+//x = [b0;c0;a1;b1;c1]
+
+x = inv(A)*B;
+
+b0 = x(1);
+c0 = x(2);
+a1 = x(3);
+b1 = x(4);
+c1 = x(5);
+
+x = poly(0,'x');
+
+printf('The expressions for the splines are \n')
+p = b0*x + c0;
+q = a1*x^2 + b1*x + c1;
+
+disp(p,q)
+
+x1 = 1:0.01:2;
+x2 = 2:0.01:4;
+
+y1 = horner(p,x1);
+y2 = horner(q,x2);
+
+plot(x1,y1,x2,y2)
+
+xlabel('x')
+ylabel('y')
+
+legend('Spline 1','Spline 2')
\ No newline at end of file diff --git a/260/CH10/EX10.11/10_11.sce b/260/CH10/EX10.11/10_11.sce new file mode 100644 index 000000000..cc9a71428 --- /dev/null +++ b/260/CH10/EX10.11/10_11.sce @@ -0,0 +1,13 @@ +//Eg-10.11
+//pg-452
+
+clear
+clc
+close()
+
+x = [1 2 3];
+y = [2.5 3.7 1.7];
+
+exec cubicspline.sci
+
+cubicspline(x,y)
diff --git a/260/CH10/EX10.12/10_12.sce b/260/CH10/EX10.12/10_12.sce new file mode 100644 index 000000000..c76415324 --- /dev/null +++ b/260/CH10/EX10.12/10_12.sce @@ -0,0 +1,13 @@ +//Eg-10.12
+//pg-458
+
+clear
+clc
+close()
+
+x = [1.04 1.11 1.19 1.32 1.47 1.6 1.79 1.97 2.15 2.34 2.48 2.64 2.76 2.86 2.96];
+y = [3.7 3.87 4 4.14 4.26 4.32 4.37 4.39 4.38 4.33 4.26 4.14 4.01 3.86 3.70];
+
+exec cubicspline.sci
+
+cubicspline(x,y)
\ No newline at end of file diff --git a/260/CH10/EX10.2/10_2.sce b/260/CH10/EX10.2/10_2.sce new file mode 100644 index 000000000..7f2621cbf --- /dev/null +++ b/260/CH10/EX10.2/10_2.sce @@ -0,0 +1,77 @@ +//Eg-10.2
+//pg-432
+
+clear
+clc
+close()
+// A = (x-x0)/h = 0.1*(x-30)
+//A is the greek alphabet 'alpha'
+
+Y = [31.8;55.3;92.5;149.4];
+
+X = [30;40;50;60];
+
+T = zeros(4,4);
+
+T(:,1) = Y;
+
+for(j = 2:4)
+ for(i = 1:4+1-j)
+ T(i,j) = T(i+1,j-1) - T(i,j-1);
+ end
+end
+
+//disp(T)
+
+//from equation [10], the interpolating polunomial is
+
+//p3 = f(x0) + A*Df(x0) + A(A-1)/2!*D2f(x0) + A(A-1)(A-2)/3!*D3f(x0)
+
+//note that A is used in place of 'alpha' and D in place of 'delta'
+
+// The above expression p3 can also be written as
+
+//p3 = f(x0) + A * [ Df(x0) - D2f(x0)/2 + 1/3*D3f(x0) ] + A^2 * [ D2f(x0)/2 - 1/2*D3f(x0)] + A^3/6 * D3f(x0)..............call this expression 1
+
+f = T(1,1);
+Df = T(1,2);
+D2f = T(1,3);
+D3f = T(1,4);
+
+//Substituting the values of D,D2,D3 in the expression 1 we finally get
+
+// p3 = a0 + a1*A + a2*A^2 + a3*A^3
+
+a0 = f;
+a1 = Df - D2f/2 + 1/3*D3f;
+a2 = D2f/2 - 1/2*D3f;
+a3 = 1/6*D3f;
+
+//disp(a0,a1,a2,a3)
+
+//Now taking A = 0.1*(x-30)
+
+//p3 = b0 + b1*x + b2*x^2 + b3*x^3
+
+b0 = a0 -3*a1 + 9*a2 - 27*a3;
+b1 = 0.1*a1 - 0.6*a2 + 2.7*a3;
+b2 = 0.01*a2 - 0.09*a3;
+b3 = 0.001*a3;
+
+//disp(b3,b2,b1,b0)
+
+printf('The polynomial is p(T) = (%f)*T^3 + (%f)*T^2 + (%f)*T + (%f)\n',b3,b2,b1,b0)
+
+deff('out = func(in)','out = b3*in^3 + b2*in^2 + b1*in + b0')
+
+
+x = 30:60;
+y = func(x);
+
+plot(x,y)
+plot(X,Y,'db')
+
+legend('Interpolated polynomial','Experimental data points')
+
+xlabel('Temperature')
+ylabel('Vapour Pressure of Water')
diff --git a/260/CH10/EX10.3/10_3.sce b/260/CH10/EX10.3/10_3.sce new file mode 100644 index 000000000..5c341492e --- /dev/null +++ b/260/CH10/EX10.3/10_3.sce @@ -0,0 +1,77 @@ +//Eg-10.3
+//pg-434
+
+clear
+clc
+close()
+
+// A = (x-xn)/h = (x-x3)/h = (0.05*x-5)
+//A is the greek alphabet 'alpha'
+
+Y = [205;201;195;190];
+
+X = [40;60;80;100];
+
+T = zeros(4,4);
+
+T(:,1) = Y;
+
+for(j = 2:4)
+ for(i = 1:4+1-j)
+ T(i,j) = T(i+1,j-1) - T(i,j-1);
+ end
+end
+
+//disp(T)
+
+//from equation [14], the interpolating polunomial is
+
+//p3 = f(x3) + A*Df(x3) + A*(A+1)/2!*D2f(x3) + A*(A+1)*(A+2)/3!*D3f(x3)
+
+//note that A is used in place of 'alpha' and D in place of 'delta'
+
+// The above expression p3 can also be written as
+
+//p3 = f(x3) + A * [ Df(x3) + D2f(x3)/2 + 1/3*D3f(x3) ] + A^2 * [ D2f(x3)/2 + 1/2*D3f(x3)] + A^3/6 * D3f(x3)..............call this expression 1
+
+f = T(4,1);
+Df = T(3,2);
+D2f = T(2,3);
+D3f = T(1,4);
+
+//Substituting the values of D,D2,D3 in the expression 1 we finally get
+
+// p3 = a0 + a1*A + a2*A^2 + a3*A^3
+
+a0 = f;
+a1 = Df + D2f/2 + 1/3*D3f;
+a2 = D2f/2 + 1/2*D3f;
+a3 = 1/6*D3f;
+
+//disp(a0,a1,a2,a3)
+
+//Now taking A = 0.05*x - 5
+
+//p3 = b0 + b1*x + b2*x^2 + b3*x^3
+
+b0 = a0 -5*a1 +25*a2 - 125*a3;
+b1 = 0.05*a1 - 0.5*a2 + 3.75*a3;
+b2 = 0.0025*a2 - 0.0375*a3;
+b3 = 12.5*10^(-5)*a3;
+
+//disp(b3,b2,b1,b0)
+
+printf('The polynomial is p(T) = (%f)*T^3 + (%f)*T^2 + (%f)*T + (%f)\n',b3,b2,b1,b0)
+
+deff('out = func(in)','out = b3*in^3 + b2*in^2 + b1*in + b0')
+
+
+x = 40:100;
+y = func(x);
+
+plot(x,y)
+plot(X,Y,'db')
+
+legend('Interpolated polynomial','Experimental data points')
+xlabel('Temperature')
+ylabel('Energy')
\ No newline at end of file diff --git a/260/CH10/EX10.4/10_4.sce b/260/CH10/EX10.4/10_4.sce new file mode 100644 index 000000000..c9bef0c79 --- /dev/null +++ b/260/CH10/EX10.4/10_4.sce @@ -0,0 +1,7 @@ +//Eg-10.4
+//pg-435
+
+clear
+clc
+close()
+printf('This is a theory question\n')
\ No newline at end of file diff --git a/260/CH10/EX10.5/10_5.sce b/260/CH10/EX10.5/10_5.sce new file mode 100644 index 000000000..7074fb0b5 --- /dev/null +++ b/260/CH10/EX10.5/10_5.sce @@ -0,0 +1,39 @@ +//Eg-10.5
+//pg-437
+
+clear
+clc
+close()
+
+X = [0;5;10;15];
+
+Y = [53;127;213;378];
+
+T = zeros(4,4);
+
+T(:,1) = Y;
+
+for(j = 2:4)
+ for(i = 1:4+1-j)
+ T(i,j) = T(i+1,j-1) - T(i,j-1);
+ end
+end
+
+//disp(T)
+
+// Using Gauss backward formula
+
+//p3 = f + d*A + d2*A(A+1)/2 + d3*A*(A-1)*(A+1)/6
+
+//Note that 'alpha' is replaced by A and 'small delta' by d
+
+f = T(3,1);
+d = T(2,2);
+d2 = T(2,3);
+d3 = T(1,4);
+
+A = (7-10)/5;
+
+p37 = f + d*A + d2*A*(A+1)/2 + d3*A*(A-1)*(A+1)/6;
+
+printf('Therefore, the number of houses after seven years is %d\n',p37)
diff --git a/260/CH10/EX10.6/10_6.sce b/260/CH10/EX10.6/10_6.sce new file mode 100644 index 000000000..050d86723 --- /dev/null +++ b/260/CH10/EX10.6/10_6.sce @@ -0,0 +1,54 @@ +//Eg-10.6
+//pg-440
+
+clear
+clc
+close()
+
+X = [3;5;6;9];
+
+Y = [293;508;585;764];
+
+T = zeros(4,4);
+
+T(:,1) = Y;
+
+for(j = 2:4)
+ for(i = 1:4+1-j)
+ T(i,j) = (T(i+1,j-1) - T(i,j-1))/(X(j-1+i) - X(i));
+ end
+end
+
+//disp(T)
+
+//p3 = a0 + a1 * (x-3) + a2 * (x-3)*(x-5) + a3 * (x-3)*(x-5)*(x-6)
+
+a0 = T(1,1);
+a1 = T(1,2);
+a2 = T(1,3);
+a3 = T(1,4);
+
+//p3 = b0 + b1*x + b2*x^2 + b3*x^3
+
+b0 = a0 + 15*a2 - 3*a1 -90*a3;
+b1 = a1 - 8*a2 + 63*a3;
+b2 = a2 - 14*a3;
+b3 = a3;
+
+//disp(b0,b1,b2,b3)
+
+deff('out = func(in)','out = b0 + b1*in + b2*in^2 + b3*in^3')
+
+x = 3:9;
+y = func(x);
+plot(x,y)
+
+plot(X,Y,'db')
+
+legend('Divided difference polynomial of order 3','Experimental data')
+
+xlabel('F')
+ylabel('P')
+
+
+
diff --git a/260/CH10/EX10.7/10_7.sce b/260/CH10/EX10.7/10_7.sce new file mode 100644 index 000000000..1062655ac --- /dev/null +++ b/260/CH10/EX10.7/10_7.sce @@ -0,0 +1,19 @@ +//Eg-10.7
+//pg-442
+
+clear
+clc
+close()
+
+x = [0;2;5];
+y = [0;2.5;6.9];
+
+exec lagrange.sci
+
+p = lagrange(x,y,2)
+
+printf('The polynomial is \n')
+disp(p)
+k = horner(p,3)
+
+printf('\nThe value of the polynomial at x = 3 is %f\n',k)
\ No newline at end of file diff --git a/260/CH10/EX10.8/10_8.sce b/260/CH10/EX10.8/10_8.sce new file mode 100644 index 000000000..49a30eff0 --- /dev/null +++ b/260/CH10/EX10.8/10_8.sce @@ -0,0 +1,22 @@ +//Eg-10.8
+//pg-445
+
+clear
+clc
+
+T = [0 80 146.9 207.6 265 320.2 373.7 426.1 477.7 528.3 578.1 627.1 675.3];
+
+y = [0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000];
+
+exec lagrange.sci
+
+p = lagrange(y,T,3)
+
+printf('The third order polynomial interpolating the given data points is \n')
+disp(p)
+
+D = [625 2143 3215 5785];
+k = horner(p,D)
+
+printf('\n\nThe values of temperature at given EMF values are \n')
+disp(k)
\ No newline at end of file diff --git a/260/CH10/EX10.9/10_9.sce b/260/CH10/EX10.9/10_9.sce new file mode 100644 index 000000000..0a4aad2b0 --- /dev/null +++ b/260/CH10/EX10.9/10_9.sce @@ -0,0 +1,25 @@ +//Eg-10.9
+//Pg-447
+
+clear
+clc
+
+x = [6 9 14 17.5 20];
+y = [5 3.04 4.68 2.7 4.75];
+
+n = length(x); //no. of data points
+
+for(i = 1:n-1)
+ s(i,1) = (y(i+1)-y(i))/(x(i+1)-x(i));
+end
+
+
+
+x = poly(0,'x');
+
+for(i = 1:n-1)
+ f(i) = y(i) - s(i)*(x-6);
+end
+
+printf('The expressions for first order splines are :\n')
+disp(f)
\ No newline at end of file |