Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Team:

1. Marisnelvys Cabreja Consuegra


2. Dannys García Miranda
Answers
Practice 19
%1)
A=zeros(100);
n=size(A,1);
for i=1:n
A(i,i:n)=10;
A(i,i)=n-i+1;
end
A=A;

%2)
[EigVectRig,Eigval,VectCond] = condeig(A);% vector of condition numbers for the
eigenvalues of A, Large condition numbers imply that A is near a matrix with
multiple eigenvalues.
d=diag(VectCond);
kA= max(max(d))
[i j] = find (d == kA ); positionkA=[i, j]
Eigvalij= Eigval(i,j)

%3)
[RightVect,Eigvals,LeftVect] = eig(A);
% Now, we choose any eigenvalue that can be the element L11 of the eigenvalues of
the matrix A, we also choose the associated eigenvectors, left and right for said
eigenvalue and calculate their respective condition number, then we obtain
Z=zeros(n);
for p=1:n
Vleft= LeftVect (p,1:n);% left eigenvector, The matrix formed by the left
eigenvectors, contains in each row the corresponding eigenvector
Vright= RightVect(1:n,p);% right eigenvector, The matrix formed by the right
eigenvectors, contains in each column the corresponding eigenvector
y= Vleft / norm(Vleft,2);% left eigenvector normalized, norm(y,2)% must be 1
x= Vright / norm(Vright,2); % right eigenvector normalized, norm(x,2)% must be 1
k=abs((y* x)^(-1));% condition number for eigenvalue Lpp
Z(p,p)=k;% In this matrix I keep the kp
end
Z=Z;
k=max(max(Z))
[i j] = find (Z == k ); positionk=[i, j]
Eigvalij= Eigvals(i,j)

% in the item 2 there is the condition number corresponding to the eigenvalue in


position i,j , before normalizing the corresponding eigenvectors, obtaining that
kA=2.2368e+15 and in this item 3 the maximun condition number k = 3.5104, because
the vectors are normalized.

%4)
V= RightVect;
K2V=norm((V^(-1)),2)* norm(V,2);
% In this item K2V=1.6075e+16, which is much bigger than k and in one order of
10^1 than kA.
K2V= K2V

%5)
Ae=zeros(n);
Ae=A(1:n-1,1:n);
i=6; % do it to 6, 10, 16
e=10^(-i);
Ae(n,1)=A(n,1)+e;
EigenvalAe=eig(Ae);
D= Eigvals-diag(EigenvalAe);
E=max(max(abs(D)));% deviations from the eigenvalues of A, must be less than or
equal to F ( Theorem 84)
F= K2V*norm(e,2);
maxdeviations=E
[i j] = find (D == E ); positionmaxdeviat=[i, j]
Eigvalij= Eigvals(i,j)
difference = abs(maxdeviations-k)
F=F
i=6 i=10 i=16 .
kA = 2.2368e+15 2.2368e+15 2.2368e+15

positionkA = 7 7 7 7 7 7

Eigvalij = 94 94 94

***k = 4.6035e+12 4.6035e+12 4.6035e+12

positionk = 30 30 30 30 30 30

Eigvalij = 71 71 71

***K2V = 1.6075e+16 1.6075e+16 1.6075e+16

maxdeviations = 93.0000 93.0000 100.0000

positionmaxdeviat = 8 8 8 8 1 1

Eigvalij = 93 93 100

difference = 4.6035e+12 4.6035e+12 4.6035e+12

F = 1.6075e+10 1.6075e+06 1.6075


Conclusion:***k is iqual to ***K2V

Practice 20
%1)
S = rand(105, 105);
x=[10^(-5), 10^(-4), 10^(-3), 10^(-2), 10^(-1), 1 : 1 : 100];
D= diag(x,0);
A = S * D * S^(-1);
n=size(A,1);
% As S is nonsingular, A is diagonalizable, that is, similar to D, any diagonal
matrix, therefore the diagonal elements of A, which are those of D also, are
necessarily the eigenvalues of A and column i of the matrix S is the eigenvector
corresponding to the eigenvalue ti, since AS = SD.

%2)
[EigenvectA,EigenvalA]=eig(A);
[EigenvectD,EigenvalD]=eig(D);

%3)
J=sort(diag(EigenvalA));
K=sort(diag(EigenvalD));
Err=zeros(n,1);
for i=1:n
Err=norm((J(i,1)-K(i,1)),2)/norm(J(i,1),2);
Err(i,1)=Err;
end
ErrMinVal=min(Err)
ErrMaxVal=max(Err)
%The error is very small because A is similar to D, and diagonalizable, so is the
same diagonal

%4)
U=zeros(n,1);
for i=1:n
T=(A*S(1:n,i)-D(i,i)*S(1:n,i))./norm(S(1:n,i),2);
U(i,1)=norm(T,2);
end
ErrMinVect=min(U)
ErrMaxVect=max(U)
%The error is very small because A is similar to D, and diagonalizable, so the
eigenvectors are the column of S

%5)
[i j] = find (U == ErrMaxVect); positionvect=[i, j]
ResidualNorm=norm((A*S(1:n,i)- D(i,i)*S(1:n,i)),2)
%The residual and the error are very small but not the same, because they were not
calculated in the same way
%6)

%1)
S = rand(105, 105);
[Q,R]=qr(S);
S=Q;
x=[10^(-5), 10^(-4), 10^(-3), 10^(-2), 10^(-1), 1 : 1 : 100];
D= diag(x,0);
A = S * D * S^(-1);
n=size(A,1);
% As S is nonsingular, A is diagonalizable, that is, similar to D, any diagonal
matrix, therefore the diagonal elements of A, which are those of D also, are
necessarily the eigenvalues of A and column i of the matrix S is the eigenvector
corresponding to the eigenvalue ti, since AS = SD.

%2)
[EigenvectA,EigenvalA]=eig(A);
[EigenvectD,EigenvalD]=eig(D);

%3)
J=sort(diag(EigenvalA));
K=sort(diag(EigenvalD));
Err=zeros(n,1);
for i=1:n
Err=norm((J(i,1)-K(i,1)),2)/norm(J(i,1),2);
Err(i,1)=Err;
end
ErrMinVal=min(Err)
ErrMaxVal=max(Err)
%The error is very small because A is similar to D, and diagonalizable, so is the
same diagonal

%4)
U=zeros(n,1);
for i=1:n
T=(A*S(1:n,i)-D(i,i)*S(1:n,i))./norm(S(1:n,i),2);
U(i,1)=norm(T,2);
end
ErrMinVect=min(U)
ErrMaxVect=max(U)
%The error is very small because A is similar to D, and diagonalizable, so the
eigenvectors are the column of S

%5)
[i j] = find (U == ErrMaxVect); positionvect=[i, j]
ResidualNorm=norm((A*S(1:n,i)- D(i,i)*S(1:n,i)),2)
%The residual and the error are very small and the same, because the matrix is
orthogonal and that multiplied by its transpose (or transpose) is equal to the
Identity matrix.

You might also like