필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
Ondrej Zoufaly
Ondrej Zoufaly 2023년 10월 7일
답변: Walter Roberson 2023년 10월 7일
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.

채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 7일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by