Optimization for minimizing cylinder dimensions
Mostra commenti meno recenti
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
Risposte (1)
Alan Weiss
il 19 Mar 2017
Modificato: Alan Weiss
il 19 Mar 2017
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 Commenti
Sam Bergen
il 20 Mar 2017
Torsten
il 20 Mar 2017
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.
Categorie
Scopri di più su Get Started with Optimization Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!