Optimization for minimizing cylinder dimensions

11 次查看(过去 30 天)
Hi there, I am hoping to verify my optimization calculations using Matlab for a cylinder's dimensions (inner (x2) and outer (x1) radius) with 2 constraint equations (max bending and deflection).
The function (objfun.m) was inputed as:
function f=objfun (x)
f=(3667.81*x(1)^2)-(3667.81*x(2)^2);
end
The constraint (constraints.m) was inputed as:
function[c,ceq]=constraints(x)
c=[-30*10^6+(31.23*(x(1)^2-x(2)^2)^(-1))+(58.33*x(1)*(x(1)^4-x(2)^4)^(-1));-0.005+(6.23591*10^(-11)*(x(1)^4-x(2)^4)^(-1))];
ceq=[];
end
My optimum (Optimum.m) script is as follows:
clc
clear all
warning off
x0=[0,0];
f=objfun(x0);
[c,ceq]=constraints (x0);
options=optimset('LargeScale', 'off');
[x,fval]=fmincon(@objfun,x0,[],[],[],[],@constraints, options);
[c,ceq]=constraints (x);
But when it is run I end up with the following:
Error using fmincon (line 220)
FMINCON requires the following inputs to be of data type double: 'LB','UB'.
Error in Optimum (line 8)
[x,fval]=fmincon(@objfun,x0,[],[],[],[],@constraints, options);
Any insight and assistance would be greatly appreciated. I have also attempted to use the Optimization tool in Matlab with no results yet, so if anyone is comfortable with that App I would love to learn it. Thank you

回答(1 个)

Alan Weiss
Alan Weiss 2017-3-19
编辑:Alan Weiss 2017-3-19
You missed counting the fmincon input arguments. Try this instead:
[x,fval] = fmincon(@objfun,x0,[],[],[],[],[],[],@constraints,options);
Two hints to help in the future:
1. Try defining ALL the fmincon arguments, even the ones you don't use. Such as
A = [];
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
[x,fval] = fmincon(@objfun,x0,A,b,Aeq,beq,lb,ub,@constraints,options);
2. Next time you want to ask a question and provide your code, use the {} Code button to make it look better (doesn't the code in my answer look better than that in your question?)
Alan Weiss
MATLAB mathematical toolbox documentation
  2 个评论
Sam Bergen
Sam Bergen 2017-3-20
Thank you so much for your response (and the tips!). I am still getting an error in that[x, fval] line.
Error using barrier (line 25)
Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 796)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in Optimum (line 11)
[x,fval]=fmincon(@objfun,x0,[],[],[],[],[],[],@constraints, options);
If you have any ideas I'd greatly appreciate them. Thanks again!
Torsten
Torsten 2017-3-20
If x(1) and x(2) are both zero at the beginning, you divide by zero in the constraint function.
Choose a different initial guess for x.
Best wishes
Torsten.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by