Finding the minimizer using fminunc.

12 vues (au cours des 30 derniers jours)
Howie
Howie le 4 Nov 2022
Commenté : Howie le 5 Nov 2022
If I have function:
fv = @(x) x(1)^2 + x(1)*x(2) + (3/2)*x(2)^2 - 2*log(x(1)) - log(x(2));
How would I use the function fminunc to find the minimizer rather than the minimum value?

Réponse acceptée

Torsten
Torsten le 4 Nov 2022
fv = @(x) x(1)^2 + x(1)*x(2) + (3/2)*x(2)^2 - 2*log(x(1)) - log(x(2));
[minimizer,minimum_value] = fminunc(fv,[1; 1])
Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
minimizer = 2×1
0.8944 0.4472
minimum_value = 2.5279
  3 commentaires
Torsten
Torsten le 5 Nov 2022
Modifié(e) : Torsten le 5 Nov 2022
What else do you expect for a function with two variables to be optimized ?
An analytic expression for x1 and x2 ?
Howie
Howie le 5 Nov 2022
thank you!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 4 Nov 2022
If you need to find a maximum rather than a minimum then construct
nfv = @(x) -fv(x)
now minimize nfv using fminunc.
If you need to display what the maximum is remember to evaluate fv at the location of the maximum.
  1 commentaire
Howie
Howie le 4 Nov 2022
Modifié(e) : Howie le 4 Nov 2022
Sorry, I needed to find the minimizer rather than the minimum value Nor the maximum!

Connectez-vous pour commenter.

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by