Explanation for the below equation containing the comparsion symbols
1 次查看(过去 30 天)
显示 更早的评论
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;
采纳的回答
Walter Roberson
2021-9-6
编辑:Walter Roberson
2021-9-6
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!