How do I force a zero value in Simscape language

14 vues (au cours des 30 derniers jours)
Ries Smith
Ries Smith le 24 Mar 2016
Commenté : Ries Smith le 28 Mar 2016
I have the following equation inside my custom Simscape block.
Mloc == sqrt( (Pratio^(gm1/-A.gam) * (1+(gm1/2)*Minf^2) - 1) * (2/gm1) );
I am encountering an issue where Pratio is near 1.0 and Minf is near zero, however rounding errors are causing the value inside the sqrt to become negative. How do I force the value inside the sqrt to remain non-negative? Here are some example numbers showing this situation.
sqrt(((14.715780533017/14.715780064774)^(0.4/-1.4) * (1+(0.4/2)*0.0001079^2) - 1) * (2/0.4))

Réponse acceptée

Sebastian Castro
Sebastian Castro le 25 Mar 2016
I would start off by changing the equations to something like
let
X = (Pratio^(gm1/-A.gam) * (1+(gm1/2)*Minf^2) - 1) * (2/gm1);
in
if X >= 0
Mloc == sqrt(X);
else
Mloc == {0,'appropriate_unit'};
end
end
In reality, most Simscape language blocks will have some sort of "smoothing" to prevent the sharp discontinuity -- usually a linear ramp down to zero over some threshold range (see, e.g., the Translational/Rotational friction blocks). You can try that further step if you run into problems, though.
- Sebastian
  1 commentaire
Ries Smith
Ries Smith le 28 Mar 2016
Thank you. That did the trick.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Brakes and Detents dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by