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, Hessian and extra parameters

Subject: fmincon, Hessian and extra parameters

From: Marco

Date: 21 Mar, 2010 21:31:02

Message: 1 of 7

Hi,
I got a problem with the definition of the Hessian used by the FMINCON function.
I'm using the interior-point algorithm to solve a constrained nonlinear problem.
I calculated the analytic expression of both gradient and Hessian, and
I'm passing both to FMINCON using the options ('GradObj','on') and
('Hessian','user-supplied'). The Hessian function is a separate defined function named @hessmgrp. It works, but I have a programming problem.

My Hessian is a function of two vectors: the target vector and another vector.
The input arguments of the Hessian function are only two, the target vector
and the Lagrange multipliers, that is

function h = hessmgrp(y,lambda)

Then, I have to pass the extra parameter to this function. I read the optim toolbox manual and found different solutions. Eventually, the only way I found is to define global variables and use them locally. It is not the best solution, as remarked in the manual.

Does anybody of you know how to pass extra parameters to
the Hessian function in a more appropriate way?

Thanks in advance
Marco

Subject: fmincon, Hessian and extra parameters

From: Steven Lord

Date: 21 Mar, 2010 22:21:10

Message: 2 of 7


"Marco " <marinimar@gmail.com> wrote in message
news:ho636m$g99$1@fred.mathworks.com...
> Hi,
> I got a problem with the definition of the Hessian used by the FMINCON
> function.
> I'm using the interior-point algorithm to solve a constrained nonlinear
> problem.
> I calculated the analytic expression of both gradient and Hessian, and
> I'm passing both to FMINCON using the options ('GradObj','on') and
> ('Hessian','user-supplied'). The Hessian function is a separate defined
> function named @hessmgrp. It works, but I have a programming problem.
>
> My Hessian is a function of two vectors: the target vector and another
> vector. The input arguments of the Hessian function are only two, the
> target vector
> and the Lagrange multipliers, that is
>
> function h = hessmgrp(y,lambda)
>
> Then, I have to pass the extra parameter to this function. I read the
> optim toolbox manual and found different solutions. Eventually, the only
> way I found is to define global variables and use them locally. It is not
> the best solution, as remarked in the manual.
>
> Does anybody of you know how to pass extra parameters to
> the Hessian function in a more appropriate way?

Anonymous function. Specify your Hessian function as @(y, lambda)
hessmgrp(y, lambda, whateverOtherParametersYouWant) [as long as
whateverOtherParametersYouWant are defined before you create this anonymous
function handle.]

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: fmincon, Hessian and extra parameters

From: Marco

Date: 22 Mar, 2010 16:35:05

Message: 3 of 7

Thanks, it works now!
Marco

"Steven Lord" <slord@mathworks.com> wrote in message <ho664c$rjl$1@fred.mathworks.com>...
>
> "Marco " <marinimar@gmail.com> wrote in message
> news:ho636m$g99$1@fred.mathworks.com...
> > Hi,
> > I got a problem with the definition of the Hessian used by the FMINCON
> > function.
> > I'm using the interior-point algorithm to solve a constrained nonlinear
> > problem.
> > I calculated the analytic expression of both gradient and Hessian, and
> > I'm passing both to FMINCON using the options ('GradObj','on') and
> > ('Hessian','user-supplied'). The Hessian function is a separate defined
> > function named @hessmgrp. It works, but I have a programming problem.
> >
> > My Hessian is a function of two vectors: the target vector and another
> > vector. The input arguments of the Hessian function are only two, the
> > target vector
> > and the Lagrange multipliers, that is
> >
> > function h = hessmgrp(y,lambda)
> >
> > Then, I have to pass the extra parameter to this function. I read the
> > optim toolbox manual and found different solutions. Eventually, the only
> > way I found is to define global variables and use them locally. It is not
> > the best solution, as remarked in the manual.
> >
> > Does anybody of you know how to pass extra parameters to
> > the Hessian function in a more appropriate way?
>
> Anonymous function. Specify your Hessian function as @(y, lambda)
> hessmgrp(y, lambda, whateverOtherParametersYouWant) [as long as
> whateverOtherParametersYouWant are defined before you create this anonymous
> function handle.]
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Subject: fmincon, Hessian and extra parameters

