Why does my Nlgreyest freezes when used?

6 views (last 30 days)
Dwayne
Dwayne on 10 Jul 2024
Edited: akshatsood on 15 Jul 2024
I am trying to identify a nonlinear model with the nlgreyest command. Where the Filename is mij nonlinear model as a function handle. The function handle works perfectly when using the sim or even the step command to check if my function works.
However when the nlgreyest is used with display on, the display freezes, status remains busy, and looks like the figure below.
When I massively mash ctrl+c, I get the following error and nlgreyest seems to load.
I have tried to reduce the number of data points but that doesnt seem to work. I have tried to use different solvers, 15s and 23s because of stiffness. I tried to reduce the number of outputs and measured outputs. I also tried a linear estimation using greyest and a linear model and this does work.
I don't really what goes wrong here.
Its a 3 Output, 1 Input, 5 State model.
Order = [3,1,5];
Init = struct('Name', {'Angle' 'Angular Velocity' 'Current A' 'Current B' 'Current C'},...
'Unit', {'rad' 'rad/s' 'A' 'A' 'A'},...
'Value', {0 0 0 0 0},...
'Minimum', {-inf -inf -inf -inf -inf},...
'Maximum', {inf inf inf inf inf},...
'Fixed', {true true true true true});
% AZ 3 Phase
Parameters = struct('Name', {'Inertia' 'Viscous Friction' 'Inductance' 'Reistance' 'Motor Torque Constant' 'Motor Omega Constant' 'Pole Pairs'},...
'Unit', {'kg/m^2' 'kg/m/s' 'Henry' 'Ohm' 'Nm/A' 'V/rad/s' '-'},...
'Value', {Jm Bm La Ra Kt Kv PolePairs},...
'Minimum', {1e-6 1e-5 1e-5 1e-2 1e-2 1e-2 -inf},...
'Maximum', {1e-3 1e-2 1e-2 1e1 1e1 1e1 inf},...
'Fixed', {false false false false false false true});
optnl = nlgreyestOptions;
optnl.Display = 'on';
optnl.SearchMethod = 'lm';
nlgr = idnlgrey(FileName, Order, Parameters, Init,0);
datar = iddata(y, u, dt);
nlgr = nlgreyest(datar, nlgr, optnl);
  1 Comment
Tianyu
Tianyu on 11 Jul 2024
Hi Dwayne,
It is difficult to determine the issue solely from a partial script and the error message that was manually stopped. Could you please share the entire script along with the data, or provide a minimal reproducible example?

Sign in to comment.

Answers (1)

akshatsood
akshatsood on 15 Jul 2024
Edited: akshatsood on 15 Jul 2024
Dear @Dwayne,
I understand that you are encountering freeze while estimating parameters for a non-linear model using the "nlgreyest" function. Based on the information you provided, while defining the non-linear grey-box model using the "idnlgrey" function, you have specified "FileName" as a function handle. This handle works fine with "sim" and "step" functions.
From my understanding, the freeze can be attributed to the system being too slow to simulate. As you have already tried using the "ode15s" and "ode23s" stiff solvers, run a time analysis to measure how long each command takes. You can leverage the "tic" and "toc" functions for this purpose. Analyse the elapsed time output in the console.
tic
sim(...)
toc
tic
step(...)
toc
For more information on "tic" and "toc" function, refer to the following documentation
If choosing stiff solvers does not help, consider writing the ODE function as a MEX file. Using a MEX function for the ODE can significantly improve performance. However, before you proceed with this, ensure that your equations are well-posed and they simulate successfully using chosen initial parameter values and estimation input signals.
If the issue still persists, consider sharing the entire MATLAB script along with any additional data you have used. This will be helpful for me in reproducing the issue on my end and taking a better look into the issue.
I hope this helps.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!