passing matrices in fmincon objective function

5 Ansichten (letzte 30 Tage)
Isha Malekar
Isha Malekar am 19 Jul. 2020
Beantwortet: Alan Weiss am 20 Jul. 2020
My objective function has matrices of below sizes
A = 150x50, B = 150x150
objective function is J = p*A'*B*A*p
Below is the code I am using -
p0 = 0.3;
plb = -0.5;
pup = 0.5;
[p,cost] = fmincon(@(p) mycost(p),p0,[],[],[],[],plb,pup);
function J = mycost(p)
% created matrices A(150x50) & B(150x150)
J = (p*A'*B*A*p);
end
My objective function size with these matrices will be 50x50. I am trying to get value of p by minimizing the objective function. I am getting following error -
"Supplied objective function must return a scalar value."

Antworten (1)

Alan Weiss
Alan Weiss am 20 Jul. 2020
What does it mean to minimize a function that has more than one dimension? The answer is, the problem is ill-defined, there is no one meaning to this question. fmincon minimizes only scalar-valued functions.
Maybe you mean to minimize the sum of squares of the entries in J. Maybe you mean to minimize the maximum entry. Maybe you mean to minimize the sum of absolute values of the entries. See, there is no unique meaning to minimizing a function with multiple outputs. No solver will do that.
If you mean to minimize the sum of squares of the entries, you can use lsqnonlin with a slight change in syntax.
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

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

Start Hunting!

Translated by