Function contain the term I dont understand
Mostrar comentarios más antiguos
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
Respuestas (1)
Star Strider
el 27 de En. de 2018
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 comentarios
Eda Yilmaz
el 27 de En. de 2018
Star Strider
el 27 de En. de 2018
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
el 27 de En. de 2018
Editada: Walter Roberson
el 27 de En. de 2018
Star Strider
el 27 de En. de 2018
As always, my pleasure.
If my Answer helped you solve your problem, please Accept it!
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!