'Arnoldi algorithm in Matlab

function [V,H] = Arnoldi(A,v,m)
[n,~] = size(A);

V = zeros(n,m+1); 
H = zeros(n,n);
V(:,1) = v/norm(v);

for k = 2:m
    V(:,k) = A*V(:,k-1);
    for j = 1:(k-1);
        H(j,k-1) = V(:,j).'*V(:,k);
        V(:,k) = V(:,k)- H(j,k-1)*V(:,j);
    end
    H(k,k-1) = norm(V(:,k));
    V(:,k) = V(:,k)/H(k,k-1);
end
end

This is my implementation of the Arnoldi algorithm. We already used wikipedia but did not find an answer there. A is a square matrix, v is our starting vector and m is the number of iterations/ dimension of Krylov subspace. It does not give the wanted Hessian H and we can not figure out where we go wrong. Can anybody help us?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source