Asked by Nitish Reddy Kotkur
on 28 Sep 2019

for j=2:inf

w = A*V(:,j) - beta(j)*V(:,j-1);

alpha(j) = w'*V(:,j);

w = w - alpha(j)*V(:,j);

beta(j+1) = norm(w,2);

V(:,j+1) = w/beta(j+1);

loopcnt = loopcnt + 1;

end

Answer by the cyclist
on 28 Sep 2019

Accepted Answer

Put this inside your loop:

if beta(j+1) == 0

break

end

You might not want to check for exact equality, because of possible floating point error. Instead, you could check like this

if abs(beta(j+1)) < 1.e-8

break

end

or use some other suitably small tolerance.

Nitish Reddy Kotkur
on 28 Sep 2019

if beta(j+1) == 0

break

end

i tried this but still the loop is iterating infinite times

if abs(beta(j+1)) < 1.e-8

break

end

and the problem with the above one is, i guess its terminating even before the value is zero there by resulting a wrong computation

the cyclist
on 28 Sep 2019

As I said, you need to try a "suitably small tolerance". You could try a smaller power.

Nitish Reddy Kotkur
on 21 Oct 2019 at 23:42

function [] = lanczos(A, m)

this is a function whick takes A as input which is a matrix and reduces it to smaller size .And i have got a for loop

for j=2:inf

w = A*V(:,j) - beta(j)*V(:,j-1);

alpha(j) = w'*V(:,j);

w = w - alpha(j)*V(:,j);

beta(j+1) = norm(w,2);

loopcnt = loopcnt + 1;

if abs(beta(j+1)) = 0

break

end

now i need the control to come out of loop when beta(j+1) is equal to zero ,but its looping continuously may be because of some floating point error.so i tried something like this

if abs(beta(j+1)) < 0.0001 should come out of loop which worked fine for smaller matrix sizes.

but when matrix size got bigger even its not working and loop is running continuosly can some one suggest me a way to avoid this problem and run the loop properly and break it when beta(j+1) become zero

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.