Non-linear least squares estimation with linear constraints in Simulink?

I'm trying to implement a non-linear least squares solver in Simulink, with linear constraints. However, it seems that only the 'levenberg-marquardt' algorithm can be used in Simulink, which does not have the facility to add linear constraints.
I get the following error message when I try to use the 'interior-point' algorithm:
OPTIMOPTIONS property 'Algorithm' must be one of the following values for lsqcurvefit:
'levenberg-marquardt'
My code is:
options = optimoptions('lsqcurvefit', 'Algorithm', 'interior-point');
x = lsqcurvefit(fun, x0, Q, P, lb, ub, options);
This problem does not occur when I use the lsqcurvefit function in a regular MATLAB script.
Do you have any advice on how I could implement a non-linear least squares solver with linear constraints in Simulink?
Many thanks.

 Akzeptierte Antwort

Torsten
Torsten am 11 Nov. 2024
Bearbeitet: Torsten am 11 Nov. 2024
I vaguely remember that using "lsqcurvefit" within Simulink requires to use the Levenberg-Marquardt algorithm. I can't answer why this is the case (if you are interested, you should ask Technical Support), but you simply have to accept this. But you only seem to have lower and upper bounds on the variables
x = lsqcurvefit(fun, x0, Q, P, lb, ub, options);
- so why don't you try Levenberg-Marquard ?
If this algorithm within "lsqcurvefit" doesn't succeed, what about using "fmincon" instead ?

3 Kommentare

Many thanks. I'll contact Technical Support.
Apologies. In the example I wrote, there are only upper and lower bounds, but I would also like to implement linear constraints.
I have tried Levenberg-Marquardt and it works, but it would be better to have linear constraints as well because this would ensure the solution remains real (rather than complex).
I'm not sure if it's possible to implement least squares objective functions in fmincon? And I assume they're all based on the same underlying algorithm. (I tried lsqnonlin, and it had the same problem.) But I could definitely give fmincon a go.
If you use
sum((yexp-ysim).^2)
as objective function for "fmincon", you should get the same solution as if you specify
yexp-ysim
in "lsqnonlin" or
ysim
in "lsqcurvefit".
I don't know if special algorithms are excluded if you use "fmincon" within Simulink. Just test it.
Have had some success with 'fmincon'. Seems it can be used in Simulink with 'sqp' or 'sqp-legacy' algorithms. The estimates can be good, but not as good or robust as 'lsqcurvefit'. Might try to find some C code for a non-linear least squares estimator with linear constraints, and implement that directly in Simulink.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2023b

Gefragt:

am 11 Nov. 2024

Kommentiert:

am 12 Nov. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by