diff options
Diffstat (limited to '260/CH7')
-rw-r--r-- | 260/CH7/EX7.1/7_1.sce | 7 | ||||
-rw-r--r-- | 260/CH7/EX7.2/7_2.sce | 7 | ||||
-rw-r--r-- | 260/CH7/EX7.3/7_3.sce | 52 | ||||
-rw-r--r-- | 260/CH7/EX7.4/7_4.sce | 55 | ||||
-rw-r--r-- | 260/CH7/EX7.5/7_5.sce | 53 | ||||
-rw-r--r-- | 260/CH7/EX7.6/7_6.sce | 58 | ||||
-rw-r--r-- | 260/CH7/EX7.7/7_7.sce | 54 | ||||
-rw-r--r-- | 260/CH7/EX7.8/7_8.sce | 59 | ||||
-rw-r--r-- | 260/CH7/EX7.9/7_9.sce | 41 |
9 files changed, 386 insertions, 0 deletions
diff --git a/260/CH7/EX7.1/7_1.sce b/260/CH7/EX7.1/7_1.sce new file mode 100644 index 000000000..a85d8dee2 --- /dev/null +++ b/260/CH7/EX7.1/7_1.sce @@ -0,0 +1,7 @@ +//Eg-7.1
+//pg-325
+
+clear
+clc
+
+printf('This is a theory question \n')
\ No newline at end of file diff --git a/260/CH7/EX7.2/7_2.sce b/260/CH7/EX7.2/7_2.sce new file mode 100644 index 000000000..b8062553f --- /dev/null +++ b/260/CH7/EX7.2/7_2.sce @@ -0,0 +1,7 @@ +//Eg-7.2
+//pg-326
+
+clear
+clc
+
+printf('This is a theory question \n')
\ No newline at end of file diff --git a/260/CH7/EX7.3/7_3.sce b/260/CH7/EX7.3/7_3.sce new file mode 100644 index 000000000..8c082eb81 --- /dev/null +++ b/260/CH7/EX7.3/7_3.sce @@ -0,0 +1,52 @@ +//Eg-7.3
+//pg-328
+
+clear
+clc
+
+//Using G and T in the place of greek alphabets 'gama' and 'tou'
+
+G = [0 5 10 15 20];
+T = [2.0 58.3 113.6 171.6 225.0];
+
+printf('\nThe equation is of the form : T = T0 + m*G\n')
+Gavg = sum(G)/length(G);
+
+Tavg = sum(T)/length(T);
+
+// Using S() for indicating 'sigma of'
+
+//using the equation a = S((xi - xavg) * (yi - yavg))/S(xi-xavg)^2;
+
+t = (G - Gavg).*(T - Tavg);
+
+u = (G - Gavg).*(G - Gavg);
+
+m = sum(t)/sum(u);
+
+printf(' The value of m = %f\n',m);
+
+T0 = Tavg - m*Gavg;
+
+printf(' The value of T0 = %f\n',T0);
+
+[r c] = size(G);
+
+
+Tmodel = T0*ones(r,c) + m*G;
+Texperiment = T;
+
+printf('\n i Tiexperimental Tmodel\n')
+for(i = 1:c)
+ printf(' %d %f %f\n',i-1,T(i),Tmodel(i))
+end
+
+p = sum((Tmodel - Tavg*ones(r,c)).*(Tmodel - Tavg*(ones(r,c))));
+
+q = sum((T - Tavg)^2);
+
+ r2 = p/q;
+
+ //using the equation [24]
+ printf('\nThe value of r^2 = %f\n',r2)
+
\ No newline at end of file diff --git a/260/CH7/EX7.4/7_4.sce b/260/CH7/EX7.4/7_4.sce new file mode 100644 index 000000000..1e32db5ec --- /dev/null +++ b/260/CH7/EX7.4/7_4.sce @@ -0,0 +1,55 @@ +//Eg-7.4
+//pg-336
+
+clear
+clc
+
+
+RH = [52 47 66 70 59 73 69];
+MC = [13 9 17 20 15 21 20];
+
+x = RH;
+y = MC;
+
+printf('\nAssuming that the equation is of the form : MC = c + m*RH\n')
+
+xavg = sum(x)/length(x);
+
+yavg = sum(y)/length(y);
+
+// Using S() for indicating 'sigma of'
+
+//using the equation a = S((xi - xavg) * (yi - yavg))/S(xi-xavg)^2;
+
+t = (x - xavg).*(y - yavg);
+
+u = (x - xavg).*(x - xavg);
+
+m = sum(t)/sum(u);
+
+printf(' The value of m = %f\n',m);
+
+c = yavg - m*xavg;
+
+printf(' The value of c = %f\n',c);
+
+[rx cx] = size(x);
+
+
+ymodel = c*ones(rx,cx) + m*x;
+yexperiment = y;
+
+printf('\n i MCiexperimental MCmodel\n')
+for(i = 1:cx)
+ printf(' %d %f %f\n',i-1,y(i),ymodel(i))
+end
+
+p = sum((ymodel - yavg*ones(rx,cx)).*(ymodel - yavg*(ones(rx,cx))));
+
+q = sum((y - yavg)^2);
+
+ r2 = p/q;
+
+ //using the equation [24]
+ printf('\nThe value of r^2 = %f\n',r2)
+
\ No newline at end of file diff --git a/260/CH7/EX7.5/7_5.sce b/260/CH7/EX7.5/7_5.sce new file mode 100644 index 000000000..eb44d18db --- /dev/null +++ b/260/CH7/EX7.5/7_5.sce @@ -0,0 +1,53 @@ +//Eg-7.5
+//pg-338
+
+clear
+clc
+
+x = [0 1 2 3 4];
+y = [1 2 9 22 41];
+
+m = length(x);
+n = 2; //since we have 2 variables
+
+//Using S for summation eg: Sx2y => summation(x^2*y)
+
+Sx = sum(x);
+
+Sx2 = sum(x.^2);
+
+Sx3 = sum(x.^3);
+
+Sx4 = sum(x.^4);
+
+Sy = sum(y);
+
+Sxy = sum(x.*y);
+
+Sx2y = sum((x.^2).*y);
+
+a(1,1) = Sx2 - (Sx)^2/m;
+a(1,2) = Sx3 - Sx*Sx2/m;
+a(2,1) = Sx3 - Sx2*Sx/m;
+a(2,2) = Sx4 - Sx2^2/m;
+
+c(1,1) = Sxy - Sx*Sy/m;
+c(2,1) = Sx2y - Sx2*Sy/m;
+
+printf('\nA =')
+disp(a)
+printf('c =')
+disp(c)
+
+b = inv(a)*c;
+
+printf('Solving the matrix equation Ab = c using matrix inversion gives\n\nb=')
+disp(b)
+
+//The coefficient 'alpha' can be obtained from equaiton 'alpha' = Sy/m - (b(1)*Sx + b(2)*Sx2)/m ;
+
+alpha = Sy/m - (b(1)*Sx + b(2)*Sx2)/m ;
+
+printf('\nThe coefficent alpha = %f\n',alpha)
+
+printf('\nThe lease square polynomial of second order is, thus \n y = %f + (%f)*x + (%f)*x^2\n\n',alpha,b(1),b(2))
diff --git a/260/CH7/EX7.6/7_6.sce b/260/CH7/EX7.6/7_6.sce new file mode 100644 index 000000000..d338b27f4 --- /dev/null +++ b/260/CH7/EX7.6/7_6.sce @@ -0,0 +1,58 @@ +//Eg-7.6
+//pg-345
+
+clear
+clc
+close()
+
+x = [10 20 30 40 50 60];
+y = [35 37 38 39 41 43];
+
+m = length(x);
+n = 2; //since we have 2 variables
+
+//Using S for summation eg: Sx2y => summation(x^2*y)
+
+Sx = sum(x);
+
+Sx2 = sum(x.^2);
+
+Sx3 = sum(x.^3);
+
+Sx4 = sum(x.^4);
+
+Sy = sum(y);
+
+Sxy = sum(x.*y);
+
+Sx2y = sum((x.^2).*y);
+
+a(1,1) = Sx2 - (Sx)^2/m;
+a(1,2) = Sx3 - Sx*Sx2/m;
+a(2,1) = Sx3 - Sx2*Sx/m;
+a(2,2) = Sx4 - Sx2^2/m;
+
+c(1,1) = Sxy - Sx*Sy/m;
+c(2,1) = Sx2y - Sx2*Sy/m;
+
+
+b = inv(a)*c;
+
+
+//The coefficient 'alpha' can be obtained from equaiton 'alpha' = Sy/m - (b(1)*Sx + b(2)*Sx2)/m ;
+
+alpha = Sy/m - (b(1)*Sx + b(2)*Sx2)/m ;
+
+printf('\nThe coefficent alpha = %f\n',alpha)
+
+printf('\nThe lease square polynomial of second order is, thus \n M = %f + (%f)*v + (%f)*v^2\n\n',alpha,b(1),b(2))
+
+deff('out = func(in)','out = alpha + b(1)*in + b(2)*in^2')
+
+printf('The fit of the polynomial is shown in the figure\n')
+
+plot(x,y,'bo')
+plot(x,func(x))
+legend('data points given','polynomial got by regression')
+xlabel('v,kmph')
+ylabel('M,kmpl')
\ No newline at end of file diff --git a/260/CH7/EX7.7/7_7.sce b/260/CH7/EX7.7/7_7.sce new file mode 100644 index 000000000..4e0fc9961 --- /dev/null +++ b/260/CH7/EX7.7/7_7.sce @@ -0,0 +1,54 @@ +//Eg-7.7
+//pg-346
+
+clear
+clc
+close()
+
+x0 = [1 2 3 4 5];
+x1 = [0.11 0.25 0.37 0.42 0.55];
+y = [8.3 13.7 22.5 27.9 34.4];
+
+//Using A in the place of greek alphabet 'alpha'
+//Using equations [34],[35] to get the elements of the coefficient matrix and the components on the right-hand side of y = A + b1*x0 + b2*x1;
+
+//Using S for summation eg: Sx02y => summation(x0^2*y)
+
+m = length(y);
+n = 2; //since there are only 2 variables
+
+Sx0 = sum(x0);
+
+Sx02 = sum(x0.^2);
+
+Sx1 = sum(x1);
+
+Sx12 = sum(x1.^2);
+
+Sx0x1 = sum(x0.*x1);
+
+Sy = sum(y);
+
+Sx0y = sum(x0.*y);
+
+Sx1y = sum(x1.*y);
+
+
+
+a(1,1) = Sx02 - Sx0^2/m;
+a(1,2) = Sx0x1 - Sx0*Sx1/m;
+a(2,1) = a(1,2);
+a(2,2) = Sx12 - Sx1^2/m;
+
+c(1,1) = Sx0y - Sx0*Sy/m;
+c(2,1) = Sx1y - Sx1*Sy/m;
+
+b = inv(a)*c;
+
+//Using equation [37] to compute the coefficient A
+
+A = (Sy - (b(1)*Sx0 + b(2)*Sx1))/m;
+
+printf('\nThe lease square polynomial of second order is, thus \n y = %f + (%f)*x0 + (%f)*x1\n\n',A,b(1),b(2))
+
+printf('Note: The small error compared to the text-book is because of the calculation mistake in the text-book\n')
\ No newline at end of file diff --git a/260/CH7/EX7.8/7_8.sce b/260/CH7/EX7.8/7_8.sce new file mode 100644 index 000000000..7d7a9c43f --- /dev/null +++ b/260/CH7/EX7.8/7_8.sce @@ -0,0 +1,59 @@ +//Eg-7.8
+//pg-354
+
+clear
+clc
+
+y = [3.21 3.25 4 3.62 3.76 4.55 5.32 4.39 4.59 5 3.68 3.18 5 0 3.7 3.4 0 2.33];
+
+x(1,1:18) = [0.12 0.12 0.17 0.24 0.1 0.11 0.10 0.10 0.17 0.17 0.15 0.23 0.21 0.37 0.28 0.32 0.28 0.22];
+
+x(2,1:18) = [3.2 2.7 2.7 2.8 2.6 2.0 2.0 2.0 2.2 2.4 2.4 2.2 1.9 2.3 2.4 3.3 3.5 3.0];
+
+x(3,1:18) = [0.01 0 0 0 0 0.02 0.07 0.02 0.03 0.04 0.02 0.1 0.04 0.14 0.05 0.08 0.12 0.06];
+
+n = 3; //since there are 3 variables
+m = length(y);
+
+
+for(i = 1:n)
+ for(j = 1:n)
+ a(i,j) = sum(x(i,:).*x(j,:)) - (sum(x(i,:))*sum(x(j,:)))/m;
+ end
+end
+
+//disp(a)
+for(i = 1:n)
+ c(i) = sum(x(i,:).*y) - (sum(x(i,:)*sum(y)))/m;
+end
+
+b = inv(a)*c;
+
+//disp(b)
+
+s = sum(b'*x)
+
+al = (sum(y) - s)/m;
+
+//disp(al)
+
+
+b1 = b(1);
+b2 = b(2);
+b3 = b(3);
+
+
+
+deff('out = func(in1, in2, in3)','out = al + b1*in1 + b2*in2 + b3*in3')
+
+y1 = func(x(1,:),x(2,:),x(3,:));
+
+//disp(y1)
+
+yb(1,1:m) = sum(y)/m;
+
+r2 = sum((y1 - yb)^2)/sum((y - yb)^2);
+
+printf('\nThe equation finally is y = %f + (%f)b0 + (%f)b1 + (%f)b2\n',al,b(1),b(2),b(3))
+
+printf('The value of r^2 is %f\n', r2)
\ No newline at end of file diff --git a/260/CH7/EX7.9/7_9.sce b/260/CH7/EX7.9/7_9.sce new file mode 100644 index 000000000..3ee7180cc --- /dev/null +++ b/260/CH7/EX7.9/7_9.sce @@ -0,0 +1,41 @@ +//Eg-7.9
+//pg-355
+
+clear
+clc
+
+y = [2 9 24 47 78];
+
+t = [0 1 2 3 4];
+
+//since P0 = 1 b0 will be as
+
+P0 = [1 1 1 1 1];
+b0 = sum(y)/5;
+
+//P1 = t-G1
+
+G1 = sum(t)/5;
+
+//b1 = summation(P1*y)/summation(P1^2)
+
+P1 = t - [G1 G1 G1 G1 G1];
+
+b1 = sum(P1.*y)/sum(P1^2);
+
+
+//P2 = (t-G2)P1 - d2
+
+//G2 = summation(t*P1^2)/summation(P1^2)
+
+G2 = sum(t.*P1^2)/sum(P1^2);
+
+//d2 = summation(t*P1*P0)/summation(P0^2)
+
+d2 = sum(t.*P1.*P0)/sum(P0^2);
+
+P2 = (t-[G2 G2 G2 G2 G2]).*P1 - [d2 d2 d2 d2 d2]
+
+b2 = sum(P2.*y)/sum(P2^2);
+
+printf('Therefore the expression is V = (%f)P0 + (%f)P1 + (%f)P2,\n where P0 = 1, P1 = (t-2), P2 = (t-2)\n\n Finally V = 4*t^2 + 3*t + 2\n\n',b0,b1,b2)
\ No newline at end of file |