Nonlinear optimization not working

조회 수: 4 (최근 30일)
userpv
userpv 2022년 10월 7일
댓글: userpv 2022년 10월 7일
Hi, I'm trying to solve the below:
min 25x+37y+48z
s.t.
z−0.25x∧2+0.1y∧2+0.01xy>=10,000
x,y,z>=200
y>=2z
So far, I have a function file:
function [c,ceq] = myfunction(x)
c(1) = z - 0.25*(x)^2 + 0.1*(y^2) + 0.01*x*y - 10000;
c(2) = x^2 - 200;
c(3) = y^2 - 200;
c(4) = z^2 - 200;
c(5) = y - 2*z;
ceq = [];
end
In the main file I have:
clc
clear
x=0;
y=0;
z=0;
fun = 25*x + 37*y + 48*z;
nonlcon=@myfunction;
x0 = [0,0,0];
A = []; % No other constraints
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
fvalue = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
I'm getting the below errors:
Error using optimfcnchk
FUN must be a function, a valid character vector expression, or an inline
function object.
Error in fmincon (line 430)
funfcn = optimfcnchk(FUN,'fmincon',length(varargin),funValCheck,flags.grad,flags.hess,false,Algorithm);
Error in HW6_4 (line 15)
fvalue = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
Can anyone advise on how to resolve this?

채택된 답변

Torsten
Torsten 2022년 10월 7일
편집: Torsten 2022년 10월 7일
fun = @(x,y,z) 25*x + 37*y + 48*z;
x0 = [0,0,0];
A = [0 -1 2];
b = [0];
Aeq = [];
beq = [];
lb = [200 200 200];
ub = [Inf Inf Inf];
fvalue = fmincon(@(x)fun(x(1),x(2),x(3)),x0,A,b,Aeq,beq,lb,ub,@(x)myfunction(x(1),x(2),x(3)))
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
fvalue = 1×3
200.0000 435.0843 200.0000
function [c,ceq] = myfunction(x,y,z)
c(1) =-( z - 0.25*x^2 + 0.1*y^2 + 0.01*x*y - 10000);
ceq = [];
end
  댓글 수: 1
userpv
userpv 2022년 10월 7일
This fixed the issue. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by