Azzera filtri
Azzera filtri

Solve optimization problem using fmincon

4 visualizzazioni (ultimi 30 giorni)
Optimization problem to solve:
Here are constant. I am trying to solve the problem with the following code given below (with fixed y), but is y variable. So could you please give any idea how to solve this problem. Thanking you.
Code:
% create file nlcon.m for nonlinear constraints
function [c,ceq] = nlcon(x,k1,k2,k3,k4)
y=0.50;
c1 = 10 - y.*log2(1+k3*k1*x);
c2 = 10- (1-y).*log2(1+(y.*(k4*k2)*x)./(1-y));
c = [c1;c2];
ceq = [];
% This is main function
function y= main(k1,k2,k3,k4,c1,c2)
objective = @(x) x;
% initial guess
x0 = 0;
% variable bounds
lb = 0;
ub = 200;
% show initial objective
%disp(['Initial Objective: ' num2str(objective(x0))])
% linear constraints
%A(1) = [];
A1 = -k1;
%A(2) = [];
A2 = -k2;
A = [A1;A2];
b1=-c1;
b2=-c2;
b = [b1;b2];
Aeq = [];
beq = [];
% nonlinear constraints
nonlincon = @(x)nlcon(x,k1,k2,k3,k4);
% optimize with fmincon
%[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]
% = fmincon(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,OPTIONS)
y = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,nonlincon);

Risposte (1)

Thiago Henrique Gomes Lobato
The answer depends on how you define your problem. If y is variable and it should be minimized together with your x than it belongs to your input vector x, so you actually needs to optimize a vector with two input variables being one of them your y. In case your y is just a general constrain that should hold for every y than an easy work around you can make is to generate a grid of y points in your non-linear constrain function and save always the worst result to the constrain (you can find more options to handle this constrain looking for semi-infinite programming. Matlab also has some options to deal with it: https://de.mathworks.com/help/optim/ug/two-dimensional-semi-infinite-constraint.html).

Categorie

Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by