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!