Undefined function or variable

1 次查看(过去 30 天)
Jhon Dukester
Jhon Dukester 2014-4-9
评论: dpb 2014-4-9
Here is my code:
global ZX1 ZX3 ZX3
[Z,fval, exitflag] = fmincon('Type1',x0,[],[],[],[],lb,ub,@myconT1,options)
function f=Type1(d)
a=1;
b=0;
g=0;
f=(1+d1())^a+(1+d2())^b+(1+d3())^g;
end
function [c,ceq,d] = myconT1(X,d)
global xn V ZX1 ZX3 ZX4
c=0;
ceq(1)=(X'*V*X)-1;
xn=1-sum(X)
ceq(2)=sum(X)+xn-1;
ceq(3)=X'*R+0.33*xn+d1()-ZX1;
ceq(4)=mean((X'*(R-mean(R)))^3)+d3()-ZX3;
ceq(5)=-mean((X'*(R-mean(R)))^4)+d4()+ZX4;
end
It's note all my code. Error message:
Undefined function or variable 'd1'.
Error in Type1 (line 5) f=(1+d1())^a+(1+d2())^b+(1+d3())^g;
Error in fmincon (line 635) initVals.f = feval(funfcn{3},X,varargin{:});
Error in TP (line 158) [Z,fval, exitflag] = fmincon('Type1',x0,[],[],[],[],lb,ub,@myconT1,options)
Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
Any idea?
Thank you
  1 个评论
dpb
dpb 2014-4-9
Clearly it's not all the code because didn't even put in what is in context of the error message --
Undefined function or variable 'd1'.
Error in Type1 (line 5) f=(1+d1())^a+(1+d2())^b+(1+d3())^g;
Your problem is that in the above line there is no d1 in context. You need that definition first. One then presumes you'll move on to d2 and d3 in turn.
What are these intended to be and what are the empty paren's trying to indicate? If the various d are functions w/ no arguments then the () are superfluous and if they're arrays they're missing a subscript expression.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by