using fmincon for min problem with nonlinear constraints
显示 更早的评论
Hello,
I tried to solve a min problem with nonlinear constraints with fmincon, but I always get an error massage.
Here are the functions I use:
function[F]= KalibrierungCIR(x)
h=sqrt(x(1)^2+2*x(3)^2);
A=(((2*h*exp(x(1)+h)*Maturity/2))./(2*h+(x(1)+h)*(exp(Maturity*h)-1))).^(2*x(1)*x(2)/x(3)^2);
B=(2*(exp(Maturity*h)-1))./(2*h+(x(1)+h)*(exp(Maturity*h)-1));
PCIR=A.*exp(-B.*x(4));
lambda_Dach=-(log(PCIR(2:length(PCIR)))-log(PCIR(1:length(PCIR)-1)))./ (Maturity(2:length(Maturity))-Maturity(1:length(Maturity)-1));
F=sum(lambda_Dach-lambda)/length(lambda);
Hier i get a scalar. My constraints are:
function [c] = mycon(x)
c = [x(3)^2-2*x(2)*x(1)];
ceq=[];
Then I type:
lb=[0.00000001 0.00000001 0.0000001 0.0001]; x0=[0.1 0.1 0.1 0.1]; [x,fval]=fmincon(@KalibrierungCIR,x0,[],[],[],[],lb,[],@myfun)
and get the error message:
Error using feval Undefined function 'myfun' for input arguments of type 'double'.
Error in fmincon (line 681) [ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Caused by: Failure in initial user-supplied nonlinear constraint function evaluation. FMINCON cannot continue.
I have realy no idea where the problem is! I would be very greatful if someone could help me.
回答(1 个)
Matt J
2013-9-28
0 个投票
You've named your constraint function "mycon", but where you invoke fmincon, you instead call it "myfun".
6 个评论
Anastasia
2013-9-28
Your objective function is generating NaN values. Use
>>dbstop if naninf
to trap the occurrence of that and investigate why it is doing so.
It might be because your bound constraints are being violated at some iterations. You could try using the 'sqp' algorithm or the 'interior-point' algorithm with the "AlwaysHonorConstraints' option turned on.
Anastasia
2013-9-28
Matt J
2013-9-28
Yes. Or you could try the sqp algorithm.
Anastasia
2013-9-29
Matt J
2013-9-29
You might have a version of MATLAB that pre-dates optimoptions. If so, you will have to use optimset.
类别
在 帮助中心 和 File Exchange 中查找有关 Solver-Based Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!