Effacer les filtres
Effacer les filtres

Alternate way of defining given function using function handle for fmincon

1 vue (au cours des 30 derniers jours)
I have an objective function which is of the form J = where C is a matrix of arbitrary constants which I have to determine along with 8 other arbitrary constants in the matrices A and B which appear in constraints and are known scalar matrices. I defined this objective function in MATLAB after evaluating the 4 product terms as follows-
fun =@(x) (x(9)+x(10)+x(11))^2+(x(9)+x(10)-x(11))^2+(x(9)-x(10)+x(12))^2+(x(9)-x(10)-x(12))^2;
where x(9) to x(12) are the 4 arbitrary constants in the matrix C and x(1) to x(8) are the 8 arbitrary constatnts in the matrices A and B. Then after setting
x0 = zeros(1,12);
and writing the constraints in terms of x(1) to x(8), I got all the 12 arbitrary constants x(1) to x(12) using fmincon. Now what I want is to write this objective function without evaluating each term. Is there any way to do the same?
  2 commentaires
Saurabh Madankar
Saurabh Madankar le 18 Fév 2022
Modifié(e) : Saurabh Madankar le 18 Fév 2022
One other way I could define this function is
fun =@(x) ([x(9) x(10) x(11) x(12)]*h(1))^2 + ([x(9) x(10) x(11) x(12)]*h(2))^2 + ...
([x(9) x(10) x(11) x(12)]*h(3))^2 + ([x(9) x(10) x(11) x(12)]*h(4))^2;
Is there any other way of writing the following row vector?
[x(9) x(10) x(11) x(12)]
Saurabh Madankar
Saurabh Madankar le 18 Fév 2022
I further reduced this as
fun =@(x) ([x(9:12)]*h(1))^2 + ([x(9:12)]*h(2))^2 + ([x(9:12)]*h(3))^2 + ([x(9:12)]*h(4))^2;
Now only thing thats remaining is instead of writing these four terms, how can I write this as summation of a single term?

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 18 Fév 2022
Modifié(e) : Matt J le 18 Fév 2022
Gather the into a 4x4 matrix H and A,B,C into an unknown 4x3 matrix X. Then write the problem as,
%X=[A,B,C]
%H=[h1,h2,h3,h4]
fun=@(X) norm(X(:,3).'*H).^2;
X0=zeros(4,3);
fmincon(fun,X0,Aineq,bineq,Aeq,beq,lb,ub,@nonlcon,opts)
function [c,ceq]=nonlcon(X)
A=X(:,1); B=X(:,2); C=X(:,3); %unpack
c=_____
ceq=_____
end

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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!

Translated by