When eigs uses a custom function as input, it cannot compute an eigenvalue near a specified sigma

As the title says, the eigs function is used to compute the eigenvalues of a 10 by 10 symmetric matrix, specify a sigma, and obtain several eigenvalues near the sigma.
The following three methods are used, the first is to solve the first five smallest eigenvalues, the second is to specify a sigma, calculate the five nearby eigenvalues, this method is no problem.
However, the third method, which turns the matrix into a custom function input to the eigs and calculates the eigenvalues near sigma, results in an error, and does not get the correct eigenvalues, the results are some numbers close to sigma.
n = 10;
A = randn(n);
A = A + A';
while rank(A) < n
A = randn(n);
A = A + A';
end
[V1,E1]=eigs(A,5,'sa');
sigma = E1(2,2)+1;
[V2,E2]=eigs(A,5,sigma);
[V3, E3] = eigs(@(x) customFunction(A, x), size(A, 1), 5, sigma);
digits = 3;
E1 = round(E1, digits)
E1 = 5×5
-7.5060 0 0 0 0 0 -6.0430 0 0 0 0 0 -4.7100 0 0 0 0 0 -2.8150 0 0 0 0 0 -1.1640
E2 = round(E2, digits)
E2 = 5×5
-4.7100 0 0 0 0 0 -6.0430 0 0 0 0 0 -2.8150 0 0 0 0 0 -7.5060 0 0 0 0 0 -1.1640
E3 = round(E3, digits)
E3 = 5×5
-4.9230 0 0 0 0 0 -5.1760 0 0 0 0 0 -5.2080 0 0 0 0 0 -4.8370 0 0 0 0 0 -5.2550
function y = customFunction(A, x)
y = A*x;
end

1 comentario

When EIGS uses a custom function and the mode is not "largestabs", this custom function must solve a linear system with the matrix A, shifted by sigma. See the doc.
You can also use the "Display" option which will tell you what EIGS assumes your function handle is computing.

Iniciar sesión para comentar.

Respuestas (1)

n = 10;
A = randn(n);
A = A + A';
E1=eigs(A,5,'sa')';
sigma = E1(2)+1;
E2=eigs(A,5,sigma)';
E3 = eigs(@(x) (A-sigma*speye(n))\x, n, 5, sigma)';
fcn=@(z) sort(round(z,3));
E1 = fcn(E1)
E1 = 1×5
-7.0480 -5.6660 -4.8060 -2.3150 -1.2150
E2 = fcn(E2)
E2 = 1×5
-7.0480 -5.6660 -4.8060 -2.3150 -1.2150
E3 = fcn(E3)
E3 = 1×5
-7.0480 -5.6660 -4.8060 -2.3150 -1.2150

Categorías

Más información sobre Linear Algebra en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 8 de Mzo. de 2024

Comentada:

el 13 de Mzo. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by