Rational Krylov Method(克雷洛夫法)求解特征值问题matlab代码示例(和Arnoldi方法比较)

最基本的特征值问题分为三类:
1、标准的线性特征值问题:
Ax=λx,ACnn
2、普遍的线性特征值问题:
Ax=λBx,ABCnn
3、普遍的艾米特正定线性特征值问题:
Ax=λBx,ABCnn
A=A,B=B>0Cnn

不妨做一个程序将RKM方法和Arnoldi方法做一个比较。

% demo routine for Rational Krylov vs Arnoldi with shift-invert
clc
clear
n = 1000;
m = 40; % subspace size
A = diag([1:1:n]); % testing matrix A of eigenvalues 1, 2, .., n

% shifts: define more shift as you like
sigma1 = 101.5;
sigma2 = 121.5;


% --  Rational Krylov with shifts SIGMA
m1 = floor(m/2); m2 = m-m1;
SIGMA = [repmat(sigma1, m1, 1); repmat(sigma2, m2, 1)];
%SIGMA = repmat([sigma1; sigma2], m/2, 1); % even number m

[Q1, K, L] = rarnoldi(A, SIGMA, m);
[V1, E1] = eig(L(1:m,:), K(1:m,:));

% pick eig of relative residual norm < tol
tol = 1.0E-6;
nA = norm(A,1);
e1 = [];
for i = 1:m
    lam = E1(i,i); 
    v = Q1*(K*V1(:, i));
    res = norm(A*v-lam*v)/norm(v)/nA;
    if res<tol, e1 = [e1, lam]; end
end

% -- shift invert Arnoldi with shift sigma1 
sigma = sigma1;
[LL, UU, PP] = lu(A-sigma*speye(n));
Afun = @(x) UU \ (LL \ (PP*x));
[Q2, H] = arnoldi(Afun, n, m);
[V2, E2] = eig(H(1:m,:)); E2 = 1./E2 + sigma;

% pick eig of relative residual norm < tol
tol = 1.0E-6;
nA = norm(A,1);
e2 = [];
for i = 1:m
    lam = E2(i,i); 
    v = Q2(:,1:m)*V2(:, i);
    res = norm(A*v-lam*v)/norm(v)/nA;
    if res<tol, e2 = [e2, lam]; end
end

% -- display results
figure
plot(real([sigma1, sigma2]), imag([sigma1, sigma2]), 'or', 'DisplayName', 'shifts', 'MarkerSize', 8)
hold on;
plot(real(e2), imag(e2), 'xb', 'DisplayName', 'Arnoldi', 'MarkerSize', 8);
plot(real(e1), imag(e1), '+k', 'DisplayName', 'Rational Krylov', 'MarkerSize', 8);
legend show
xlabel('real'); ylabel('imag')
title('approximate eigenvalues')

% END

这里写图片描述

用到的一些子函数就一起列在下面了:

function [V, H] = arnoldi(Afun, n, m)
% function [V, H] = arnoldi(Afun, n, m) produce an Arnoldi decomposition
%   of order m for a square matri A. 
%       Afun(v) = A*v
%       n = dim of A
%
v = randn(n,1);
v = v / norm(v);

V = v;
H = zeros(m+1, m);

for i = 1:m
    w = Afun(v);
    h = V'*w;
    w = w - V*h;
    gamma = norm(w);

    if gamma==0
        return
    end

    v = w/gamma;
    V = [V, v];
    H(1:i,i) = h;
    H(1+i, i) = gamma;   
end



function [V, K, L] = rarnoldi(A, SIGMA, m)
% function [V, K, L] = rarnoldi(Afun, n, m) produce an rational Krylov
%   decomposition of order m for a square matri A. 
%       SIGMA: length m vector containing shifts
%

n = size(A,1);
v = randn(n,1);
v = v / norm(v);

V = v;
K = zeros(m+1, m);
L = zeros(m+1, m);

for i = 1:m
    sigma = SIGMA(i);
    if sigma ~= inf
        w = (A-sigma*speye(n))\v;
        h = V'*w;
        w = w - V*h;
        gamma = norm(w);
        v = w/gamma;

        V = [V, v];
        K(1:i, i) = h;
        K(i+1, i) = gamma;
        L(1:i+1, i) = sigma*K(1:i+1, i);
        L(i, i) = L(i, i) + 1;
    else
        w = A*v;
        h = V'*w;
        w = w - V*h;
        gamma = norm(w);
        v = w/gamma;

        V = [V, v];
        K(i, i) = 1;
        L(1:i, i) = h;
        L(i+1, i) = gamma;
    end
    % breakdown case L(i+1, i) = K(i+1,i) = 0 is not treated.
end
  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陆嵩

有打赏才有动力,你懂的。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值