Effacer les filtres
Effacer les filtres

how to use fmincon solver for optimising a continuously varying function?

2 vues (au cours des 30 derniers jours)
Hi
I need to optimize a function of the form
y(i)= exp(-a(i)/x(1)) + 1.285 + ((b(i)^2)*x(2)) - (x(3)*c(i)*(1-exp(-c(i)/(x(3)*x(2))));
a(i) and c(i) are inputs. b(i) is dependant on a(i). The matrices a,b,c are obtained first. x(1),x(2),x(3) are the coefficients to be optimized. x>=0 .
When I try to use fmincon solver, it returns an error ::
Error using fmincon (line 607)
User supplied objective function must return a scalar value.
How do I rectify this?
Thanks
Nadia

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Juin 2016
function y = obj(x, a, b, c)
y = sum( ( exp(-a./x(1)) + 1.285 + ((b.^2).*x(2)) - (x(3).*c.*(1-exp(-c./(x(3).*x(2))))) ).^2 );
You need to recheck your equation as you have a missing ")" in it. I put it at the end.
To use the above:
fmincon( @(x) obj(x, a, b, c), x0, .....)
What will be minimized is the sum of squares. This is, in other words, a least squared minimimization.
  2 commentaires
Nadia A
Nadia A le 2 Juin 2016
Is it better to use lsqnonneg/lsqnonlin/lsqcurvefit instead of fmincon if this is actually minimizing the least squares?
Walter Roberson
Walter Roberson le 2 Juin 2016
lsqnonlin has better residue analysis, but the available algorithms are the same I think. Your only constraint is non-negative, which lsqnonlin can handle through the lb argument. If you had any linear or nonlinear constraints then you would have to use fmincon.
For lsqnonlin you would not do the sum() or the squaring yourself in the objective function.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by