How do i use optimization toolbox to optimize an objective function with matrix input variables (4x4)
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an objective function and non linear constraint m file as follows:
objective function
function k = mut(u)
load('matlab1.mat')
k = (exp(u(1)*test__TT*u(2)));
end
non linear constraint
function [c,ceq] = constr(u)
load('matlab1.mat')
% Nonlinear inequality constraints
c = (exp(u(1)*test__TT*u(2)))-B;
ceq = [];
end
% End of function
test_TT input variable is a 4x4 matrix
i am solving using the optimization tool box "fmincon". u0 = [0 0]
when i run the optimization solver, i get an error saying "Supplied objective function must return a scalar value."
basically, my output should be two (4x4) optimal variables for u(1) and u(2).
how to i setup the problem to return solution thats calculates the optimal for each variable matrix pair (element wise).
0 commentaires
Réponses (1)
Alan Weiss
le 3 Fév 2017
You can only optimize scalar objective functions. What does it mean to optimize two or more functions at the same time? Either optimize each function separately, or find a Pareto front for a multiobjective optimization.
In terms of programming efficiency, you should not put a load statement in an objective function or nonlinear constraint function. Instead, load the data into your workspace just once, and then pass parameters using anonymous functions or nested functions as you prefer.
Alan Weiss
MATLAB mathematical toolbox documentation
4 commentaires
Walter Roberson
le 11 Fév 2017
Does your objective function take multiple inputs and return a scalar output? If so, then don't worry about it: just pass in a matrix for the initial values of the variable and you will get out a matrix of the same size, and your objective function will be passed the variable in the form of a matrix.
Does your objective function return a non-scalar output? If so then that cannot be handled by MATLAB using fmincon or ga or particleswarm or patternsearch or simulated annealing. It can be handled by gamultiobj() though.
Voir également
Catégories
En savoir plus sur Problem-Based Nonlinear Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!