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.

Réponses (1)

Matt J
Matt J le 28 Sep 2013

0 votes

You've named your constraint function "mycon", but where you invoke fmincon, you instead call it "myfun".

6 commentaires

Thank you Matt J , you are right.
now I get this message: Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you have specified. FMINCON will use the active-set algorithm instead. For information on applicable algorithms, see Choosing the Algorithm in the documentation. > In fmincon at 486
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 400 (the default value).
x =
NaN NaN NaN NaN
fval =
NaN
so it still do not work.
Matt J
Matt J le 28 Sep 2013
Modifié(e) : Matt J le 28 Sep 2013
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.
I'm not that familiar with matlab but if I would like to try your proposal than I would write
options = optimoptions('fmincon','Algorithm','interior-point','AlwaysHonorConstraints','none');
[x,fval]=fmincon(@KalibrierungCIR,x0,[],[],[],[],lb,[],@mycon,options)
right?
Yes. Or you could try the sqp algorithm.
using on of the algorithm I get a erreor message again:
>> options = optimoptions('fmincon','Algorithm','sqp','AlwaysHonorConstraints','none');
Undefined function 'optimoptions' for input arguments of type 'char'.
You might have a version of MATLAB that pre-dates optimoptions. If so, you will have to use optimset.

Connectez-vous pour commenter.

Question posée :

le 28 Sep 2013

Commenté :

le 29 Sep 2013

Community Treasure Hunt

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

Start Hunting!

Translated by