From: Manthos Vogiatzoglou

Date: 22 Mar, 2010 22:21:20

Message: 4 of 7

Steven thank you for the very helpfull comment. I have exactly the same problem as Marco, however my constraints are linear therefore in my case the hessian of the objective is the same as the hessian of the Lagrangian. Does this change anything? In my case how should I pass the hessian function to optimset? @(y)HessianFcn(y,[],myextraparameters) or @(y,lambda)HessianFcn(y,lambda,myextraparameters) or in another way?

Thanks again!!!

Subject: fmincon, Hessian and extra parameters

From: Fang

Date: 6 Nov, 2013 21:15:05

Message: 5 of 7

"Steven Lord" <slord@mathworks.com> wrote in message <ho664c$rjl$1@fred.mathworks.com>...
>
> "Marco " <marinimar@gmail.com> wrote in message
> news:ho636m$g99$1@fred.mathworks.com...
> > Hi,
> > I got a problem with the definition of the Hessian used by the FMINCON
> > function.
> > I'm using the interior-point algorithm to solve a constrained nonlinear
> > problem.
> > I calculated the analytic expression of both gradient and Hessian, and
> > I'm passing both to FMINCON using the options ('GradObj','on') and
> > ('Hessian','user-supplied'). The Hessian function is a separate defined
> > function named @hessmgrp. It works, but I have a programming problem.
> >
> > My Hessian is a function of two vectors: the target vector and another
> > vector. The input arguments of the Hessian function are only two, the
> > target vector
> > and the Lagrange multipliers, that is
> >
> > function h = hessmgrp(y,lambda)
> >
> > Then, I have to pass the extra parameter to this function. I read the
> > optim toolbox manual and found different solutions. Eventually, the only
> > way I found is to define global variables and use them locally. It is not
> > the best solution, as remarked in the manual.
> >
> > Does anybody of you know how to pass extra parameters to
> > the Hessian function in a more appropriate way?
>
> Anonymous function. Specify your Hessian function as @(y, lambda)
> hessmgrp(y, lambda, whateverOtherParametersYouWant) [as long as
> whateverOtherParametersYouWant are defined before you create this anonymous
> function handle.]
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

I tried this method, but I got an error message
Error Using
@(x, lambda)fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d)
Too many input arguments".

I have a function file:
function Hes=fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d)

And in my script:
hessinterior=@(x, lambda)fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d);
options = optimset('Algorithm','interior-point', 'GradObj','on', ...
        'Hessian', 'user-supplied', 'HessFcn', hessinterior, 'UseParallel', 'Always');
[x, fval] = fmincon(@fun_f,x0,[],[],[],[],lb,ub,[],options, k, RFA, iS_T1, iS_T2);
    
What is the problem? Anyone can help? Thank you very much.

Subject: fmincon, Hessian and extra parameters

From: Torsten

Date: 7 Nov, 2013 07:37:06

Message: 6 of 7

"Fang" wrote in message <l5ebgp$296$1@newscl01ah.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <ho664c$rjl$1@fred.mathworks.com>...
> >
> > "Marco " <marinimar@gmail.com> wrote in message
> > news:ho636m$g99$1@fred.mathworks.com...
> > > Hi,
> > > I got a problem with the definition of the Hessian used by the FMINCON
> > > function.
> > > I'm using the interior-point algorithm to solve a constrained nonlinear
> > > problem.
> > > I calculated the analytic expression of both gradient and Hessian, and
> > > I'm passing both to FMINCON using the options ('GradObj','on') and
> > > ('Hessian','user-supplied'). The Hessian function is a separate defined
> > > function named @hessmgrp. It works, but I have a programming problem.
> > >
> > > My Hessian is a function of two vectors: the target vector and another
> > > vector. The input arguments of the Hessian function are only two, the
> > > target vector
> > > and the Lagrange multipliers, that is
> > >
> > > function h = hessmgrp(y,lambda)
> > >
> > > Then, I have to pass the extra parameter to this function. I read the
> > > optim toolbox manual and found different solutions. Eventually, the only
> > > way I found is to define global variables and use them locally. It is not
> > > the best solution, as remarked in the manual.
> > >
> > > Does anybody of you know how to pass extra parameters to
> > > the Hessian function in a more appropriate way?
> >
> > Anonymous function. Specify your Hessian function as @(y, lambda)
> > hessmgrp(y, lambda, whateverOtherParametersYouWant) [as long as
> > whateverOtherParametersYouWant are defined before you create this anonymous
> > function handle.]
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
>
> I tried this method, but I got an error message
> Error Using
> @(x, lambda)fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d)
> Too many input arguments".
>
> I have a function file:
> function Hes=fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d)
>
> And in my script:
> hessinterior=@(x, lambda)fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d);
> options = optimset('Algorithm','interior-point', 'GradObj','on', ...
> 'Hessian', 'user-supplied', 'HessFcn', hessinterior, 'UseParallel', 'Always');
> [x, fval] = fmincon(@fun_f,x0,[],[],[],[],lb,ub,[],options, k, RFA, iS_T1, iS_T2);
>
> What is the problem? Anyone can help? Thank you very much.

