MATLAB: Display text string if eigenvalue is complex

eigenvaluematrix manipulation

Hi,
I am using the basic eigensolver function to compute the eigenvalues of matrix A and define them in matrix L as follows:
%Define value of A
A=input('Enter Values for Matrix "A" in form [a b;x y]:')
%Calculate eigenvalues of A
L=eig(A);
As any matrix which could produce complex eigenvalues is not a valid input for this scenario, I would like to be able to display a text string and return the user to a point at which matrix A can be redefined if a complex result is computed.
Any advice on how to do this would be greatly appreciated, this is my first foray into the world of Matlab.

Best Answer

  • You could put the INPUT line in a WHILE loop and check with ISREAL whether A is complex or not.
  • Related Question