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){
grad = ((*f)(x*J(1,nv,1)+tvec)-(f0)*(J(1,nv,1)))/delta
/*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
enough, please let me know.--Matt
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/