Can someone help with nonlinear optimization with constraints? (i've tried tutorials with no luck)

1 次查看(过去 30 天)
Hi, I've been working on a hw assignment for a while trying to self teach optimization and its proving difficult. I have to minimize the function x1^3-6x1^2+11x1+x3 with the following constraints:
x1^2+x2^2-x3^2<=0 4-x1^2-x2^2-x3^2<=0 x3-5<=0 -x1<=0 -x2<=0 -x3<=0 the starting feasible point is .1,.1,3 So far, by looking at the tutorials I've come up with this coding, but I'm getting an error message about the function definition, saying "x and fval may not be used". Also, the code runs and in the command window k>> appears. Any help would be appreciated.
function f=mae342hw5p2(x) f=x1.^3-6.*x1.^2+11.*x1+x3; function [c,ceq]=confun(x) c=[ x1^2+x2^2-x3^2; 4-x1^2-x2^2-x3^2; x3-5;-x1;-x2;-x3]; ceq = []; x0=[.1 .1 3]; options=optimset('Algorithm','active-set'); [x,fval]=... fmincon(@mae342hw5p2,x0,[],[],[],[],[],[],@confun,options);

采纳的回答

Jing
Jing 2013-2-25
The input of every function includes 'x', but there's no x in the function body. Actually, you should write your function as follows:(and it's a bit weird without x(2) in your target function...)
function f=mae342hw5p2(x)
f=x(1).^3-6.*x(1).^2+11.*x(1)+x(3);
For the constraints, it's better to separate the linear and non-linear constraints, which makes the non-linear constraints function to be:
function [c,ceq]=confun(x)
c=[ x(1)^2+x(2)^2-x(3)^2; 4-x(1)^2-x(2)^2-x(3)^2];
ceq=[];
the linear constraints can be set by upper and lower boundary when you call fmincon: lb=[-Inf,-Inf,0];ub=[0,0,5];
Hope you understand!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by