Calculate eigenvectors without the function eig

조회 수: 14 (최근 30일)
Alberto Grassi
Alberto Grassi 2017년 12월 6일
편집: Nadir Bait Saleem 2022년 6월 13일
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
Bruno Luong
Bruno Luong 2018년 11월 2일
Sunil, please read my answer bellow

댓글을 달려면 로그인하십시오.

답변 (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
Guillermo Serrano Nájera 2018년 5월 9일
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