passing matrices in fmincon objective function
6 次查看(过去 30 天)
显示 更早的评论
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."
0 个评论
回答(1 个)
Alan Weiss
2020-7-20
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!