Function contain the term I dont understand
Mostra commenti meno recenti
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
Risposte (1)
Star Strider
il 27 Gen 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 Commenti
Eda Yilmaz
il 27 Gen 2018
Star Strider
il 27 Gen 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
il 27 Gen 2018
Modificato: Walter Roberson
il 27 Gen 2018
Star Strider
il 27 Gen 2018
As always, my pleasure.
If my Answer helped you solve your problem, please Accept it!
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!