diff options
Diffstat (limited to '260/CH5')
-rw-r--r-- | 260/CH5/EX5.1/5_1.sce | 34 | ||||
-rw-r--r-- | 260/CH5/EX5.10/5_10.sce | 40 | ||||
-rw-r--r-- | 260/CH5/EX5.11/5_11.sce | 7 | ||||
-rw-r--r-- | 260/CH5/EX5.12/5_12.sce | 106 | ||||
-rw-r--r-- | 260/CH5/EX5.13/5_13.sce | 65 | ||||
-rw-r--r-- | 260/CH5/EX5.14/5_14.sce | 25 | ||||
-rw-r--r-- | 260/CH5/EX5.15/5_15.sce | 7 | ||||
-rw-r--r-- | 260/CH5/EX5.16/5_16.sce | 12 | ||||
-rw-r--r-- | 260/CH5/EX5.17/5_17.sce | 20 | ||||
-rw-r--r-- | 260/CH5/EX5.18/5_18.sce | 15 | ||||
-rw-r--r-- | 260/CH5/EX5.2/5_2.sce | 11 | ||||
-rw-r--r-- | 260/CH5/EX5.3/5_3.sce | 33 | ||||
-rw-r--r-- | 260/CH5/EX5.4/5_4.sce | 37 | ||||
-rw-r--r-- | 260/CH5/EX5.5/5_5.sce | 27 | ||||
-rw-r--r-- | 260/CH5/EX5.6/5_6.sce | 21 | ||||
-rw-r--r-- | 260/CH5/EX5.7/5_7.sce | 27 | ||||
-rw-r--r-- | 260/CH5/EX5.8/5_8.sce | 19 | ||||
-rw-r--r-- | 260/CH5/EX5.9/5_9.sce | 52 |
18 files changed, 558 insertions, 0 deletions
diff --git a/260/CH5/EX5.1/5_1.sce b/260/CH5/EX5.1/5_1.sce new file mode 100644 index 000000000..90d9b5ce6 --- /dev/null +++ b/260/CH5/EX5.1/5_1.sce @@ -0,0 +1,34 @@ +//Eg-5.1
+//pg-213
+
+clear
+clc
+
+A=[1 -1 4;3 2 -1;2 1 -1];
+d=spec(A);
+
+//eigen equation
+
+printf('the eigen equation is(L-%f)(L-(%f))(L-%f)=0',d(1),d(2),d(3));
+
+//eigen values
+
+disp(d)
+
+//Verification
+
+e=diag(A);
+f=det(A);
+
+if sum(e)==sum(d)&prod(d)==f then
+ disp("verification done")
+end
+
+//Eigen Vectors
+
+[v,d]=spec(A);
+
+disp("eigen vectors corresponding to each eigenvalue are are columns of the following matrix")
+disp(v)
+
+printf('\n\nThe eigen vectors are different because each set of equations have infinite solutions and the ones given in the text book are just one of them.\n')
\ No newline at end of file diff --git a/260/CH5/EX5.10/5_10.sce b/260/CH5/EX5.10/5_10.sce new file mode 100644 index 000000000..108510fdd --- /dev/null +++ b/260/CH5/EX5.10/5_10.sce @@ -0,0 +1,40 @@ +//Eg-5.10
+//pg-235
+
+clear
+clc
+
+A=[1 0.5 .5;0.5 0.5 0;0.5 0 1];
+z=[1;1;1];
+ for i=1:50
+ a=A*z;
+ b=(sum(a.^2))^.5;
+ z=a/b;
+ z0=z;
+end
+
+B=A-(b*z*z');
+ for i=1:50
+ c=B*z;
+ d=(sum(c.^2))^.5;
+ z=c/d;
+ z1=-z;
+end
+
+C=B-(d*z1*z1');
+ for i=1:50
+ e=C*z;
+ f=(sum(e.^2))^.5;
+ z=e/f;
+ z2=z;
+end
+
+disp("eigen values")
+disp(b)
+disp(d)
+disp(f)
+disp("corresponding eigen vectors")
+disp(z0)
+disp(z1)
+disp(z2)
+
diff --git a/260/CH5/EX5.11/5_11.sce b/260/CH5/EX5.11/5_11.sce new file mode 100644 index 000000000..b938a7cfd --- /dev/null +++ b/260/CH5/EX5.11/5_11.sce @@ -0,0 +1,7 @@ +//Eg-5.11
+//pg-239
+
+clear
+clc
+
+printf('Theoretical Question\n')
\ No newline at end of file diff --git a/260/CH5/EX5.12/5_12.sce b/260/CH5/EX5.12/5_12.sce new file mode 100644 index 000000000..b519b3b41 --- /dev/null +++ b/260/CH5/EX5.12/5_12.sce @@ -0,0 +1,106 @@ +//Eg-5.12
+//pg-242
+
+clear
+clc
+
+A=[1 2 3;2 3 5;3 5 5];
+
+//Iteration Number----1
+
+//for i=1,j=2
+sigma=sum(diag(A).^2);
+S=sum(A.^2);
+q=abs(A(1,1)-A(2,2));
+p=2*A(1,2)*q/(A(1,1)-A(2,2));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U=[cosalp sinalp 0;sinalp -cosalp 0;0 0 1];
+
+//for i=1,j=3
+A1=inv(U)*A*U;
+
+q=abs(A1(1,1)-A1(3,3));
+p=2*A1(1,3)*q/(A1(1,1)-A1(3,3));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U1=[cosalp 0 sinalp;0 1 0;sinalp 0 -cosalp];
+
+
+//for i=2,j=3
+A2=inv(U1)*A1*U1;
+
+q=abs(A2(2,2)-A2(3,3));
+p=2*A2(2,3)*q/(A2(2,2)-A2(3,3));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U2=[1 0 0 ;0 cosalp sinalp;0 sinalp -cosalp];
+
+A3=inv(U2)*A2*U2;
+
+sig2=sum(diag(A3.^2));
+T=U*U1*U2;
+
+//Iteration number ---2
+
+A=A3;
+//for i=1,j=2
+sigma=sum(diag(A).^2);
+S=sum(A.^2);
+q=abs(A(1,1)-A(2,2));
+p=2*A(1,2)*q/(A(1,1)-A(2,2));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U=[cosalp sinalp 0;sinalp -cosalp 0;0 0 1];
+
+//for i=1,j=3
+A1=inv(U)*A*U;
+
+q=abs(A1(1,1)-A1(3,3));
+p=2*A1(1,3)*q/(A1(1,1)-A1(3,3));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U1=[cosalp 0 sinalp;0 1 0;sinalp 0 -cosalp];
+
+
+//for i=2,j=3
+A2=inv(U1)*A1*U1;
+
+q=abs(A2(2,2)-A2(3,3));
+p=2*A2(2,3)*q/(A2(2,2)-A2(3,3));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U2=[1 0 0 ;0 cosalp sinalp;0 sinalp -cosalp];
+
+A3=inv(U2)*A2*U2;
+T6=T*U*U1*U2;
+
+sig3=sum(diag(A3.^2));
+
+printf('The values of the sigmas are\n sigma1 = %f\n sigma2 = %f\n',sig2,sig3)
+T = A.^2;
+Sumofsqrs = sum(T);
+printf('\nThe sum of squares of the elements of the given original matrix = %f\n',Sumofsqrs)
+printf('\nSum of squares of all elements is equal to sigma2\n')
+printf('\nThe eigen values are as follows\n')
+disp(diag(A3))
+printf('\nThe corresponding eigen vectors are columns of the following matrix\n')
+disp(T6)
+for(i = 1:3)
+ eigenv(i) = A3(i,i);
+end
+
+printf('\n\nThe checklist given at the end of the problem \n')
+printf('\n1. The sum of eigen values = %f\n The trace of the original matrix = %f\n',sum(eigenv),trace(A))
+printf('\n2. The product of eigenvalues = %f\n The determinant of the original matrix = %f\n',eigenv(1)*eigenv(2)*eigenv(3),det(A))
+
+ dot(1) = sum(T6(:,1).*T6(:,2));
+ dot(2) = sum(T6(:,1).*T6(:,3));
+ dot(3) = sum(T6(:,3).*T6(:,2));
+printf('\n3. The dot product of eigen vectors 1&2 = %f\n The dot product of eigen vectors 1&3 = %f\n The dot product of eigen vectors 3&2 = %f\n=> The eigen vecotrs are orthonormal\n',dot(1),dot(2),dot(3))
\ No newline at end of file diff --git a/260/CH5/EX5.13/5_13.sce b/260/CH5/EX5.13/5_13.sce new file mode 100644 index 000000000..a723af6c0 --- /dev/null +++ b/260/CH5/EX5.13/5_13.sce @@ -0,0 +1,65 @@ +//Eg-5.13
+//pg-250
+
+clear
+clc
+
+A=[0 1.5 1;1.5 0 0.5;1 0.5 0];
+iter=1;
+imax=100;
+sig2=0;
+S=sum(A.^2);
+T=eye(3,3);
+
+//A(1,1)=A(2,2)=A(3,3),,,so in this case sinalp=cosalp=(1/2)^.5
+while sig2~=S&iter<imax
+//for i=1,j=2
+sigma=sum(diag(A).^2);
+cosalp=(1/2)^.5;
+sinalp=(1/2)^.5;
+U=[cosalp sinalp 0;sinalp -cosalp 0;0 0 1];
+
+//for i=1,j=3
+A1=inv(U)*A*U;
+
+q=abs(A1(1,1)-A1(3,3));
+p=2*A1(1,3)*q/(A1(1,1)-A1(3,3));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U1=[cosalp 0 sinalp;0 1 0;sinalp 0 -cosalp];
+
+
+//for i=2,j=3
+A2=inv(U1)*A1*U1;
+
+q=abs(A2(2,2)-A2(3,3));
+p=2*A2(2,3)*q/(A2(2,2)-A2(3,3));
+spq=(p^2+q^2)^.5;
+cosalp=((1+q/spq)/2)^.5;
+sinalp=p/(2*cosalp*spq);
+U2=[1 0 0 ;0 cosalp sinalp;0 sinalp -cosalp];
+
+A3=inv(U2)*A2*U2;
+
+sig2=sum(diag(A3.^2));
+iter=iter+1;
+T=T*U*U1*U2;
+end
+printf('Note that the eigen values are in a different order from that on the text book and the part B is printed first and then the part A\n')
+disp(A)
+disp("eigen values")
+disp(diag(A3))
+disp("eigen vectors are columns of the following matrix")
+disp(T)
+
+
+B=[1 8 7 6;8 7 3 4;7 3 2 1;6 4 1 5];
+[v,d]=spec(B);
+disp(B)
+disp("eigen values")
+disp(d)
+disp("eigen vectors are columns of the following matrix")
+disp(v)
+
+
diff --git a/260/CH5/EX5.14/5_14.sce b/260/CH5/EX5.14/5_14.sce new file mode 100644 index 000000000..1a3e2fe4d --- /dev/null +++ b/260/CH5/EX5.14/5_14.sce @@ -0,0 +1,25 @@ +//Eg-5.14
+//pg-252
+
+clear
+clc
+
+A=[1 3 6;3 5 7;6 7 4];
+k=1;
+summ=0;
+for i=2:3
+ summ=summ+A(1,i)^2;
+end
+sig=summ^.5;
+
+w1=0;
+w2=(.5*(1+(abs(A(1,2)/sig))))^.5;
+w3=A(1,3)/(2*sig*w2);
+
+w=[w1;w2;w3];
+
+B=eye(3,3)-2*w*w';
+A1=inv(B)*A*B;
+
+disp("required tridiagonal matrix is")
+disp(A1)
\ No newline at end of file diff --git a/260/CH5/EX5.15/5_15.sce b/260/CH5/EX5.15/5_15.sce new file mode 100644 index 000000000..17458f6f2 --- /dev/null +++ b/260/CH5/EX5.15/5_15.sce @@ -0,0 +1,7 @@ +//Eg-5.15
+//pg-253
+
+clear
+clc
+
+printf('Theoretical Question\n')
\ No newline at end of file diff --git a/260/CH5/EX5.16/5_16.sce b/260/CH5/EX5.16/5_16.sce new file mode 100644 index 000000000..3e22cf362 --- /dev/null +++ b/260/CH5/EX5.16/5_16.sce @@ -0,0 +1,12 @@ +//Eg-5.16
+//pg-257
+
+clear
+clc
+
+A=[4 -2 2 8;-2 6 2 4;2 2 10 -6;8 4 -6 12];
+
+T=hess(A);
+
+disp("required tridiagonal matrix is")
+disp(T)
\ No newline at end of file diff --git a/260/CH5/EX5.17/5_17.sce b/260/CH5/EX5.17/5_17.sce new file mode 100644 index 000000000..4db2fef14 --- /dev/null +++ b/260/CH5/EX5.17/5_17.sce @@ -0,0 +1,20 @@ +//Eg-5.17
+//pg-259
+
+clear
+clc
+
+A=[1 3 6;3 5 7;6 7 4];
+T = [1 -6.7082 0;-6.7082 9.8 4.6;0 4.6 -0.8]; //The corresponding tridigonal matrix
+
+x = poly(0,'x');
+
+p = det(A - x*eye(3,3));
+q = det(T - x*eye(3,3));
+
+printf('\nThe characteristic polynomial of the orignal matrix A is ')
+disp(p)
+printf('\nThe characteristic polynomial of the tridiagonal matrix of A is ')
+disp(q)
+
+printf('\n\nIt is clear that both the polynomials are almost the same.\n')
diff --git a/260/CH5/EX5.18/5_18.sce b/260/CH5/EX5.18/5_18.sce new file mode 100644 index 000000000..d3eb7a414 --- /dev/null +++ b/260/CH5/EX5.18/5_18.sce @@ -0,0 +1,15 @@ +//Eg-5.18
+//pg-260
+
+clear
+clc
+
+A=[1 3 6;3 5 7;6 7 4];
+
+for l=20:-2:-6
+ p0l=1;
+ p1l=A(1,1)-l;
+ p2l=(A(2,2)-l)*p1l-A(1,2)^2;
+ p3l=(A(3,3)-l)*p2l-p1l*A(2,3)^2;
+ printf('lambda=%f,phi0lambda=%f,phi02ambda=%f,phi03ambda=%f',l,p0l,p1l,p2l,p3l)
+end
\ No newline at end of file diff --git a/260/CH5/EX5.2/5_2.sce b/260/CH5/EX5.2/5_2.sce new file mode 100644 index 000000000..06c2d3455 --- /dev/null +++ b/260/CH5/EX5.2/5_2.sce @@ -0,0 +1,11 @@ +//Eg-5.2
+//pg-216
+
+clear
+clc
+
+A=[1 -1 4;3 2 -1;2 1 -1];
+
+if (A^3)-2*(A^2)-(5*A)+6*eye(3,3)==zeros(3,3) then
+ disp("cayley-hamiliton theorem was verified")
+end
\ No newline at end of file diff --git a/260/CH5/EX5.3/5_3.sce b/260/CH5/EX5.3/5_3.sce new file mode 100644 index 000000000..93d21cf8c --- /dev/null +++ b/260/CH5/EX5.3/5_3.sce @@ -0,0 +1,33 @@ +//Eg-5.3
+//pg-217
+
+clear
+clc
+
+A=[5 3;3 5];
+
+[v,d]=spec(A);
+
+//Eigen equation and values
+printf('the eigen equation is(l-%f)(l-%f)=0',d(1),d(2));
+disp("eigen values")
+disp(d)
+
+//eigen vectors
+//corresponding to d(1)
+g=v(1:2,1);
+h=v(1:2,2);
+disp("eigen vectors")
+disp(g)
+disp(h)
+
+//checking orthogonality
+if g'*h==0 then
+ disp("the given eigen vectors are orthogonal")
+end
+
+//checking orthonormality
+
+if round(g'*g)==1& round(h'*h)==1 then
+ disp("the given eigen vectors are orthonormal")
+end
\ No newline at end of file diff --git a/260/CH5/EX5.4/5_4.sce b/260/CH5/EX5.4/5_4.sce new file mode 100644 index 000000000..2abbf2796 --- /dev/null +++ b/260/CH5/EX5.4/5_4.sce @@ -0,0 +1,37 @@ +//Eg-5.4
+//pg-219
+
+clear
+clc
+
+exec graf.sci
+clc
+A=[1 2 4;3 1 2;4 2 5];
+
+a1=zeros(3,1);
+a1(1)=trace(A);
+A1=A;
+
+for k=2:3
+ A2=A*(A1-a1(k-1)*eye(3,3));
+ a1(k)=trace(A2)/k;
+ A1=A2;
+end
+
+C=[1; -a1];
+
+for(i = 1:4)
+ c(i) = C(5-i);
+end
+
+ce = poly(c,'x','c');
+
+printf('\nThe expression of the characteristic equation is \n')
+
+disp(ce)
+printf('\n')
+for(i = 1:4)
+ G(1,i) = c(5-i);
+end
+
+q = graf(G,0.001);
\ No newline at end of file diff --git a/260/CH5/EX5.5/5_5.sce b/260/CH5/EX5.5/5_5.sce new file mode 100644 index 000000000..2e07532d4 --- /dev/null +++ b/260/CH5/EX5.5/5_5.sce @@ -0,0 +1,27 @@ +//Eg-5.5
+//pg-223
+
+clear
+clc
+
+A=[0.35 0.15;0.15 .1];
+
+a1=zeros(2,1);
+a1(1)=trace(A);
+A1=A;
+
+for k=2
+ A2=A*(A1-a1(k-1)*eye(2,2));
+ a1(k)=trace(A2)/k;
+end
+
+c=[1; -a1];
+
+disp("hence coefficients of eigen equation are as follows in decreasing order of polynomial")
+disp(c)
+
+p=[c(1),c(2),c(3)];
+s=roots(p);
+
+disp("hence eigen valuesi.e principal moments of inertia are....")
+disp(s)
\ No newline at end of file diff --git a/260/CH5/EX5.6/5_6.sce b/260/CH5/EX5.6/5_6.sce new file mode 100644 index 000000000..8d2b91677 --- /dev/null +++ b/260/CH5/EX5.6/5_6.sce @@ -0,0 +1,21 @@ +//Eg-5.6
+//pg-225
+
+clear
+clc
+
+A=[1 2 4;3 1 2;4 2 5];
+ z=[1;1;1];
+for i=1:7
+ printf('iteration number=%f\n',i);
+ a=A*z;
+ b=(sum(a.^2))^.5;
+ printf('dominant eigen value=%f\n',b);
+ z=a/b;
+ printf('z=%f\n',z);
+end
+
+disp("from iterations dominant eigen value converged to ")
+disp(b)
+disp("after 7 iterations")
+disp("its value is positive from equation 30");
\ No newline at end of file diff --git a/260/CH5/EX5.7/5_7.sce b/260/CH5/EX5.7/5_7.sce new file mode 100644 index 000000000..326e7e921 --- /dev/null +++ b/260/CH5/EX5.7/5_7.sce @@ -0,0 +1,27 @@ +//Eg-5.7
+//pg-230
+
+clear
+clc
+
+A=[0 1 1 1;1 0 1 1;1 1 0 1;1 1 1 0];
+ z=[1;0;0;0];
+ for i=1:20
+ printf('iteration number=%f\n',i);
+ a=A*z;
+ b=(sum(a.^2))^.5;
+ printf('dominant eigen value=%f\n',b);
+ z=a/b;
+ printf('z=%f\n',z);
+end
+
+disp("from iterations dominant eigen value converged to ")
+disp(b)
+disp("after 20 iterations")
+
+
+if round((A-b*eye(4,4))*z)==0 then
+ disp("dominant eigen value is positive")
+else
+ disp("dominant eigen value is negative")
+end
diff --git a/260/CH5/EX5.8/5_8.sce b/260/CH5/EX5.8/5_8.sce new file mode 100644 index 000000000..28bab45ab --- /dev/null +++ b/260/CH5/EX5.8/5_8.sce @@ -0,0 +1,19 @@ +//Eg-5.8
+//pg-231
+
+clear
+clc
+
+A=[1 2 4;3 1 2;4 2 5];
+invA=inv(A);
+z=[1;1;1];
+for i=1:25
+ a=invA*z;
+ b=(sum(a.^2))^.5;
+ z=a/b;
+end
+
+la_d=b;
+minval=1/b;
+disp("minimum eigen value of A")
+disp(minval)
diff --git a/260/CH5/EX5.9/5_9.sce b/260/CH5/EX5.9/5_9.sce new file mode 100644 index 000000000..e44d632f2 --- /dev/null +++ b/260/CH5/EX5.9/5_9.sce @@ -0,0 +1,52 @@ +//Eg-5.9
+//pg-232
+
+clear
+clc
+
+A = [0 1 1.5;-5 -0.5 1;-1 2 3.5];
+z = [1;1;1];
+lambda = zeros(3,1);
+z_in = z;
+
+for(i = 1:50)
+ a = A*z;
+ b = (sum(a.^2))^.5;
+ lambda(1) = b;
+ z = a/b;
+ z0 = z;
+end
+
+
+B = A - lambda(1)*eye(3,3);
+y = B*z_in;
+
+for(i = 1:50)
+ c = B*y;
+ d = (sum(c.^2))^.5;
+ lambda(2) = d;
+ y = c/d;
+ z1 = y;
+end
+
+C = (A - lambda(1)*eye(3,3))*(A - lambda(2)*eye(3,3));
+u = C*z_in;
+
+for(i = 1:50)
+ e = C*u;
+ f = (sum(e.^2))^.5;
+ lambda(3) = f;
+ u = e/f;
+ z2 = u;
+end
+
+disp("eigen values")
+disp(lambda)
+
+disp("corresponding eigen vectors")
+disp(z0)
+disp(z1)
+disp(z2)
+
+
+//Note that the eigen vector corresponding to lambda value of 1 is not matching with that in the text book, the method followed here is giving correct answers for the other two eigen values. So the eigen vector given in the book is wrong.
|