From b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b Mon Sep 17 00:00:00 2001 From: priyanka Date: Wed, 24 Jun 2015 15:03:17 +0530 Subject: initial commit / add all books --- 1670/CH4/EX4.1/4_1.sce | 19 +++++++++++++++++++ 1670/CH4/EX4.10/4_10.sce | 30 +++++++++++++++++++++++++++++ 1670/CH4/EX4.11/4_11.sce | 30 +++++++++++++++++++++++++++++ 1670/CH4/EX4.12/4_12.sce | 36 +++++++++++++++++++++++++++++++++++ 1670/CH4/EX4.13/4_13.sce | 23 +++++++++++++++++++++++ 1670/CH4/EX4.14/4_14.sce | 23 +++++++++++++++++++++++ 1670/CH4/EX4.15/4_15.sce | 25 ++++++++++++++++++++++++ 1670/CH4/EX4.16/4_16.sce | 25 ++++++++++++++++++++++++ 1670/CH4/EX4.17/4_17.sce | 18 ++++++++++++++++++ 1670/CH4/EX4.2/4_2.sce | 20 ++++++++++++++++++++ 1670/CH4/EX4.3/4_3.sce | 20 ++++++++++++++++++++ 1670/CH4/EX4.4/4_4.sce | 20 ++++++++++++++++++++ 1670/CH4/EX4.5/4_5.sce | 37 ++++++++++++++++++++++++++++++++++++ 1670/CH4/EX4.6/4_6.sce | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1670/CH4/EX4.7/4_7.sce | 32 +++++++++++++++++++++++++++++++ 1670/CH4/EX4.8/4_8.sce | 30 +++++++++++++++++++++++++++++ 1670/CH4/EX4.9/4_9.sce | 30 +++++++++++++++++++++++++++++ 17 files changed, 467 insertions(+) create mode 100755 1670/CH4/EX4.1/4_1.sce create mode 100755 1670/CH4/EX4.10/4_10.sce create mode 100755 1670/CH4/EX4.11/4_11.sce create mode 100755 1670/CH4/EX4.12/4_12.sce create mode 100755 1670/CH4/EX4.13/4_13.sce create mode 100755 1670/CH4/EX4.14/4_14.sce create mode 100755 1670/CH4/EX4.15/4_15.sce create mode 100755 1670/CH4/EX4.16/4_16.sce create mode 100755 1670/CH4/EX4.17/4_17.sce create mode 100755 1670/CH4/EX4.2/4_2.sce create mode 100755 1670/CH4/EX4.3/4_3.sce create mode 100755 1670/CH4/EX4.4/4_4.sce create mode 100755 1670/CH4/EX4.5/4_5.sce create mode 100755 1670/CH4/EX4.6/4_6.sce create mode 100755 1670/CH4/EX4.7/4_7.sce create mode 100755 1670/CH4/EX4.8/4_8.sce create mode 100755 1670/CH4/EX4.9/4_9.sce (limited to '1670/CH4') diff --git a/1670/CH4/EX4.1/4_1.sce b/1670/CH4/EX4.1/4_1.sce new file mode 100755 index 000000000..4043d5311 --- /dev/null +++ b/1670/CH4/EX4.1/4_1.sce @@ -0,0 +1,19 @@ +//Example 4.1 +//Power Method +//Page no. 89 +clc;close;clear; + +A=[1,3,-1;3,2,4;-1,4,10]; +e=0.001; +q0=[0;0;1]; +for i=1:5 + q1=A*q0; + a=max(q1) + for j=1:3 + q2(j)=q1(j)/a; + end + printf('\nq(%i) = %.4f a = %.4f Scaled q(%i) = %.3f\n %.3f %.3f\n %.3f %i\n\n',i,q1(1),a,i,q2(1),q1(2),q2(2),q1(3),q2(3)) + q1=q2; + q0=q1; +end +printf('Hence the largest eigenvalue is %.2f with the corresponding eigenvector as %.3f\n %.3f\n %i',a,q0(1),q0(2),q0(3)) \ No newline at end of file diff --git a/1670/CH4/EX4.10/4_10.sce b/1670/CH4/EX4.10/4_10.sce new file mode 100755 index 000000000..ab713b8ab --- /dev/null +++ b/1670/CH4/EX4.10/4_10.sce @@ -0,0 +1,30 @@ +//Example 4.10 +//Givens Method +//Page no. 105 +clc;close;clear; + +A=[8,-6,2;-6,7,-4;2,-4,3]; +n=3; +for k=1:1 + max1=0 +i1=2;j1=3; +fi=(atan((2*A(i1,j1))/(A(i1,i1)-A(j1,j1)+10^-20)))/2 +disp(fi,'fi = ') +O1=eye(n,n) +O1(i1,j1)=-sin(fi) +O1(j1,i1)=sin(fi) +O1(i1,i1)=cos(fi) +O1(j1,j1)=cos(fi) +disp(O1,'O1 = ') +A=inv(O1)*A*O1 +disp(A,'B = ') +end +printf('\n\n') +l=poly(0,'lb') +A=A-l*eye(n,n) +disp(det(A),'Characteristic Equation = ') +A=roots(det(A)) +printf('\n\n The eigenvalues are : \n\n') +for i=1:n + printf('\tl%i = %g\t',i,A(i)) +end \ No newline at end of file diff --git a/1670/CH4/EX4.11/4_11.sce b/1670/CH4/EX4.11/4_11.sce new file mode 100755 index 000000000..63c49dd08 --- /dev/null +++ b/1670/CH4/EX4.11/4_11.sce @@ -0,0 +1,30 @@ +//Example 4.11 +//Givens Method +//Page no. 106 +clc;close;clear; + +A=[1,2,2;2,1,2;2,2,1]; +n=3; +for k=1:1 + max1=0 +i1=2;j1=3; +fi=(atan((2*A(i1,j1))/(A(i1,i1)-A(j1,j1)+10^-20)))/2 +disp(fi,'fi = ') +O1=eye(n,n) +O1(i1,j1)=-sin(fi) +O1(j1,i1)=sin(fi) +O1(i1,i1)=cos(fi) +O1(j1,j1)=cos(fi) +disp(O1,'O1 = ') +A=inv(O1)*A*O1 +disp(A,'B = ') +end +printf('\n\n') +l=poly(0,'lb') +A=A-l*eye(n,n) +disp(-det(A),'Characteristic Equation = ') +A=roots(det(A)) +printf('\n\n The eigenvalues are : \n\n') +for i=1:n + printf('\tl%i = %g\t',i,A(i)) +end \ No newline at end of file diff --git a/1670/CH4/EX4.12/4_12.sce b/1670/CH4/EX4.12/4_12.sce new file mode 100755 index 000000000..56ceeb5e8 --- /dev/null +++ b/1670/CH4/EX4.12/4_12.sce @@ -0,0 +1,36 @@ +//Example 4.12 +//Givens Method +//Page no. 107 +clc;close;clear; + +A=[1,2,2,2;2,1,2,2;2,2,1,3;2,2,3,1]; +n=4; +for k=1:3 + max1=0 + if k==1 then + i1=2;j1=3; + elseif k==2 + i1=2;j1=4; + else + i1=3;j1=4; + end +fi=(atan((2*A(i1,j1))/(A(i1,i1)-A(j1,j1)+10^-20)))/2 +disp(fi,'fi = ') +O1=eye(n,n) +O1(i1,j1)=-sin(fi) +O1(j1,i1)=sin(fi) +O1(i1,i1)=cos(fi) +O1(j1,j1)=cos(fi) +disp(O1,'O1 = ') +A=inv(O1)*A*O1 +disp(A,'B = ') +end +printf('\n\n') +l=poly(0,'lb') +A=A-l*eye(n,n) +disp(-det(A),'Characteristic Equation = ') +A=roots(det(A)) +printf('\n\n The eigenvalues are : \n\n') +for i=1:n + printf('\tl%i = %g\t',i,A(i)) +end \ No newline at end of file diff --git a/1670/CH4/EX4.13/4_13.sce b/1670/CH4/EX4.13/4_13.sce new file mode 100755 index 000000000..4d4cb3c6b --- /dev/null +++ b/1670/CH4/EX4.13/4_13.sce @@ -0,0 +1,23 @@ +//Example 4.13 +//House Holder Transformation +//Page no. 113 +clc;clear;close; + +A=[3,2,1;2,3,2;1,2,3] +disp(A,'A=') +k=0; +for j=2:3 + k=k+A(j,1)^2; +end +a=A(2,1)*abs(1/A(2,1))*sqrt(k); +disp(a,'alpha=') +U=[0;a+A(2,1);A(3,1)]; +disp(U,'U=') +U1=U'*U; +disp(U1,'UT*U=') +U2=U*U'; +disp(U2,'U*UT=') +P=eye(3,3)-(2*U2)/U1; +disp(P,'P='); +B=P*A*P; +disp(B,'B='); \ No newline at end of file diff --git a/1670/CH4/EX4.14/4_14.sce b/1670/CH4/EX4.14/4_14.sce new file mode 100755 index 000000000..a8f26a1fe --- /dev/null +++ b/1670/CH4/EX4.14/4_14.sce @@ -0,0 +1,23 @@ +//Example 4.14 +//House Holder Transformation +//Page no. 114 +clc;clear;close; + +A=[1,3,4;3,1,2;4,2,1] +disp(A,'A=') +k=0; +for j=2:3 + k=k+A(j,1)^2; +end +a=A(2,1)*abs(1/A(2,1))*sqrt(k); +disp(a,'alpha=') +U=[0;a+A(2,1);A(3,1)]; +disp(U,'U=') +U1=U'*U; +disp(U1,'UT*U=') +U2=U*U'; +disp(U2,'U*UT=') +P=eye(3,3)-(2*U2)/U1; +disp(P,'P='); +B=P*A*P; +disp(B,'B='); \ No newline at end of file diff --git a/1670/CH4/EX4.15/4_15.sce b/1670/CH4/EX4.15/4_15.sce new file mode 100755 index 000000000..3c4b2d935 --- /dev/null +++ b/1670/CH4/EX4.15/4_15.sce @@ -0,0 +1,25 @@ +//Example 4.15 +//Strum Sequence +//Page no. 116 +clc;clear;close; + +A=[1,2,2;2,1,2;2,2,1] +disp(A,'A=') +k=0; +for j=2:3 + k=k+A(j,1)^2; +end +a=A(2,1)*abs(1/A(2,1))*sqrt(k); +U=[0;a+A(2,1);A(3,1)]; +U1=U'*U; +U2=U*U'; +P=eye(3,3)-(2*U2)/U1; +B=P*A*P; +disp(B,'Reduced Matrix = '); +lb=poly(0,"lb") +f0l=1; //strum sequence +f1l=(B(1,1)-lb)*f0l; +f2l=(B(2,2)-lb)*f1l-B(1,2)^2*f0l +f3l=(B(3,3)-lb)*f2l-B(2,3)^2*f1l +disp(f3l,"f3(lambda) = ") +disp(roots(f3l),"Therefore the eigenvalues are : ") \ No newline at end of file diff --git a/1670/CH4/EX4.16/4_16.sce b/1670/CH4/EX4.16/4_16.sce new file mode 100755 index 000000000..a507e0337 --- /dev/null +++ b/1670/CH4/EX4.16/4_16.sce @@ -0,0 +1,25 @@ +//Example 4.16 +//Strum Sequence +//Page no. 117 +clc;clear;close; + +A=[8,-6,2;-6,7,-4;2,-4,3] +disp(A,'A=') +k=0; +for j=2:3 + k=k+A(j,1)^2; +end +a=A(2,1)*abs(1/A(2,1))*sqrt(k); +U=[0;a+A(2,1);A(3,1)]; +U1=U'*U; +U2=U*U'; +P=eye(3,3)-(2*U2)/U1; +B=P*A*P; +disp(B,'Reduced Matrix = '); +lb=poly(0,"lb") +f0l=1; //strum sequence +f1l=(B(1,1)-lb)*f0l; +f2l=(B(2,2)-lb)*f1l-B(1,2)^2*f0l +f3l=(B(3,3)-lb)*f2l-B(2,3)^2*f1l +disp(f3l,"f3(lambda) = ") +disp(roots(f3l),"Therefore the eigenvalues are : ") \ No newline at end of file diff --git a/1670/CH4/EX4.17/4_17.sce b/1670/CH4/EX4.17/4_17.sce new file mode 100755 index 000000000..659bda4d1 --- /dev/null +++ b/1670/CH4/EX4.17/4_17.sce @@ -0,0 +1,18 @@ +//Example 4.17 +//Gerschgorin Circles +//Page no. 118 +clc;clear;close; + +A=[1,2,3;2,4,6;3,6,1]; +j=2; +k=3; +printf('The Gerschgorin Circles are : \n\n A =' ) +for i=1:3 + printf('\t|z-%i| = |%i| + |%i| = %i\n',A(i,i),A(i,j),A(i,k),A(i,j)+A(i,k)) + if j~=1 then + j=j-1 + end + if i==2 then + k=k-1 + end +end \ No newline at end of file diff --git a/1670/CH4/EX4.2/4_2.sce b/1670/CH4/EX4.2/4_2.sce new file mode 100755 index 000000000..24c7196c1 --- /dev/null +++ b/1670/CH4/EX4.2/4_2.sce @@ -0,0 +1,20 @@ +//Example 4.2 +//Power Method +//Page no. 90 +clc;close;clear; + +A=[1,-3,2;4,4,-1;6,3,5]; +e=0.001; +q0=[1;1;1]; +for i=1:9 + q1=A*q0; + a=max(q1) + for j=1:3 + q2(j)=q1(j)/a; + end + printf('\nq(%i) = %.4f a = %.4f Scaled q(%i) = %.3f\n %.3f %.3f\n %.3f %i\n\n',i,q1(1),a,i,q2(1),q1(2),q2(2),q1(3),q2(3)) + q1=q2; + q0=q1; +end +q0=q0*30 +printf('Hence the largest eigenvalue is %.1g with the corresponding eigenvector as %.1g\n %.1g\n %i',a,q0(1),q0(2),q0(3)) \ No newline at end of file diff --git a/1670/CH4/EX4.3/4_3.sce b/1670/CH4/EX4.3/4_3.sce new file mode 100755 index 000000000..659796729 --- /dev/null +++ b/1670/CH4/EX4.3/4_3.sce @@ -0,0 +1,20 @@ +//Example 4.3 +//Power Method +//Page no. 91 +clc;close;clear; + +A=[2,-1,0;-1,2,-1;0,-1,2]; +e=0.001; +q0=[1;1;1]; +for i=1:6 + q1=A*q0; + a=max(q1) + for j=1:3 + q2(j)=q1(j)/a; + end + printf('\nq(%i) = %.4f a = %.4f Scaled q(%i) = %.3f\n %.3f %.3f\n %.3f %i\n\n',i,q1(1),a,i,q2(1),q1(2),q2(2),q1(3),q2(3)) + q1=q2; + q0=q1; +end +q0=-q0/q0(2) +printf('Hence the largest eigenvalue is %.3f with the corresponding eigenvector as %.1f\n %.1g\n %.1f',a,q0(1),q0(2),q0(3)) \ No newline at end of file diff --git a/1670/CH4/EX4.4/4_4.sce b/1670/CH4/EX4.4/4_4.sce new file mode 100755 index 000000000..0452e0c06 --- /dev/null +++ b/1670/CH4/EX4.4/4_4.sce @@ -0,0 +1,20 @@ +//Example 4.4 +//Power Method +//Page no. 93 +clc;close;clear; + +A=[3,-1,0;-1,2,-1;0,-1,3]; +e=0.001; +q0=[1;1;1]; +for i=1:5 + q1=A*q0; + a=max(q1) + for j=1:3 + q2(j)=q1(j)/a; + end + printf('\nq(%i) = %.4f a = %.4f Scaled q(%i) = %.3f\n %.3f %.3f\n %.3f %i\n\n',i,q1(1),a,i,q2(1),q1(2),q2(2),q1(3),q2(3)) + q1=q2; + q0=q1; +end +q0=-q0/q0(2) +printf('Hence the largest eigenvalue is %.1g with the corresponding eigenvector as %.1g\n %.1g\n %.1g',a,q0(1),q0(2),q0(3)) \ No newline at end of file diff --git a/1670/CH4/EX4.5/4_5.sce b/1670/CH4/EX4.5/4_5.sce new file mode 100755 index 000000000..34a049b36 --- /dev/null +++ b/1670/CH4/EX4.5/4_5.sce @@ -0,0 +1,37 @@ +//Example 4.5 +//Jacobi Method +//Page no. 95 +clc;close;clear; + +A=[10,7,8,7;7,5,6,5;8,6,10,9;7,5,9,10]; +n=4; +for k=1:14 + max1=0 +for i=1:n + for j=1:n + if A(i,j)>max1 & i~=j then + max1=A(i,j) + i1=i;j1=j; + end + end +end +fi=(atan((2*A(i1,j1))/(A(i1,i1)-A(j1,j1)+10^-20)))/2 +disp(fi,'fi = ') +O1=eye(n,n) +O1(i1,j1)=-sin(fi) +O1(j1,i1)=sin(fi) +O1(i1,i1)=cos(fi) +O1(j1,j1)=cos(fi) +disp(O1,'O1 = ') +A=inv(O1)*A*O1 +disp(A,'A1 = ') +end +printf('\n\n The eigenvalues are : \n\n') +for i=1:n + printf('\tl%i = %g\t',i,A(i,i)) +end +printf('\n\n') +l=poly(0,'lb') +A=A-l*eye(n,n) +disp(det(A),'Characteristic Equation = ') +printf("\n\n\n\n\nNote : Computation Errors in some parts in calculation performed in book") \ No newline at end of file diff --git a/1670/CH4/EX4.6/4_6.sce b/1670/CH4/EX4.6/4_6.sce new file mode 100755 index 000000000..bbe85501d --- /dev/null +++ b/1670/CH4/EX4.6/4_6.sce @@ -0,0 +1,49 @@ +//Example 4.6 +//Jacobi Method +//Page no. 97 +clc;close;clear; + +A=[1,sqrt(2),2;sqrt(2),3,sqrt(2);2,sqrt(2),1]; +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/1670/CH4/EX4.7/4_7.sce b/1670/CH4/EX4.7/4_7.sce new file mode 100755 index 000000000..5211d5285 --- /dev/null +++ b/1670/CH4/EX4.7/4_7.sce @@ -0,0 +1,32 @@ +//Example 4.7 +//Jacobi Method +//Page no. 99 +clc;close;clear; + +A=[2,3,1;3,2,2;1,2,1]; +n=3; +for k=1:10 + max1=0 +for i=1:n + for j=1:n + if A(i,j)>max1 & i~=j then + max1=A(i,j) + i1=i;j1=j; + end + end +end +fi=(atan((2*A(i1,j1))/(A(i1,i1)-A(j1,j1)+10^-20)))/2 +disp(fi,'fi = ') +O1=eye(n,n) +O1(i1,j1)=-sin(fi) +O1(j1,i1)=sin(fi) +O1(i1,i1)=cos(fi) +O1(j1,j1)=cos(fi) +disp(O1,'O1 = ') +A=inv(O1)*A*O1 +disp(A,'A1 = ') +end +printf('\n\n The eigenvalues are : \n\n') +for i=1:n + printf('\tl%i = %g\t',i,A(i,i)) +end \ No newline at end of file diff --git a/1670/CH4/EX4.8/4_8.sce b/1670/CH4/EX4.8/4_8.sce new file mode 100755 index 000000000..6f214fa7c --- /dev/null +++ b/1670/CH4/EX4.8/4_8.sce @@ -0,0 +1,30 @@ +//Example 4.8 +//Givens Method +//Page no. 103 +clc;close;clear; + +A=[2,3,1;3,2,2;1,2,1]; +n=3; +for k=1:1 + max1=0 +i1=2;j1=3; +fi=(atan((2*A(i1,j1))/(A(i1,i1)-A(j1,j1)+10^-20)))/2 +disp(fi,'fi = ') +O1=eye(n,n) +O1(i1,j1)=-sin(fi) +O1(j1,i1)=sin(fi) +O1(i1,i1)=cos(fi) +O1(j1,j1)=cos(fi) +disp(O1,'O1 = ') +A=inv(O1)*A*O1 +disp(A,'B = ') +end +printf('\n\n') +l=poly(0,'lb') +A=A-l*eye(n,n) +disp(-det(A),'Characteristic Equation = ') +A=roots(det(A)) +printf('\n\n The approximate roots of characteristic equation are: \n\n') +for i=1:n + printf('\tl%i = %g\t',i,A(i)) +end \ No newline at end of file diff --git a/1670/CH4/EX4.9/4_9.sce b/1670/CH4/EX4.9/4_9.sce new file mode 100755 index 000000000..0a315d3cf --- /dev/null +++ b/1670/CH4/EX4.9/4_9.sce @@ -0,0 +1,30 @@ +//Example 4.9 +//Givens Method +//Page no. 104 +clc;close;clear; + +A=[3,2,1;2,3,2;1,2,3]; +n=3; +for k=1:1 + max1=0 +i1=2;j1=3; +fi=(atan((2*A(i1,j1))/(A(i1,i1)-A(j1,j1)+10^-20)))/2 +disp(fi,'fi = ') +O1=eye(n,n) +O1(i1,j1)=-sin(fi) +O1(j1,i1)=sin(fi) +O1(i1,i1)=cos(fi) +O1(j1,j1)=cos(fi) +disp(O1,'O1 = ') +A=inv(O1)*A*O1 +disp(A,'B = ') +end +printf('\n\n') +l=poly(0,'lb') +A=A-l*eye(n,n) +disp(-det(A),'Characteristic Equation = ') +A=roots(det(A)) +printf('\n\n The eigenvalues are : \n\n') +for i=1:n + printf('\tl%i = %g\t',i,A(i)) +end \ No newline at end of file -- cgit