diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /1332/CH11 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '1332/CH11')
22 files changed, 557 insertions, 0 deletions
diff --git a/1332/CH11/EX11.1/11_1.pdf b/1332/CH11/EX11.1/11_1.pdf Binary files differnew file mode 100755 index 000000000..ed2819e08 --- /dev/null +++ b/1332/CH11/EX11.1/11_1.pdf diff --git a/1332/CH11/EX11.1/11_1.sce b/1332/CH11/EX11.1/11_1.sce new file mode 100755 index 000000000..8149a5d76 --- /dev/null +++ b/1332/CH11/EX11.1/11_1.sce @@ -0,0 +1,17 @@ +//Example 11.1
+//Eigenvalues and Eigenvectors
+//Page no. 333
+clc;clear;close;
+
+A1=[0.6;0.2];A2=[-0.2;0.6];A3=[-0.6;-0.2];A4=[0.2;-0.6];
+T=[1.1,-0.3;-0.3,1.9];
+B1=T*A1;B2=T*A2;B3=T*A3;B4=T*A4;
+disp(B4,B3,B2,B1,'The transformed vectors are :')
+disp('These points lie on the ellipse:')
+printf(' 2 2\n(x-3y)+(3x+y)\n------ ------\n 16 4\n\n')
+A5=[0;2/sqrt(10)];
+disp('The vector (0,2/10^(1/2)) lies on the circle:')
+printf(' 2 2\nx + y = 4\n -\n 10\n\n')
+B5=T*A5;
+disp('Also lies on the same ellipse',B5)
+printf('\n\nWe can see that there is a linear relationship between the first 4 vectors and their respective transformend vectors through the scalars known as eigenvectors and eigenvalues respectively')
\ No newline at end of file diff --git a/1332/CH11/EX11.10/11_10.pdf b/1332/CH11/EX11.10/11_10.pdf Binary files differnew file mode 100755 index 000000000..f586d6d7a --- /dev/null +++ b/1332/CH11/EX11.10/11_10.pdf diff --git a/1332/CH11/EX11.10/11_10.sce b/1332/CH11/EX11.10/11_10.sce new file mode 100755 index 000000000..bb91d6b91 --- /dev/null +++ b/1332/CH11/EX11.10/11_10.sce @@ -0,0 +1,49 @@ +//Example 11.10
+//LU Method
+//Page no. 363
+clc;close;clear;
+
+A=[120,80,40,-16;80,120,16,-40;40,16,120,-80;-16,-40,-80,120];
+disp(A,"A =")
+L=eye(4,4);
+for l=1:20
+for j=1:4
+ for i=1:j
+ k=0
+ for p=1:i-1
+ k=k-A(i,p)*A(p,j)
+ end
+ A(i,j)=A(i,j)+k
+ end
+ for i=j+1:4
+ k=0;
+ for p=1:j-1
+ k=k-A(i,p)*A(p,j)
+ end
+ A(i,j)=(A(i,j)+k)/A(j,j)
+ end
+end
+disp(A,"Modified A = ")
+ for i=1:4
+ for j=1:4
+ if i>j then
+ L(i,j)=A(i,j)
+ else
+ U(i,j)=A(i,j)
+ end
+ end
+end
+disp(U,"U =",L,"L =")
+A=U*L;
+printf('\n\nAfter %i iterations, matrix A =\n\n',l)
+for i=1:4
+ for j=1:4
+ printf(' %.2f\t',A(i,j))
+ end
+ printf('\n')
+end
+end
+printf('\n\nTherefore the eigenvalues are the diagonal elements f the transformed triangular matrix are:\n\n')
+for i=1:4
+ printf(' %.2f,',A(i,i))
+end
\ No newline at end of file diff --git a/1332/CH11/EX11.11/11_11.pdf b/1332/CH11/EX11.11/11_11.pdf Binary files differnew file mode 100755 index 000000000..cc1ab5a87 --- /dev/null +++ b/1332/CH11/EX11.11/11_11.pdf diff --git a/1332/CH11/EX11.11/11_11.sce b/1332/CH11/EX11.11/11_11.sce new file mode 100755 index 000000000..745b06f80 --- /dev/null +++ b/1332/CH11/EX11.11/11_11.sce @@ -0,0 +1,119 @@ +//Example 11.11
+//Generalized Eigenvalue Problem
+//Page no. 365
+clc;close;clear;
+
+A=[1,1,0.5;1,1,0.25;0.5,0.25,2]
+B=[2,2,2;2,5,5;2,5,11]
+disp(B,"B =",A,"A =")
+for i=1:3
+ G(i,i)=sqrt(B(i,i))
+end
+G=[B;eye(3,3)];
+
+//transformation to frobenius matrix
+for k=3:-1:2
+ g(k)=0;
+ for j=1:k-1
+ if(g(k)<G(k,j))
+ g(k)=G(k,j)
+ p=j;
+ end
+ end
+ if(g(k)~=0)
+ for j=1:3
+ r(1,j)=G(k,j)
+ end
+ for i=1:6
+ G(i,k-1)=G(i,k-1)/g(k)
+ end
+ for j=1:3
+ if(j~=k-1)
+ l=G(k,j)
+ for i=1:6
+ G(i,j)=G(i,j)-l*G(i,k-1)
+ end
+ end
+ end
+ end
+ for j=1:3
+ for i=1:3
+ c(i,1)=G(i,j)
+ end
+ G(k-1,j)=0
+ for i=1:3
+ G(k-1,j)=G(k-1,j)+r(1,i)*c(i,1)
+ end
+ end
+end
+
+//partition g
+for i=4:6
+ for j=1:3
+ T(i-3,j)=G(i,j)
+ end
+end
+
+//eigenvalues computation
+p=poly(B,'x')
+a=roots(p)
+printf('\n\nDiagonalized Matrix B = \n\n')
+for i=1:3
+ for j=1:3
+ if i~=j then
+ B(i,j)=0
+ else
+ B(i,j)=a(i)
+ end
+ end
+end
+disp(B)
+//eigenvectors computation
+for k=1:3
+ m=2
+ for l=1:3
+ y(l,k)=a(k)^(m)
+ m=m-1;
+ end
+end
+printf('\n\n')
+
+
+for k=1:3
+ for l=1:3
+ y1(l,1)=y(l,1)
+ y2(l,1)=y(l,2)
+ y3(l,1)=y(l,3)
+ end
+ x1=T*y3;
+ x2=T*y2;
+ x3=T*y1;
+end
+printf('\n\nEigenvectors of B are :\n\n')
+for i=1:3
+ printf('|%.5f|\t\t|%.5f|\t\t|%.5f|',x3(i,1),x2(i,1),x1(i,1))
+ printf('\n')
+end
+x=[x3,x2,x1]
+
+
+
+
+
+B=[2,2,2;2,5,5;2,5,11]
+G=0
+for i=1:3
+ for j=1:3
+ if i==j then
+ G(i,j)=sqrt(B(i,j))
+ else
+ G(i,j)=0;
+ end
+ end
+end
+
+B=inv(G)*x'*A*x*inv(G)
+disp(B,"Eigenvectors of A =")
+
+printf('\n\n\nNote : Computation Error in book in caculation of eigenvector of B thus for A')
+
diff --git a/1332/CH11/EX11.2/11_2.pdf b/1332/CH11/EX11.2/11_2.pdf Binary files differnew file mode 100755 index 000000000..78f0fd729 --- /dev/null +++ b/1332/CH11/EX11.2/11_2.pdf diff --git a/1332/CH11/EX11.2/11_2.sce b/1332/CH11/EX11.2/11_2.sce new file mode 100755 index 000000000..4bb0413f5 --- /dev/null +++ b/1332/CH11/EX11.2/11_2.sce @@ -0,0 +1,43 @@ +//Example 11.2
+//Leverrier's Method
+//Page no. 337
+clc;close;clear;
+
+A=[2,2,2;2,5,5;2,5,1];
+A1=A;
+C(1)=0;
+ for j=1:3
+ for k=1:3
+ if(j==k)
+ C(1)=C(1)+A1(j,k)
+ end
+ end
+ end
+ disp(A,'A=')
+ disp(A1,'A1=')
+ printf('\nC1=')
+ disp(C(1));
+for i=2:3
+ A2=A*(A1-C(i-1)*eye(3,3));
+ printf('\n\n\nA%i=',i)
+ disp(A2);
+ C(i)=0;
+ for j=1:3
+ for k=1:3
+ if(j==k)
+ C(i)=C(i)+A2(j,k)/i
+ end
+ end
+ end
+ printf('\nC%i=',i)
+ disp(C(i))
+ A1=A2;
+end
+printf('\n\n\nTherefore the characteristic polynomial is:\n 3 2\nx - %ix - %ix %i = 0',C(1),C(2),C(3))
+
+//verification
+printf('\n\nVerification:')
+s=poly(0,"s");
+p=poly(A,'x');
+A=A-eye(3,3)*%s;
+disp(p,'=',A)
diff --git a/1332/CH11/EX11.3/11_3.pdf b/1332/CH11/EX11.3/11_3.pdf Binary files differnew file mode 100755 index 000000000..afc59990b --- /dev/null +++ b/1332/CH11/EX11.3/11_3.pdf diff --git a/1332/CH11/EX11.3/11_3.sce b/1332/CH11/EX11.3/11_3.sce new file mode 100755 index 000000000..f25a0d626 --- /dev/null +++ b/1332/CH11/EX11.3/11_3.sce @@ -0,0 +1,90 @@ +//Example 11.3
+//Danilevsky Method
+//Page no. 341
+clc;close;clear;
+
+A=[-1,0,0;1,-2,3;0,2,-3];
+G=[A;eye(3,3)];
+disp(G);
+//transformation to frobenius matrix
+for k=3:-1:2
+ g(k)=0;
+ for j=1:k-1
+ if(g(k)<G(k,j))
+ g(k)=G(k,j)
+ p=j;
+ end
+ end
+ if(g(k)~=0)
+ for j=1:3
+ r(1,j)=G(k,j)
+ end
+ for i=1:6
+ G(i,k-1)=G(i,k-1)/g(k)
+ end
+ disp(G)
+ for j=1:3
+ if(j~=k-1)
+ l=G(k,j)
+ for i=1:6
+ G(i,j)=G(i,j)-l*G(i,k-1)
+ end
+ end
+ end
+ disp(G)
+ end
+ for j=1:3
+ for i=1:3
+ c(i,1)=G(i,j)
+ end
+ G(k-1,j)=0
+ for i=1:3
+ G(k-1,j)=G(k-1,j)+r(1,i)*c(i,1)
+ end
+ end
+ disp(G)
+end
+
+//partition g
+for i=4:6
+ for j=1:3
+ T(i-3,j)=G(i,j)
+ end
+end
+disp(T,'T=')
+
+//eigenvalues computation
+printf('\n\n\nCharateristic polynomial:')
+p=poly(A,'x')
+disp(p)
+printf('\n\n\nEigenvalues:')
+a=roots(p)
+disp(a')
+//eigenvectors computation
+for k=1:3
+ m=2
+ for l=1:3
+ y(l,k)=a(k,1)^(m)
+ m=m-1;
+ end
+end
+printf('\n\n')
+disp(y,'y=')
+
+//eigenvector computation
+
+for k=1:3
+ for l=1:3
+ y1(l,1)=y(l,1)
+ y2(l,1)=y(l,2)
+ y3(l,1)=y(l,3)
+ end
+ x1=T*y3;
+ x2=T*y2;
+ x3=T*y1;
+end
+printf('\n\nEigenvectors :\n')
+for i=1:3
+ printf('|%.1f|\t\t|%.1f|\t\t|%.1f|',x1(i,1),x2(i,1),x3(i,1))
+ printf('\n')
+end
diff --git a/1332/CH11/EX11.4/11_4.pdf b/1332/CH11/EX11.4/11_4.pdf Binary files differnew file mode 100755 index 000000000..7afaedb01 --- /dev/null +++ b/1332/CH11/EX11.4/11_4.pdf diff --git a/1332/CH11/EX11.4/11_4.sce b/1332/CH11/EX11.4/11_4.sce new file mode 100755 index 000000000..6e787e59a --- /dev/null +++ b/1332/CH11/EX11.4/11_4.sce @@ -0,0 +1,19 @@ +//Example 11.4
+//Power Method
+//Page no. 345
+clc;close;clear;
+
+A=[1,2;3,4];
+e=0.001;
+q0=[1;1];
+for i=1:5
+ q1=A*q0;
+ a=max(q1)
+ for j=1:2
+ q2(j)=q1(j)/a;
+ end
+ printf('\nq(%i) = %.4f a = %.4f Scaled q(%i) = %.4f\n %.4f %i\n\n',i,q1(1),a,i,q2(1),q1(2),q2(2))
+ q1=q2;
+ q0=q1;
+end
+printf('Hence the largest eigenvalue is %.4f with the corresponding eigenvector as %.4f\n %i',a,q0(1),q0(2))
\ No newline at end of file diff --git a/1332/CH11/EX11.5/11_5.pdf b/1332/CH11/EX11.5/11_5.pdf Binary files differnew file mode 100755 index 000000000..1db354995 --- /dev/null +++ b/1332/CH11/EX11.5/11_5.pdf diff --git a/1332/CH11/EX11.5/11_5.sce b/1332/CH11/EX11.5/11_5.sce new file mode 100755 index 000000000..8c4c7be78 --- /dev/null +++ b/1332/CH11/EX11.5/11_5.sce @@ -0,0 +1,41 @@ +//Example 11.5
+//Inverse Power Method
+//Page no. 347
+clc;close;clear;
+
+A=[7,6,-3;-12,-20,24;-6,-12,16];
+e=10^-6;
+X=[1;1;1];
+B=0;
+Y=[0;0;0]
+a=0;l=0;
+for i=1:2
+ printf('When a=%i\n',a);
+ C=A-a*eye();
+ disp(C,"C=")
+ C_1=inv(C);
+ disp(C_1,"Inverse of C=");
+ printf('\n\nItr lambda X')
+ printf('\n------------------------------------------------------------------\n')
+ for j=1:10
+ printf('\n%i %f %f %f %f',j-1,l,X(1),X(2),X(3));
+ Y=C_1*X;
+ B=max(Y);
+ e1=abs(l-B);
+ X=Y/B;
+ m=0;
+ for k=1:3
+ m=m+(Y(k)-X(k))^2;
+ end
+ e2=sqrt(m);
+ er=max(e1,e2);
+ if(er<e)
+ break
+ end
+ l=B;
+
+ end
+ a=-3;
+ printf('\n\n\n\n')
+end
+printf('\n\n\nNote : Computation of Y is wrong given in the book')
\ No newline at end of file diff --git a/1332/CH11/EX11.6/11_6.pdf b/1332/CH11/EX11.6/11_6.pdf Binary files differnew file mode 100755 index 000000000..614f45376 --- /dev/null +++ b/1332/CH11/EX11.6/11_6.pdf diff --git a/1332/CH11/EX11.6/11_6.sce b/1332/CH11/EX11.6/11_6.sce new file mode 100755 index 000000000..1ead55877 --- /dev/null +++ b/1332/CH11/EX11.6/11_6.sce @@ -0,0 +1,26 @@ +//Example 11.6
+//Rayleigh Quotient
+//Page no. 348
+clc;close;clear;
+
+A=[10,7,8,7;7,5,6,5;8,6,10,9;7,5,9,10];
+q0=[1;1;1;1];
+for i=0:4
+ X=(A^i)*q0;
+ l=(X'*A*X)/(X'*X)
+ printf('\nLambda(%i) = %f\n',i+1,l)
+end
+printf('\n\nDominant Eigenvalue = %f\n\n\n',l)
+
+e=0.001;
+for i=1:5
+ q1=A*q0;
+ a=max(q1)
+ for j=1:4
+ q2(j)=q1(j)/a;
+ end
+
+ q1=q2;
+ q0=q1;
+end
+disp(q2,'Corresponding Eigenvector = ')
\ No newline at end of file diff --git a/1332/CH11/EX11.7/11_7.pdf b/1332/CH11/EX11.7/11_7.pdf Binary files differnew file mode 100755 index 000000000..537aae140 --- /dev/null +++ b/1332/CH11/EX11.7/11_7.pdf diff --git a/1332/CH11/EX11.7/11_7.sce b/1332/CH11/EX11.7/11_7.sce new file mode 100755 index 000000000..4aba85754 --- /dev/null +++ b/1332/CH11/EX11.7/11_7.sce @@ -0,0 +1,49 @@ +//Example 11.7
+//Jacobi's Method
+//Page no. 355
+clc;close;clear;
+
+A=[1,1,1/2;1,1,1/4;1/2,1/4,2];
+C=A;
+V=[sqrt(2),0,1/2;sqrt(2),0,1/4;3/(4*sqrt(2)),-1/(4*sqrt(2)),2]
+S=eye(3,3)
+disp(A,"A =")
+VI=0;
+for i=1:3
+ for j=1:3
+ if(i~=j)
+ VI=VI+A(i,j)^2 //initial off diag norm
+ end
+ end
+end
+VI=sqrt(VI);
+VF=VI*10^-7; //final threshold
+V1=VI/3;
+o=poly(0,"o");
+for i=1:3
+for q=2:3
+ for p=q-1:-1:1
+ if(A(p,q)>V1)
+ a=-A(p,q);
+ b=(A(p,p)-A(q,q))/2
+ if(b~=0)
+ w=b*abs(1/b)*(a/sqrt(a^2+b^2));
+ else
+ w=(a/sqrt(a^2+b^2));
+ end
+ sin0=w/sqrt(2*(1+sqrt(1-w^2)));
+ cos0=sqrt(1-sin0^2)
+ end
+ B(p,p)=A(p,p)*cos0^2+A(q,q)*sin0^2-2*A(p,q)*sin0*cos0
+ B(q,q)=A(p,p)*sin0^2+A(q,q)*cos0^2+2*A(p,q)*sin0*cos0
+ B(p,q)=(A(p,p)-A(q,q))*sin0*cos0+A(p,q)*(cos0^2-sin0^2)
+ S(i,i)=S(i,i)
+ S(i,p)=S(i,p)*cos0-S(i,q)*sin0
+ S(i,q)=S(i,p)*sin0+S(i,q)*cos0
+
+ end
+end
+end
+disp(B,"B =")
+disp(S,"S =")
+printf('\n\n\nComputation error in the solution provided by book')
\ No newline at end of file diff --git a/1332/CH11/EX11.8/11_8.pdf b/1332/CH11/EX11.8/11_8.pdf Binary files differnew file mode 100755 index 000000000..03ccb3fcd --- /dev/null +++ b/1332/CH11/EX11.8/11_8.pdf diff --git a/1332/CH11/EX11.8/11_8.sce b/1332/CH11/EX11.8/11_8.sce new file mode 100755 index 000000000..d366036b9 --- /dev/null +++ b/1332/CH11/EX11.8/11_8.sce @@ -0,0 +1,16 @@ +//Example 11.8
+//Recursive Formula
+//Page no. 357
+clc;close;clear;
+
+A=[2,-1,0,0;-1,2,-1,0;0,-1,2,-1;0,0,-1,2];
+l=poly(0,"l");
+p0=1;
+p1=A(1,1)-l;
+for i=2:4
+ p2=(A(i,i)-l)*p1-A(i,i-1)^2*p0;
+ p0=p1;
+ p1=p2;
+ printf('\n\np%i(l) = ',i);
+ disp(p2)
+end
diff --git a/1332/CH11/EX11.9/11_9.pdf b/1332/CH11/EX11.9/11_9.pdf Binary files differnew file mode 100755 index 000000000..6cd99ab28 --- /dev/null +++ b/1332/CH11/EX11.9/11_9.pdf diff --git a/1332/CH11/EX11.9/11_9.sce b/1332/CH11/EX11.9/11_9.sce new file mode 100755 index 000000000..5c95364bb --- /dev/null +++ b/1332/CH11/EX11.9/11_9.sce @@ -0,0 +1,88 @@ +//Example 11.9
+//QR Method
+//Page no. 360
+clc;close;clear;
+
+A=[2,-1,0;-1,2,-1;0,-1,2];
+deff('y=c(i,j)','y=A(j,j)/sqrt((A(i,j)^2+A(j,j)^2))')
+deff('y=s2(i,j)','y=A(i,j)/sqrt((A(i,j)^2+A(j,j)^2))')
+disp(A,'A=')
+l0=0;f=1;m=0;s=0;w=0;
+for n=1:5
+ for j=1:2
+ for k=1:2
+ V(j,k)=A(j,k)
+ end
+ end
+ disp(V,'V=')
+ p=poly(V,'x');
+ disp('=0',p);
+ a=roots(p);
+ for j=1:2
+ printf('\na(%i) = %f',j,a(j))
+ end
+ if(abs(a(1)-V(1,1))<=abs(a(2)-V(1,1)))
+ a=a(1)
+ else
+ a=a(2)
+ end
+ printf('\na = %f\n',a)
+ s=s+a;
+ A=A-a*eye()
+ R=A;Q=eye(3,3);
+
+ for j=1:2
+ for i=j+1:3
+ for k=1:3 //C matrix evaluation
+ for l=1:3
+ if(k==l)
+ if(k==i | k==j)
+ C(k,l)=c(i,j)
+ else
+ C(k,l)=1
+ end
+ end
+ if(k>l)
+ if(k==i & l==j)
+ C(k,l)=-1*s2(i,j)
+ else
+ C(k,l)=0
+ end
+ end
+ if(k<l)
+ if(k==j & l==i)
+ C(k,l)=s2(i,j)
+ else
+ C(k,l)=0
+ end
+ end
+ end
+ end
+
+ R=C*R;
+ Q=Q*C';
+
+ end
+ end
+disp(Q,'Q=',R,'R=')
+disp(Q*R,'Q*R=')
+A=R*Q;
+disp(A,'A=')
+end
+l1=l0+s;
+for i=2:3
+ for j=2:3
+ V(i-1,j-1)=A(i,j)
+ end
+end
+disp(V,'V=')
+ p=poly(V,'x');
+ disp('=0',p);
+ a=roots(p);
+ for j=1:2
+ printf('\na(%i) = %f',j,a(j))
+ end
+ l2=l1+a(1)
+ l3=l1+a(2)
+ disp(l3,'l3=',l2,'l2=',l1,'l1=')
+printf('\n\n\nNote : Values of V varies in each step resulting in different results due to error in book calculation')
\ No newline at end of file |