How to use fminunc for a 2D function composed of two functions?
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!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! 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! fminunc, declare, function MATLAB Answers — New Questions