Efficient way to evaluate multiple logic expression as in 'if' condition
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!