[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: mata: passing additional arguments to functions passed to functions
> I've been working on a mata function, called qnewsolve, which finds
> to nonlinear equations f using a quasi-newton's method.
I'd be interested in that. Please make it public once you're done.
> I'd like to
> also be able to pass additional arguments to f.How do I do this?
One solution would be to pass a pointer vector. Note that this requires
that f() knows what to do with the pointer vector. Example:
numeric matrix qnewsolve(..., pointer vector opt)
f0 = (*f)(x, opt)
where in f() the options are then used as *opt, *opt, etc. and you
could call qnewsolve() as
: s = qnewsolve(&f(), x, (&a1, &a2, ...))
See -help m2_pointers-
A related approach would be to use structures but I don't really see the
advantage of using structures in this situation.
> Also, is there an easy way to return x and rc separately instead of
> tacking rc to the end of x?
Yes. Use structures. See -help m2_struct-.
* For searches and help try: