Efficient way to evaluate multiple logic expression as in 'if' condition

1 view (last 30 days)
I am running an iterative algorithm, which will generate a row vector with 10 parameters. After one iteration, the new row vector, or 10 new parameters, will augment to the previous row vector to form a matrix ‘u’. The element in the same column shows the variance/change of the same variable. For all variables, when the absolute deviation of current value versus the value from previous iteration is less than a tolerance, 1e-7, I want algorithm terminates. Then the termination condition can be expressed as,
abs(u(i+1,k)- u(i,k))<= 1e-7, for k = 1,…,10
That could be easily achieved with following code:
if abs(u(i+1,1)- u(i,1))<= 1e-7&& ...
abs(u(i+1,2)- u(i,2))<= 1e-7&& ...
abs(u(i+1,3)- u(i,3))<= 1e-7&& ...
abs(u(i+1,4)- u(i,4))<= 1e-7&& ...
abs(u(i+1,5)- u(i,5))<= 1e-7&& ...
abs(u(i+1,6)- u(i,6))<= 1e-7&& ...
abs(u(i+1,7)- u(i,7))<= 1e-7&& ...
abs(u(i+1,8)- u(i,8))<= 1e-7&& ...
abs(u(i+1,9)- u(i,9))<= 1e-7&& ...
abs(u(i+1,10)- u(i,10))<= 1e-7
break
end
My problem is now the number of parameters increases to 100, all other assumptions remain the same. I do not want to code the termination condition (though just copy/paste) by hand with 100 lines. Is there a easy way I can do this?

Accepted Answer

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!