Function contain the term I dont understand
显示 更早的评论
To Define initial condition they define a function but I dont understand the following statement
ui = uR+(uL-uR)*((x-xshift)<= 0) , <=0 how matlab understand this step
I think it will be something similar the step function but I dont understand why we put <=0
function ui = uinit1(x)
xshift=0.5;
uL=1;
uR=0;
ui = uR+(uL-uR)*((x-xshift)<= 0);
end
回答(1 个)
Star Strider
2018-1-27
The ‘<=0’ creates a logical vector, so that if ‘(x-xshift)’ is less than zero, the value for that sub-expression is true or 1, and if it greater than 0, the value is false or 0. When used in a numeric calculation such as in this expression, the true values become numeric 1 and the false values become numeric 0.
ui = uR+(uL-uR)*((x-xshift)<= 0);
(I have no idea what the expression is actually calculating otherwise.)
4 个评论
Eda Yilmaz
2018-1-27
Star Strider
2018-1-27
As always, my pleasure.
If x=xshift, that will evaluate as true, because ‘<=’ means ‘less than or equal to’, and in that situation, (x-xshift) would be equal to 0, matching the ‘equal to’ condition. (The actual MATLAB code for that logical test would use the ‘double equal’ sign, or x == xshift.)
So as long as ‘x’ is less than or equal to ‘xshift’, the condition will return as true.
If ‘x’ is greater than ‘xshift’, the sub-expression is positive, and would evaluate as false.
Eda Yilmaz
2018-1-27
编辑:Walter Roberson
2018-1-27
Star Strider
2018-1-27
As always, my pleasure.
If my Answer helped you solve your problem, please Accept it!
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!