Simscape sqrt assert failure in custom block

4 visualizzazioni (ultimi 30 giorni)
Tyler V
Tyler V il 9 Dic 2013
Commentato: Tyler V il 9 Dic 2013
I have a custom Simscape component (thermal and pneumatic) and have the following expression in a let block within the equations section:
TcEff = (Ap + 2*Omega)/(4*R);
D = ...
if temperature >= TcEff, ...
{0, '1'} ...
else ...
abs(1 - temperature/TcEff) ...
end
% Get two solutions
xL = (1 - sqrt(D))/2;
xR = (1 + sqrt(D))/2;
where Ap, Omega, and R are parameters and temperature is a variable. The component compiles without errors, but when I run a simple test diagram with it I get an assertion triggered at time 0.0 by the first sqrt function ("Input must be non-negative"). If I remove the sqrt functions and set xL and xR to constant values as a test the component works. I thought that between the if - else statement and the abs() this would be protected against square roots of negative numbers.
How can I keep this assertion from occurring? Is there a better way to keep the input to sqrt from going negative and/or why doesn't this work?
Thanks!
  1 Commento
Tyler V
Tyler V il 9 Dic 2013
I still do not know why the assert is being generated, but I found that I can get around it by using D^0.5 rather than sqrt(D). The fact that this doesn't generate any complex number errors makes the assert all the more puzzling.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Foundation and Custom Domains in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by