Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: [Mata] passing a function to mata


From   Antoine Terracol <[email protected]>
To   [email protected]
Subject   st: [Mata] passing a function to mata
Date   Thu, 25 Aug 2005 17:32:33 +0200

Dear _all

I'm trying to write mata code to evaluate integrals |f(x)g(x) (where g(x)is the standard normal pdf) by Gauss-Hermite quadrature (I know this has been done before in Stata, but I'm trying to learn mata, so I thought I might give it a try).

I was able to code for the nodes and weight vectors, but I can't figure out how to tell mata which fuction f(x) I wish to evaluate.

I want to be able to specify the f(x) function, say x^2, when calling the mata program

Here is a sketch of the code :


___________________________________________
void gaussher(scalar node, funct){

[compute nodes (x) and weight (w) vectors]

x=x:*sqrt(2)
s=w:/sqrt(pi()):*(funct)

[return stuff]
}
end
____________________________________________



If I type -gaussher(12 , x:^2)-

mata complains that "x not found"

but if I type -gaussher(12 , "x:^2")-

mata complains that "nonnumeric found where numeric required"


Could anyone point me to the correct way of passing such arguments to a mata program ?

Best,
Antoine

--
Ce message a �t� v�rifi� par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a �t� trouv�.

*
* 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/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index