Simscape sqrt assert failure in custom block

5 次查看(过去 30 天)
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 个评论
Tyler V
Tyler V 2013-12-9
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Foundation and Custom Domains 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by