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!