Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fmincon function error

Subject: fmincon function error

From: Gerry

Date: 20 Jul, 2013 10:33:11

Message: 1 of 8

Getting the following error when calling fmincon fn:
-------------------------------
Undefined function 'classifyBoundsOnVars' for input arguments of type
'double'.

Error in fmincon (line 561)
    xIndices = classifyBoundsOnVars(l,u,sizes.nVar,false);
-----------------------------------
I am calling fmincon from a program using the following command:
fmincon(minFn,[.2 .2 .2],[],[],[],[],[],[],@nLinCons,optimset('Algorithm','sqp'));
where minFn is my function passed and @nLinCons are my function constraints.

Is it a path issue that is not set within my Matlab environment or is it some other problem?

Grateful if any assistance could be given to me on this issue.
Thank you.

Subject: fmincon function error

From: Chris

Date: 20 Jul, 2013 12:21:10

Message: 2 of 8

What version of Matlab are you using?
What value of @nLinCons are you passing?

Subject: fmincon function error

From: Gerry

Date: 21 Jul, 2013 11:32:10

Message: 3 of 8

Chris,

Thanks for reverting on this.

2012a Student version

@nLinCons calls this function nLinCons:

        function [c,ceq]=nLinCons(x)
            c(1) = T*x(3)^2 - 1; %constriant (nu^2*T)<1
            ceq = [];
        end

When running the code, don't seem to see where x(3) is set and therefore hence the possible problem. This is code that I have inherited and am working through it to see if issues with it and to be honest not fully au fait with the workings.

Is there any way of returning the parameter values set for @nLinCons. Stepping through the code does not seem to allow me to obtain the values passed. Is there way of getting the values passed? Also, is there workaround maybe by passing the values for c and ceq directly into fmincon vs using the calling fn @nLinCons .

Thanks
Gerry

"Chris " <cfweise@yahoo.com> wrote in message <ksdvbm$9lk$1@newscl01ah.mathworks.com>...
> What version of Matlab are you using?
> What value of @nLinCons are you passing?

Subject: fmincon function error

From: Chris

Date: 21 Jul, 2013 14:06:11

Message: 4 of 8

Unfortunately I have an earlier version without classifyBoundsOnVars in fmincon, but I'll do my best:
I am a little puzzled since
nLinCons
evaluates a variable T but that variable is not among the input parameters, so where does it come from?
My guess is that your nonlinear constraining function is messed up.

Otherwise you may want to check the values of u, l and sizes.nVar being passed at
xIndices = classifyBoundsOnVars(l,u,sizes.nVar,false);
inside fmincon, since this is were the problem arises, and see if they match what you expect. For instance try placing a breakpoint at that line and check the values of u,l, etc

Subject: fmincon function error

From: Gerry

Date: 27 Jul, 2013 10:27:12

Message: 5 of 8


Thank you Chris for reverting on this.

Actually, I understand x(3) is the third value of the 2nd argument that is passed into fmincon function (i.e. x(3) = 0.2 initially):
P(i,1:3) = fmincon(minFn,[.2 .2 .2],[],[],[],[],[],[],@nLinCons,optimset('Algorithm','sqp'));

As mentioned the code is inherited and is running on other machines with the full version of Matlab (not student version).

I checked the values for l, u, sizes.nVar. Three parameters are being optimised and therefore l and u are both single vectors with 3 values.
l= [-inf -inf -inf]
u=[inf inf inf]
sizes.nVar = 3

So the lower and upper bounds are set to -inf and inf resp. - it mustn't like this. Any further ideas? l and u can be passed as arguments values into the fmincon function? If so, I would set a large negative and positive values for lower and upper bounds and see if it likes this.

Thanks,
Gerry

"Chris " <cfweise@yahoo.com> wrote in message <ksgpsj$h58$1@newscl01ah.mathworks.com>...
> Unfortunately I have an earlier version without classifyBoundsOnVars in fmincon, but I'll do my best:
> I am a little puzzled since
> nLinCons
> evaluates a variable T but that variable is not among the input parameters, so where does it come from?
> My guess is that your nonlinear constraining function is messed up.
>
> Otherwise you may want to check the values of u, l and sizes.nVar being passed at
> xIndices = classifyBoundsOnVars(l,u,sizes.nVar,false);
> inside fmincon, since this is were the problem arises, and see if they match what you expect. For instance try placing a breakpoint at that line and check the values of u,l, etc

