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!