Filter löschen
Filter löschen

sqrt(complex(x)) error occuring earlier than expected

5 Ansichten (letzte 30 Tage)
I have a simple simscape model of an object moving on a perimeter of an ellipse. I managed to do this with two prismatic joints and using an ellipse equation I was able to to prescribe motion for the object. When the object hits the pole of an ellipse it should run into error because of sqrt(complex(x)) which is quite obvious. However, it runs into the problem way earlier and I don't know why.
The simulink model looks like this:
and the ellipse equation:
function y = fcn(x)
a=1;
b=1;
y = sqrt((b^2)*(1-x^2/a^2));
The simulation should stop near x=-1, but it stops with the domain error in this value of x:
This is the error:
An error occurred while running the simulation and the simulation was terminated
Caused by:
Domain error. To compute complex results from real x, use 'sqrt(complex(x))'.
Error in sqrt.m (line 13)
coder.internal.error('Coder:toolbox:ElFunDomainError',mfilename);
Error in 'vazba_elipsa/ellipse equation' (line 5)
Could anybody tell me where the problem is ? Thank you for your answers, Ondrej.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Okt. 2023
It looks to me as if you might be using continuous time. As such, the ode solver is going to evaluate the function at a number of different trial positions in order to determine where the best direction to step is. If the maximum step size is too large, then it might try beyond 1 even if it does not intend to go in that direction, as it "feels out" what the slope is like in the area.
You can impose a smaller maximum step size -- but as long as you are using continuous time and not clipping x then you should expect that x beyond +/-1 will be attempted as part of determining the correct slope for ode purposes.

Weitere Antworten (0)

Kategorien

Mehr zu General Applications finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by