Clear Filters
Clear Filters

Nonlinear optimization not working

1 view (last 30 days)
userpv
userpv on 7 Oct 2022
Commented: userpv on 7 Oct 2022
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?

Accepted Answer

Torsten
Torsten on 7 Oct 2022
Edited: Torsten on 7 Oct 2022
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

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!