Calculate eigenvectors without the function eig

103 次查看(过去 30 天)
Hi! I am trying to write a function which can calculate the eigenvalues and eigenvectors of a generic square matrix, and I want to compute it by myself, without relying on the function eig. Unfortunately my function calculates only the right eigenvalues, while it sets the eigenvectors always = 0. Can someone give me a hint on how to solve this problem? I also would appreciate if anyone can tell me how to avoid the creation of symbolic solution at the end because it boring to have to shift them in numbers every time.
Thanks in advance.
Alberto
function [eigVal,eigVec]=spec_calculation(A)
s = size(A);
if s(1)~=s(2)
error('Error: Input must be square.')
end
I = eye(length(A));
%
syms x
eq1 = det(A-I*x) == 0 ;
eigVal = double(solve(eq1,x));
%
eigVec = zeros(s);
for i = 1:length(A)
syms y
eq2 = (A-eigVal(i)*I)*y == 0;
eigVec(:,i) = double(solve(eq2,y));
end
end
  4 个评论
Sunil Patil
Sunil Patil 2018-11-2
Hi, Can anyone suggest how we can solve for eigen vectors for identity matrix ? Let A = given matrix (A-lamda I)x = 0 rref(A-lamda1*I) => Identity matrix is coming out of it.
and when we solve identity matrix for eigen vectors, it is coming as all values= 1 (thats not correct). can anyone guide me ?
Thanks Sunil

请先登录,再进行评论。

回答(3 个)

Bruno Luong
Bruno Luong 2018-10-25
You need to find y, such that
|y| = 1 (for example)
A*y = lambda*y
In otherword
y = null(A - lambda*eye(size(A))

Guillermo Serrano Nájera
SOLVE THIS BY HAND! (A-eigVal(i)*I)*y == 0;
trivial solution is y = 0
try A*y == eigVal*y
to avoid trivial solutions, fixing y1 to 1 or something similar
  1 个评论
Bruno Luong
Bruno Luong 2018-10-25
编辑:Bruno Luong 2018-10-25
Can't see why y=0 is not trivial solution of the later form. It's the same equation.

请先登录,再进行评论。


Nadir Bait Saleem
Nadir Bait Saleem 2021-12-12
编辑:Nadir Bait Saleem 2022-6-13
Hello Alberto!
I like you was struggling with a situation like this for hours and even tried to find a chat board which had an answer but I couldn't find any answer that was sufficient. I finally saw the light and figured it out on my own and I felt I had to share it here.
Anyways, this problem is cut into two parts:
  • Finding eigenvalues
  • Finding eigenvectors from the eigenvalues
I'll do this through the lens of the problem I was working on. A Physics problem where we had to solve for the ω "eigenvalues" and the a "eigenvectors".
To find eigenvalues for that arbitrary matrix, we would have to use the equation and the solutions of this will give us values of ω. You can do this in MATLAB by using the solve() function like so:
%NOTE: insert appropriate "syms" call with variables you're using in K and
%M
% w = omega^2
sub = K - w.*M
%To find omega we need to find the solutions to det(sub) = 0
w = solve(det(sub)==0, w)
This will give us an (nx1) matrix w with every row giving us an "eigenvalue" of . Once we have these values we can use them one by one to find the corresponding eigenvector by using solve() of a system of equations along with the handy trick of specifying (Return Condtions, true). An example of this is shown here:
%NOTE: insert appropriate "syms" call with variables you're using in K and
%M
syms a1_2 a2_2 a3_2
a2 = [a1_2 ; a2_2 ; a3_2];
w_2 = w(2,1) ; %single eigenvalue from eigenvalue matrix
sub2 = K - w_2.*M ; %using eigenvalue
solve2 = sub2*a2
%Getting components
eqn1_2 = solve2(1,1) == 0 ;
eqn2_2 = solve2(2,1) == 0 ;
eqn3_2 = solve2(3,1) == 0 ;
sol2 = solve([eqn1_2,eqn2_2,eqn3_2],[a1_2,a2_2,a3_2],"ReturnConditions",true);
%Below are components of sol2 that you can pull out of its structure
a1_2 = sol2.a1_2
a2_2 = sol2.a2_2
a3_2 = sol2.a3_2
By specifying (Return Condtions, true) and cutting up your combined matrix into the appropriate number of linear equations you will find that MATLAB returns eigenvectors in this form where we can set z to be 1.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by