The problem are the parameters k, RFA, iS_T1, iS_T2 in the call to fmincon.
You can't just add them to the usual calling list.

Best wishes
Torsten.

Subject: fmincon, Hessian and extra parameters

From: Fang

Date: 7 Nov, 2013 08:50:19

Message: 7 of 7

"Torsten" wrote in message <l5ffv2$1nh$1@newscl01ah.mathworks.com>...
> "Fang" wrote in message <l5ebgp$296$1@newscl01ah.mathworks.com>...
> > "Steven Lord" <slord@mathworks.com> wrote in message <ho664c$rjl$1@fred.mathworks.com>...
> > >
> > > "Marco " <marinimar@gmail.com> wrote in message
> > > news:ho636m$g99$1@fred.mathworks.com...
> > > > Hi,
> > > > I got a problem with the definition of the Hessian used by the FMINCON
> > > > function.
> > > > I'm using the interior-point algorithm to solve a constrained nonlinear
> > > > problem.
> > > > I calculated the analytic expression of both gradient and Hessian, and
> > > > I'm passing both to FMINCON using the options ('GradObj','on') and
> > > > ('Hessian','user-supplied'). The Hessian function is a separate defined
> > > > function named @hessmgrp. It works, but I have a programming problem.
> > > >
> > > > My Hessian is a function of two vectors: the target vector and another
> > > > vector. The input arguments of the Hessian function are only two, the
> > > > target vector
> > > > and the Lagrange multipliers, that is
> > > >
> > > > function h = hessmgrp(y,lambda)
> > > >
> > > > Then, I have to pass the extra parameter to this function. I read the
> > > > optim toolbox manual and found different solutions. Eventually, the only
> > > > way I found is to define global variables and use them locally. It is not
> > > > the best solution, as remarked in the manual.
> > > >
> > > > Does anybody of you know how to pass extra parameters to
> > > > the Hessian function in a more appropriate way?
> > >
> > > Anonymous function. Specify your Hessian function as @(y, lambda)
> > > hessmgrp(y, lambda, whateverOtherParametersYouWant) [as long as
> > > whateverOtherParametersYouWant are defined before you create this anonymous
> > > function handle.]
> > >
> > > --
> > > Steve Lord
> > > slord@mathworks.com
> > > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> > >
> >
> > I tried this method, but I got an error message
> > Error Using
> > @(x, lambda)fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d)
> > Too many input arguments".
> >
> > I have a function file:
> > function Hes=fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d)
> >
> > And in my script:
> > hessinterior=@(x, lambda)fun_hessian(x, lambda, k, S_T1, iS_T2, xy_h, xy_d);
> > options = optimset('Algorithm','interior-point', 'GradObj','on', ...
> > 'Hessian', 'user-supplied', 'HessFcn', hessinterior, 'UseParallel', 'Always');
> > [x, fval] = fmincon(@fun_f,x0,[],[],[],[],lb,ub,[],options, k, RFA, iS_T1, iS_T2);
> >
> > What is the problem? Anyone can help? Thank you very much.
>
> The problem are the parameters k, RFA, iS_T1, iS_T2 in the call to fmincon.
> You can't just add them to the usual calling list.
>
> Best wishes
> Torsten.

Yes, you are right. Thank you very much.

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