"Runtime Error: Call to MATLAB function aborted: Domain error. To compute complex results, make at least one input complex, e.g. 'power(complex(a),b)'."

27 次查看(过去 30 天)
Hello, I'm trying to solve the following system in Simulink. I have some coder.extrinsic('intpolyval') into the Embeeded Matlab Function to deal with function handles I need to use while exchanging variables between functions, for instance:
function sol=intpolyval(coeff,minx,maxx)
sol=integral(@(x) polyval(coeff,x),minx,maxx);
end
While i try to run my model I get the error in debugger:
"Runtime Error: Call to MATLAB function aborted: Domain error. To compute complex results, make at least one input complex, e.g. 'power(complex(a),b)'."
This only happens when there is a loop in the Simulink model, while the model is simple- everything goes all right. Did anyone have similiar problems? How have u worked arround it?

采纳的回答

Walter Roberson
Walter Roberson 2015-7-9
When there is a expression that might produce a complex result, the input signals for the calculation must be changed to Complex, or you must use complex() on the real signals that might produce a complex result. For example if you have sqrt() then if the input might go negative then you need to complex() the input before taking the sqrt.
I gather the error shows up at the time the need for a complex result is detected, so if you are not expecting the calculation to produce a complex result you may need to add debugging to see why it does produce such a result.
MATLAB silently transforms values to complex at need, but Simulink does not.
When you have a loop, Simulink has to solve the loop to establish the initial conditions for self-consistency because everything in one step has to be true simultaneously (if that is not needed for you then send your signal through a time delay so the rest of the calculation can be performed in the next step) . The result can include values outside the range you expect.
  2 个评论
Lukasz Wieczorek
Lukasz Wieczorek 2015-7-16
Well, the problem is I can solve single fcn block while there's no loops. The result is quite so, I've computed it in another soft as well and it produces the same result. That's why I'm sure about the code in Matlab and the problem must lay somewhere in Simulink. When I run Debbug it refers me to the location of the problem, and it seems the result goes somewhere out of range I expect. Is there any way to get know each particuliar step of iteration process in Simulink? I consider to solve the problem direcly in Matlab using fsolve.
Walter Roberson
Walter Roberson 2015-7-16
You have a loop that probably does not take into account the time required to compute the result. Simulink needs to run the computations in such a way as to make everything for a single step true simultaneously. That can result in your inputs being different than you expect.

请先登录,再进行评论。

更多回答(1 个)

shulin hu
shulin hu 2018-10-28
编辑:Walter Roberson 2020-7-7
hello,have you solve it?I have the similar problem:
Call to matlab function aborted:Domain error,To compute complex results from real x,use 'log(complex(x))'
function y = fcn(u1,u2,t) %#codegen
if t>0.4
y=-2.875*t/log(1-(2.875*u1/u2));
end
  2 个评论
jose luis huayanay villar
hello,have you solve it?I have the similar problem:
An error occurred while running the simulation and the simulation was terminated
Caused by:
  • Domain error. To compute complex results, make at least one input complex, e.g. 'power(complex(a),b)'.
Walter Roberson
Walter Roberson 2020-7-7
function y = fcn(u1,u2,t) %#codegen
if t>0.4
y=-2.875*t/log(complex(1-(2.875*u1/u2)));
end
The original code would have had problems when u1 > u2 / 2.875 so that the log() would have been of a negative number.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Configure Simulation Conditions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by