Azzera filtri
Azzera filtri

Minimize multivariable function with multivariable nonlinear constraints in MATLAB

1 visualizzazione (ultimi 30 giorni)
Hi !
So I'm trying to :
  • minimize a function (non linear and multivariable)
  • with constraints also non linear, multivariable and with inequations (maybe we can use slack variables) and equations
And for now I've tried this
x=[H, P, L, A, B, M]; %name of my variables
fun=@(x) (x(1)*x(3)*cos(x(4))); %function to minimize
nonlcon = % ??????
x0=[0,0 ,0 ,0 ,0 ,0] %I will have to find a first solution
A=[x(3)*cos(x4), x(6)*cos(x5),x(3)*sin(x4)+ x(6)*sin(x5)]; %constraints with inequality
b=[12.5, 12.5,25]; %boundary for constraints with inequality
Aeq=[x(1)*cos(x(2)), x(3)*cos(x(4))]; %constraints with equality
beq=[x(1)-14,x(6)*cos(x5)]; %boundary for constraints with inequality
x = fmincon(fun,x0,A,b,Aeq,beq);
but this only works for linear constraint and can't understand how works nonlcon in
Can you help, thanks :)
  1 Commento
Torsten
Torsten il 23 Ott 2023
I'm not sure which nonlinear constraints you try to set with your A, b, Aeq and beq.
A and Aeq must have 6 columns and b and beq must have as many rows as A resp. Aeq in order that
A*x <= b or Aeq*x = beq
make sense.

Accedi per commentare.

Risposte (2)

Bruno Luong
Bruno Luong il 23 Ott 2023
x0 = [0;0;0;0;0;0];
x = fmincon(@mycost,x0,[],[],[],[], [],[],@mycon)
Converged to an infeasible point. fmincon stopped because the size of the current step is less than the value of the step size tolerance but constraints are not satisfied to within the value of the constraint tolerance. Consider enabling the interior point method feasibility mode.
x = 6×1
1.0e+13 * -1.4175 0.0000 1.1787 0.0000 0.0000 0.3344
function f = mycost(x)
f = (x(1)*x(3)*cos(x(4)));
end
function [c,ceq] = mycon(x)
A=[x(3)*cos(x(4));
x(6)*cos(x(5));
x(3)*sin(x(4))+ x(6)*sin(x(5))];
b = [12.5; 12.5; 25];
c = A-b;
Aeq=[x(1)*cos(x(2));
x(3)*cos(x(4))]; %constraints with equality
beq=[x(1)-14;
x(6)*cos(x(5))];
ceq = Aeq-beq;
end

Matt J
Matt J il 23 Ott 2023
Modificato: Matt J il 23 Ott 2023
The problem is unbounded. Consider x=[ 14, pi/2, x3,0,0,x6]. Then the problem reduces to the linear program,
This imposes no lowerbound on , so just send it to to push the objective to as well.

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by