Error: Expression or statement is incomplete or incorrect
4 views (last 30 days)
Show older comments
I'm working on minimizing an objective function using fmincon. Below I have included the objective function, as well as the constraints and gradient functions.
options=optimset('LargeScale','on','GradObj','off','GradConstr','off',...
'TolCon',1e-8,'TolX',1e-8);
Lb=[0.25,0.005]; Ub=[1.5;0.1]; % upper and lower bounds for x1 & x2
x0=[1.5;0.1]; % initial design pt.
[x,FunVal,ExitFlag,output]=fmincon('FinalProj_ObjAndGrad',x0,...
[],[],[],[],Lb,Ub,'FinalProj_ConstAndGrad',options)
function [ g,h,gg,gh ] = FinalProj_ConstAndGrad( x )
% Constraints and Gradients
x1=x(1); % do
x2=x(2); % t
g(1)=(184/(28125*pi^3*(x1-x2)*x2*((x1)^2/2-x1*x2+(x2)^2))+(x1*(563200+34865152/(5625*pi*(x1^4-(x1-2*x2)^4))))/(4375000*pi*((x1)^4-(x1-2*x2)^4)))-1;
g(2)=((272384)/(3515625*pi*(x1^4-(x1-2*x2)^4)))-0.1;
g(3)=(x1/x2)-92;
h=[ ]; %no equality constraints
% if nargout>2
% gg(1,1)=(x1*(34865152/(5625*pi*(x1^4-(x1-2*x2)^4))+563200))/...
%(4375000*pi*(x1^4-(x1-2*x2)^4))-(368*(3*x1^2-6*x1*x2+4*x2^2))/...
%(28125*pi^3*x2*(x2-x1)^2*(x1^2-2*x1*x2+2*x2^2)^2);
% gg(2,1)=(x1*(34865152/(5625*pi*(x1^4-(x1-2*x2)^4))+563200))/...
%(4375000*pi*(x1^4-(x1-2*x2)^4))-(368*(x1-2*x2)^3)/...
%(28125*pi^3*x2^2*(x1-x2)^2*(x1^2-2*x1*x2+2*x2^2)^2);
% gh=[ ];
end
function [ f, gf ] = FinalProj_ObjAndGrad( x )
% Objective function and gradient for minimizing weight of column
x1=x(1); % do
x2=x(2); % t
f=(400000*pi)*(x1^2-(x1-2*x2)^2); %weight of support column,
if nargout >1
gf(1,1)=1600000*pi*x2;
gf(2,1)=16000000*pi*(x1-2*x2);
end
When the first m-file is run the following error appears:
Error using feval Error: File: FinalProj_ConstAndGrad.m Line: 5 Column: 6 Expression or statement is incomplete or incorrect.
Error in fmincon (line 681) [ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error in Final_Proj (line 11) [x,FunVal,ExitFlag,output]=fmincon('FinalProj_ObjAndGrad',x0,...
Caused by: Failure in initial user-supplied nonlinear constraint function evaluation. FMINCON cannot continue.
0 Comments
Answers (0)
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!