フィルターのクリア

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 Center および File ExchangeGeneral Applications についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by