geometric linear programming help

3 次查看(过去 30 天)
hello everone can you help me?
In the code i want to get maximum value of 3*x+4*x with the constrain x^2+y^2<=1 and n=9
I have a code that dosent work i get this errors
Error using separateOptimStruct (line 25)
Use FMINCON function for this problem structure.
Error in linprog (line 126)
[f,A,B,Aeq,Beq,lb,ub,x0,options] =
separateOptimStruct(f);
Error in test (line 9)
[sol,fval,exitflag,output] = linprog(problem)
the code:
n=9;
z=0;
for(k=0:1:(n-1))
x = optimvar('x','LowerBound',0,'UpperBound',[]);
y = optimvar('y','LowerBound',0,'UpperBound',[]);
prob = optimproblem('Objective',3*x + 4*y,'ObjectiveSense','max');
prob.Constraints.c1 =((x*x)+(y*y)<=1);
problem=prob2struct(prob);
[sol,fval,exitflag,output] = linprog(problem)
i=fval*(-1);
if (z<=i)
q=sol
z=i
end
k
end

回答(1 个)

Jyothis Gireesh
Jyothis Gireesh 2020-1-22
From the code provided above, it is my understanding that there is a quadratic constraint involving “x”and “y” in addition to the non-negative constraints.
According to MATLAB documentation, it may not be a recommended practice to use “linprog” as it is better suited for problems involving a linear objective function and at least one linear constraint. A “fmincon”solver may be more appropriate in this case as indicated by the error message.
Please refer to the following documentation link on “Linear on Quadratic Objective with Quadratic Constraints” which contains pointers on how to reformulate the problem.

类别

Help CenterFile Exchange 中查找有关 Direct Search 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by