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)
E2 = round(E2, digits)
E3 = round(E3, digits)
function y = customFunction(A, x)
y = A*x;
end
1 个评论
Christine Tobler
2024-3-13
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.
回答(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)
E2 = fcn(E2)
E3 = fcn(E3)
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!