フィルターのクリア

power method with rayleigh coeff

2 ビュー (過去 30 日間)
Sonali
Sonali 2024 年 4 月 12 日
コメント済み: Sonali 2024 年 4 月 14 日
Hello, I'm working on Rayleigh iteration and my program is as follows. I am getting wrong values. I was wondering if someone could suggest something.
function [eigval, eigvec,itern] = rayl(A, x0, tol, nmax)
x = x0;
iter = 0;
e0 = 0;
while iter < nmax
y = A * x;
en = (x' * y) / (x' * x);
if abs(en - e0) <= tol
break;
end
x = y / norm(y);
e0 = en;
iter = iter + 1;
end
eigval = en;
eigvec = x;
itern =iter;
end
.........................................................................
Calling in function:
A=[4 1 -1 0;1 3 -1 0;-1 -1 5 2;0 0 2 4]
tol=1.d-8; nmax=100; x0=[1 1 1 1]';
[eig_val_ray, xr,iter] = rayl(A, x0, nmax, tol)
................................................................
output:
eig_val_ray = 4.5000
xr = 4×1
1
1
1
1
iter = 0

採用された回答

Alan Stevens
Alan Stevens 2024 年 4 月 13 日
Make sure you call the function with the arguments in the same order as those defined in the function!
A=[4 1 -1 0;1 3 -1 0;-1 -1 5 2;0 0 2 4];
tol=1.d-8; nmax=100; x0=[1 1 1 1]';
[eig_val_ray, xr,iter] = rayl(A, x0, tol, nmax); %%%%%%%%%%%%%%%%%%%
eig_val_ray
eig_val_ray = 7.0861
xr
xr = 4x1
-0.3325 -0.2671 0.7590 0.4919
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
iter
iter = 24
function [eigval, eigvec,itern] = rayl(A, x0, tol, nmax)%%%%%%%%%%%%%%
x = x0;
iter = 0;
e0 = 0;
while iter < nmax
y = A * x;
en = (x' * y) / (x' * x);
if abs(en - e0) <= tol
break;
end
x = y / norm(y);
e0 = en;
iter = iter + 1;
end
eigval = en;
eigvec = x;
itern =iter;
end
  1 件のコメント
Sonali
Sonali 2024 年 4 月 14 日
Thank you. It worked.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePHY Components についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by