"If number belongs in the interval defined by a matrix" into code?
1 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to veto if two given numbers belong in two admissible ranges. Instead of writing line 11 that way, could I instead say something like if x_ini' does not belong to x_bound? Meaning that if the value of the first row of the transposed vector x_ini (i.e. x1_0) does not belong in the interval defined by the first row of matrix x_bound (i. e. x1_min x1_max) and/or, likewise, if the value of the second row of the transposed vector x_ini (i.e. x2_0) is not in the interval defined by the second row of matrix x_bound ((i. e. x2_min x2_max)), then that message is displayed?
Hopefully I have been clear? Thank you in advance for the help!
x1_min = 0.1;
x1_max = 2.0;
x2_min = 0.1;
x2_max = 2.5;
x_bound = [x1_min x1_max ; x2_min x2_max];
x1_0 = 1;
x2_0 = 1;
x_ini = [x1_0 x2_0];
if x1_0 < x1_min || x2_0 < x2_min || x1_0 > x1_max || x2_0 > x2_max
disp("Initial value of x does not belong in admissible interval.");
quit
end
2 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!