How to solve a nonlinear least square problem with constraints

Hello,
I'm using to function lqsnonlin to solve a nonlinear least square problem. Additional to the upper bound I need a constraint with notation 2*mu*kappa-sigma^2>=0. I have four Parameters: mu, Sigma, kappa,y0. Do someone have an idea how i could add this constraint? Or should i better use another function than lqsnonlin?
I would be very greatful for each advise.

Answers (3)

I am not sure what that constraint means in terms of your decision variables (the variables you adjust to achieve an optimum). If mu, Sigma, kappa, and y0 are your decision variables, then this is a nonlinear constraint, and the only solver that addresses problems with nonlinear constraints is fmincon.
You would include the constraint as follows (I assume that the vector x is [mu, Sigma, kappa, y0]):
function [c,ceq] = confun(x)
ceq = []; % no equality constraint
c = x(2)^2 - 2*x(1)*x(3); % sigma^2 - 2*mu*kappa <= 0
You would also have to change your objective function to be the sum of the squares of your current vector-valued objective function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Thank you Alan for your answer. I tried it with fmincon, but I always get a 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.
You wrote
function [c] = mycon(x)
c = [x(3)^2-2*x(2)*x(1)];
ceq=[];
But you called the nonlinear constraint function myfun , not mycon , in fmincon:
[x,fval]=fmincon(@KalibrierungCIR,x0,[],[],[],[],lb,[],@myfun)
Alan Weiss
MATLAB mathematical toolbox documentation

Categories

Asked:

on 16 Sep 2013

Answered:

on 30 Sep 2013

Community Treasure Hunt

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

Start Hunting!