An error occurred while running the simulation and the simulation was terminated

5 views (last 30 days)
Hi everyone, I am using matlab simmulink to simulate the system. However, I am having the following 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)'.

Answers (1)

Walter Roberson
Walter Roberson on 28 Nov 2024
You have a MATLAB Function block in the lower left. It has s0 as input and ds0 as output. The 4th line of code for it is
ds0=(s0.^(q0/p0));
where q0/p0 does NOT happen to be an integer.
That code has problems when s0 is negative. Negative raised to a fractional power gives a complex result, but you have not specifically marked the inputs as being complex.
In practice, s0 does go negative.
You could try
ds0=(complex(s0).^(q0/p0));
and that will remove the error about complexity. However you will then get errors about how the complexity of ds0 does not match the back-propagated complexity of the signal. It is doubtful that your Position Tracking Controller is prepared to handle complex input.
  2 Comments
The Tran
The Tran on 29 Nov 2024
Thanks for your help. I am converting the file from S-function to matlab-function. However, the above error occurred because I am simulating the kinematic equations in the document. Can you help me check?
Walter Roberson
Walter Roberson on 29 Nov 2024
The file chap7_3plant.m uses
T1=abs(x1)^(q/p)*sign(x1);
T2=abs(x1)^(q/p-1)*sign(x1);
%...
T1=abs(x2)^(p/q)*sign(x2);
T2=abs(x2)^(2-p/q)*sign(x2);
Notice the abs(). Your implementation for ds0 has s0.^(q0/p0) without the abs()

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!