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.
Simscape sqrt assert failure in custom block
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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!
Respuestas (0)
Ver también
Categorías
Más información sobre Foundation and Custom Domains en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!