[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Aux. functions with multiple outputs

From: Mike B.
Subject: Re: Aux. functions with multiple outputs
Date: Tue, 14 Sep 2010 18:47:02 -0700 (PDT)

Thanks everyone for replying.

Here is a specific example:
I have a function which returns the objective value and gradient at x. I want to pass both (objective + gradient) to SQP.

simple example:
function [ f, g ] = myf( x )
f = x^2;
g = 2*x;

to use only the objective value (f) I've defined
auxf = @(x) myf( x );
[ x1, f1 ] = sqp( 0, auxf );

now I want to pass to sqp also the gradient (as a third argument).
Any ideas how to do this? (ideally without defining another aux. function which outputs g only).


--- On Sat, 11/9/10, Judd Storrs <address@hidden> wrote:

From: Judd Storrs <address@hidden>
Subject: Re: Aux. functions with multiple outputs
To: address@hidden
Cc: "Francesco Potortì" <address@hidden>, "Octave mai. lis." <address@hidden>
Date: Saturday, 11 September, 2010, 12:08 AM

On Fri, Sep 10, 2010 at 6:22 AM, Mike B. <address@hidden> wrote:
Thanks for replying.
How do I refer to each of the outputs (a and b in the example)?.

I think you might be asking how do I write something like this as an inline function?

function b = myfunc(x)
     [a,b] = somefunc(x) ;

Unfortunately, short of making a wrapper function, I don't know. I think the wrapper function could look something like:

function b = secondout(func, varargin)
    # use [~,b] instead of [a,b] in the development version of octave
    [a,b] = feval(func, varargin{:}) ; 

Then maybe something like:

y = @(x) secondout(@f1, x);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]