Simscape sqrt assert failure in custom block

1 view (last 30 days)
Tyler V
Tyler V on 9 Dec 2013
Commented: Tyler V on 9 Dec 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 Comment
Tyler V
Tyler V on 9 Dec 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.

Sign in to comment.

Answers (0)

Categories

Find more on Foundation and Custom Domains in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!