How to use fminunc for a 2D function composed of two functions?
Ältere Kommentare anzeigen
I have:

and I want to minimize it on the unit square
without using differentials.
I use the following code,
close all; clear; clc;
options = optimoptions(@fminunc,'Display','iter','Algorithm','quasi-newton');
xy_guess = [0,0];
[xy_opt,fval] = fminunc(@quadratic,xy_guess,options)
function f = quadratic(in)
x = in(1);
y = in(2);
f = -5.*x - 5.*y + 10.*x.^2 + 2.*x.*y
f = 1/200.*(-1000.*x - 1000.*y + 400.*x.*y + 1200.*y.^2 + 5.*cos(30.*x) + 4.*cos(80.*x.^2) + 5.*cos(30.*y) + 4.*cos(80.*y^2))
But declaring f twice does not work. How should I declare this double-function as an input for fminunc ?
Thanks!
2 Kommentare
Ashutosh Thakur
am 28 Jun. 2024
Hi Sergio,
With the last line of code the value of f is overwritten, and only this value is passed to the fminunc. Also I have observed that you have a constraint on the unit square. You can take advantage of the fmincon function, https://www.mathworks.com/help/optim/ug/fmincon.html, as fminunc does not have any constraint.
Can you try to use fmincon function?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Spline Postprocessing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
