From: Teresa Cascino on
Dear all,
I am new to Matlab and I am struggling a little bit with the fmincom function.
The code I wrote is the following:

x0=[200,200,1,2,2];

lb=[0,0,0,-Inf,-Inf];

ub=[Inf,Inf,Inf,Inf,Inf];

[x,fval,exitflag,output] = fmincon(@(x)BondParameters(beta,alpha,sigma,gamma,eta),x0,[],[],[],[],lb,ub)

where BondParameters is the function to minimize w.r.t. beta,alpha,sigma,gamma,eta. But for some reason, the program makes only 1 run and I get x=x0 as resulting x...I can not understand where I got wrong...

Thank you very much for your help,

Teresa
From: Torsten Hennig on
> Dear all,
> I am new to Matlab and I am struggling a little bit
> with the fmincom function.
> The code I wrote is the following:
>
> x0=[200,200,1,2,2];
>
> lb=[0,0,0,-Inf,-Inf];
>
> ub=[Inf,Inf,Inf,Inf,Inf];
>
> [x,fval,exitflag,output] =
> fmincon(@(x)BondParameters(beta,alpha,sigma,gamma,eta)
> ,x0,[],[],[],[],lb,ub)
>
> where BondParameters is the function to minimize
> w.r.t. beta,alpha,sigma,gamma,eta. But for some
> reason, the program makes only 1 run and I get x=x0
> as resulting x...I can not understand where I got
> wrong...
>
> Thank you very much for your help,
>
> Teresa

You forgot the x in the parameter list to
BondParameters.

Best wishes
Torsten.
From: Teresa Cascino on
Dear Torsten,

So you are saying that the fmincom operates only on x and not on the BondParameters function actually?
But then, when I have a function handle for function with parameters, how am I going to pass the parameters to the function handle? I think this is the point I didn't understand although I amreading many tutorials...

Thank you very much for your help,

Teresa


Torsten Hennig <Torsten.Hennig(a)umsicht.fhg.de> wrote in message <1753137053.97569.1281594539631.JavaMail.root(a)gallium.mathforum.org>...
> > Dear all,
> > I am new to Matlab and I am struggling a little bit
> > with the fmincom function.
> > The code I wrote is the following:
> >
> > x0=[200,200,1,2,2];
> >
> > lb=[0,0,0,-Inf,-Inf];
> >
> > ub=[Inf,Inf,Inf,Inf,Inf];
> >
> > [x,fval,exitflag,output] =
> > fmincon(@(x)BondParameters(beta,alpha,sigma,gamma,eta)
> > ,x0,[],[],[],[],lb,ub)
> >
> > where BondParameters is the function to minimize
> > w.r.t. beta,alpha,sigma,gamma,eta. But for some
> > reason, the program makes only 1 run and I get x=x0
> > as resulting x...I can not understand where I got
> > wrong...
> >
> > Thank you very much for your help,
> >
> > Teresa
>
> You forgot the x in the parameter list to
> BondParameters.
>
> Best wishes
> Torsten.
From: Torsten Hennig on
> Dear Torsten,
>
> So you are saying that the fmincom operates only on x
> and not on the BondParameters function actually?
> But then, when I have a function handle for function
> with parameters, how am I going to pass the
> parameters to the function handle? I think this is
> the point I didn't understand although I amreading
> many tutorials...
>
> Thank you very much for your help,
>
> Teresa
>
>

You _must_ pass the parameters expected by the
subroutine and you _can_ pass extra parameters.
In your case, the call would look like
[x,fval,exitflag,output] =
fmincon(@(x)BondParameters(x,beta,alpha,sigma,gamma,eta)
,x0,[],[],[],[],lb,ub)
and the suboutine BondParameters would have the
form
function f = BondParameters(x,beta,alpha,sigma,gamma,eta)
f = ...;

For further information, take a look at
http://www.mathworks.de/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html

Best wishes
Torsten.
From: Steven_Lord on


"Teresa Cascino" <teresacascino(a)gmail.com> wrote in message
news:i40dgl$jnh$1(a)fred.mathworks.com...
> Dear Torsten,
>
> So you are saying that the fmincom operates only on x and not on the
> BondParameters function actually?
> But then, when I have a function handle for function with parameters, how
> am I going to pass the parameters to the function handle? I think this is
> the point I didn't understand although I amreading many tutorials...

Your objective function was:

@(x)BondParameters(beta,alpha,sigma,gamma,eta)

FMINCON calls this function with various vectors of values x. Since x
doesn't appear in the call to BondParameters inside this anonymous function,
it's being called with the same inputs each time and so obviously this
function is going to return the same value each time. Thus FMINCON decides
that your function is flat at the starting point, and if it can't find a way
to move "downhill" from the starting point, it returns the starting point as
the optimal point.

Now I'm guessing you want to use the elements of x as the inputs to
BondParameters. If that's the case, you need to write your objective
function to reflect that.

@(x) BondParameters(x(1), x(2), x(3), x(4), x(5))

Alternately, if beta, alpha, sigma, gamma, and eta are additional parameters
that you want to pass into BondParameters _in addition to_ x, then do this:

@(x)BondParameters(x, beta,alpha,sigma,gamma,eta)

Now BondParameters is being called with different inputs each time FMINCON
gives it an x to use in evaluation, and so your function will not look flat
(unless it actually IS flat around your starting point.)

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com