Explanation for the below equation containing the comparsion symbols
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Laxmi Akshaya Thela
le 5 Sep 2021
Modifié(e) : Walter Roberson
le 6 Sep 2021
I couldnt get these equations with comparison.
gbLoss = (fdTrq>0 & gbEff>eps) .* (1-gbEff) .* fdTrq ./ (gbEff .* gbSpRatio) ...
+ (fdTrq>0 & gbEff==eps) .* fdTrq .* gbSpRatio ...
+ (fdTrq<=0) .* (1-gbEff) .* fdTrq ./ gbSpRatio;
vehForce = (wheelSpd~=0) .* (rolling_friction + veh.aero_coeff.*w{1}.^2 + veh.mass.*w{2});
% Wheel torque (Nm)
wheelTrq = (vehForce .* veh.wh_radius + veh.axle_loss .* (wheelSpd~=0));
% Torque provided by engine
engTrq = (shaftSpd>0) .* (reqTrq>0) .* (1-u{2}).*reqTrq;
brakeTrq = (shaftSpd>0) .* (reqTrq<=0) .* (1-u{2}).*reqTrq;
% Torque provided by electric motor
emTrq = (shaftSpd>0) .* u{2} .* reqTrq;
3 commentaires
Réponse acceptée
Walter Roberson
le 6 Sep 2021
Modifié(e) : Walter Roberson
le 6 Sep 2021
When you are working with numeric values, then a comparison operator returns logical false or logical true. Logical false, in most circumstances, concerns to double 0.0 and logical true in most circumstances converts to double 1.0. Therefore you can impliment
%result = VALUE1 if CONDITION2, otherwise VALUE2 if CONDITION2, otherwise 0
result = piecewise(CONDITION1, VALUE1, CONDITION2, VALUE2, 0)
as
(CONDITION1) .* (VALUE1) + (~CONDITION1).*(CONDITION2) .* (VALUE2)
In cases where the conditions are mutually exclusive, this can often be simplified to
(CONDITION1) .* (VALUE1) + (CONDITION2) .* (VALUE2)
However, you have to be careful that the values never become infinity for the unselected case. For example you cannot do
(x ~= 0) .* (1/x) + (x == 0) .* 1
to use 1 for x == 0 and 1/x for other x. This is because if you write like that, then at 0 you would have (x ~= 0) .* (1/0) which would be 0 (false) * infinity which would give NaN for that term, not 0.
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!