    # st: mata: passing additional arguments to functions passed to functions

 From Matt To statalist@hsphsun2.harvard.edu Subject st: mata: passing additional arguments to functions passed to functions Date Wed, 7 Jun 2006 17:44:05 -0400

```Hi all,
I've been working on a mata function, called qnewsolve, which finds roots
to nonlinear equations f using a quasi-newton's method.  I'd like to
also be able to pass additional arguments to f.How do I do this?

To be more precise, the structure of my function is below.
I'd like to be able to give qnewsolve additional arguments a1,
a2,..,an,which will then be passed to f.

numeric matrix qnewsolve(pointer matrix f, numeric matrix x, real
scalar crit, real scalar itmax,real matrix a1,real matrix a2,...,real
matrix an)
{
delta=1e-6
alpha=1e-3
nv=max((rows(x),cols(x)))
tvec=delta*I(nv)
done=0
f0=(*f)(x) /* HERE I WANT TO ALSO GIVE f a1,a2,...,an*/
af0=colsum(abs(f0))
af00=af0
itct=0
while(!done){
/*HERE TOO*/

/*a bunch of
operations...*/

if(itct>=itmax) {
done=1
rc=4
}
else if(af0<crit) {
done=1
rc=0
}
}
return(x\rc)
}
end
Also, is there an easy way to return x and rc separately instead of
tacking rc to the end of x?

Thanks for helping me figure this out!  If I'm not being clear