Nonlinear optimization not working
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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)))
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)
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!