How to run an algorithm with higher precision?
3 views (last 30 days)
Show older comments
I would like to run my own function with higher precision (more than double precision). My problem is that i don't really understand the syntax. I have for example the following function:
function [ V_k, H_k ] = Arnoldi( A, b, K )
n=length(b);
V=zeros(n,K);
V(:,1)=b*1/norm(b);
H=zeros(K,K);
for k=1:1:K
u=A*V(:,k);
for j=1:1:k
H(j,k)=V(:,j)'*u;
u=u-H(j,k)*V(:,j);
end
H(k+1,k)=norm(u);
V(:,k+1)=u*1/H(k+1,k);
V_k=V(1:n,1:K);
H_k=H(1:K,1:K);
end
end
wehre A is a n times n matrix and b is a n-dimensional vector and K a positive integer. Is it enough to use the command
digits(50)
[V,H] = vpa(Arnoldi(A,B,K))
this command doesn't work, because I have two output arguments. But the question is do I have to edit the whole code like:
function [ V_k, H_k ] = Arnoldi( A, b, K )
digits(50)
n=length(b);
V=zeros(n,K);
V(:,1)=vpa(b*1/norm(b));
H=zeros(K,K);
for k=1:1:K
u=vpa(A*V(:,k));
for j=1:1:k
H(j,k)=vpa(V(:,j)'*u);
u=vpa(u-H(j,k)*V(:,j));
end
H(k+1,k)=vpa(norm(u));
V(:,k+1)=vpa(u*1/H(k+1,k));
V_k=V(1:n,1:K);
H_k=H(1:K,1:K);
end
end
and use than the command
[V,H]=Arnoldi(A,b,K)
Is the solution then more precise? This is just a short example. I would like to use higher precision for a longer code and funtcion.
0 Comments
Answers (0)
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!