Subject: fmincon function error

From: Gerry

Date: 27 Jul, 2013 11:22:11

Message: 6 of 8

Chris,

In response to your query re variable T. This variable is set within the function that execute the fmincon fn. nLinCons fn is inside this function too, therefore value for T is initialised (that said as mentioned previously, stepping through the code, I can't seem to pull back the value set, for example, for c(1) in nLinCons as the nLinCons fn is called within fmincon - (you know of anyway of stepping into the nLincons fn to see the variables passed and calculations executed)).

Shortened extract of the function:

   function [SABRParams, SABRResiduals] = calibrateSABR()
        
        %for loop from 1 to no of time intervals for the implied surface
        for i = 1:length(impliedVolatilitySurface(2:end,1))
            
            T = impliedVolatilitySurface(i+1,1);
            .........
            .........
            .........
            .........
            minFn = @(b)sum((sabrFn(b(1),b(2),b(3))-impliedVolatilitySurface(i+1,2:end)).^2);
            %Minimise the errors using the constraint.
           P(i,1:3) = fmincon(minFn,[.2 .2 .2],[],[],[],[],[],[],@nLinCons,optimset('Algorithm','sqp'));

            .........
            .........
        end
        
        %Define constraints for fmincons
        function [c,ceq]=nLinCons(x)
            c(1) = T*x(3)^2 - 1; %constriant (nu^2*T)<1
            ceq = [];
        end
            .........
            .........
            .........
end

Regards,
Gerry

"Gerry" wrote in message <kt07a0$393$1@newscl01ah.mathworks.com>...
>
> Thank you Chris for reverting on this.
>
> Actually, I understand x(3) is the third value of the 2nd argument that is passed into fmincon function (i.e. x(3) = 0.2 initially):
> P(i,1:3) = fmincon(minFn,[.2 .2 .2],[],[],[],[],[],[],@nLinCons,optimset('Algorithm','sqp'));
>
> As mentioned the code is inherited and is running on other machines with the full version of Matlab (not student version).
>
> I checked the values for l, u, sizes.nVar. Three parameters are being optimised and therefore l and u are both single vectors with 3 values.
> l= [-inf -inf -inf]
> u=[inf inf inf]
> sizes.nVar = 3
>
> So the lower and upper bounds are set to -inf and inf resp. - it mustn't like this. Any further ideas? l and u can be passed as arguments values into the fmincon function? If so, I would set a large negative and positive values for lower and upper bounds and see if it likes this.
>
> Thanks,
> Gerry
>
> "Chris " <cfweise@yahoo.com> wrote in message <ksgpsj$h58$1@newscl01ah.mathworks.com>...
> > Unfortunately I have an earlier version without classifyBoundsOnVars in fmincon, but I'll do my best:
> > I am a little puzzled since
> > nLinCons
> > evaluates a variable T but that variable is not among the input parameters, so where does it come from?
> > My guess is that your nonlinear constraining function is messed up.
> >
> > Otherwise you may want to check the values of u, l and sizes.nVar being passed at
> > xIndices = classifyBoundsOnVars(l,u,sizes.nVar,false);
> > inside fmincon, since this is were the problem arises, and see if they match what you expect. For instance try placing a breakpoint at that line and check the values of u,l, etc

Subject: fmincon function error

From: Chris

Date: 27 Jul, 2013 14:19:14

Message: 7 of 8

I am at a loss as to what may causing the problem.
Best I can suggest is reposting to the newsreader, or trying this on stackoverflow with a matlab tag.

Subject: fmincon function error

From: Gerry

Date: 20 Aug, 2013 14:20:34

Message: 8 of 8

"Chris" wrote in message <kt0kt2$163$1@newscl01ah.mathworks.com>...
> I am at a loss as to what may causing the problem.
> Best I can suggest is reposting to the newsreader, or trying this on stackoverflow with a matlab tag.

Thanks Chris. It might be an installation issue with 2012a (I have student version). I am looking for lsqnonlin.m in the Optimization Toolbox and its not be found. Apparently, I have another posts about this suggesting that there may be an installation issue. I suppose 'get in and out of the car' in IT speak - reinstall or upgrade to the latest version and move on...

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us