[Math] ny matlab code to find out maximum eigenvalue of the randomly generated matrices

MATLAB

I am running a matlab code for computing the Drazin inverse of the matrix $A$.

Initial value of the iteration method
is $X_0 = \beta A^{k}$, where $k = index (A)$(For $A\in \mathbb{C}^{n\times
n}$, the smallest nonnegative integer $k$ such that $rank(A^{k+1}) =
rank(A^k)$ is called the index of $A$
). .

Parameter $\beta$ satisfies: $0<\beta < \frac{2}{\lambda_{max}(A^{k+1})}$.

I want to test the method for the randomly generated matrices so I need a matlab code to determine the maximum eigen value of the matrix $A^k$ so that I may easily choose the value of $\beta$.

Could anybody help me with this. Thanks

Best Answer

Are you looking for the largest eigenvalue or the eigenvalue with the largest magnitude? For magnitude,

a=rand(1000);
max(abs(eig(a)))

is much slower especially if you want to repeat it multiple times because it will compute all of the eigenvalues and then pick the max. You might want to use

a=rand(1000);
eigs(a,1)

which will compute and return only the largest magnitude eigenvalue.