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

2 次查看(过去 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?

采纳的回答

Yifeng Tang
Yifeng Tang 2021-5-1
something like
max(abs(u(i+1,:)-u(i,:))) <= 1e-7
do you think this will work?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by