|
|
|
|
|
|
| Author |
Message |
mlimber *nix forums Guru
Joined: 06 Sep 2005
Posts: 1249
|
Posted: Fri Jul 21, 2006 12:28 pm Post subject:
Re: Arbitrary function with parameter
|
|
|
darknails@gmail.com wrote:
| Quote: | Hi, I would like to know how to define a arbitrary mathematical
function with one variable and a list of paramter, like, f(x). For
example, in GSL library this is done as
/* Definition of an arbitrary function with parameters */
struct gsl_function_struct
{
double (* function) (double x, void * params);
void * params;
};
typedef struct gsl_function_struct gsl_function ;
#define GSL_FN_EVAL(F,x) (*((F)->function))(x,(F)->params)
and the usage is here:
http://www.gnu.org/software/gsl/manual/html_node/Providing-the-function-to-solve.html#Providing-the-function-to-solve
I wonder how one does it in C++?
|
In C++, one would use a functor. See this for a description:
http://www.sgi.com/tech/stl/functors.html
See especially the example involving struct less_mag.
Cheers! --M |
|
| Back to top |
|
 |
joosteto@gmail.com *nix forums beginner
Joined: 09 Jul 2006
Posts: 20
|
Posted: Fri Jul 21, 2006 10:59 am Post subject:
Re: Arbitrary function with parameter
|
|
|
darknails@gmail.com wrote:
If you're using gnu stuff anyway, "man stdarg" should do the trick (has
an example).
googling should tell you how to use it on different systems too. |
|
| Back to top |
|
 |
darknails@gmail.com *nix forums beginner
Joined: 21 Jul 2006
Posts: 1
|
Posted: Fri Jul 21, 2006 9:58 am Post subject:
Arbitrary function with parameter
|
|
|
Hi, I would like to know how to define a arbitrary mathematical
function with one variable and a list of paramter, like, f(x). For
example, in GSL library this is done as
/* Definition of an arbitrary function with parameters */
struct gsl_function_struct
{
double (* function) (double x, void * params);
void * params;
};
typedef struct gsl_function_struct gsl_function ;
#define GSL_FN_EVAL(F,x) (*((F)->function))(x,(F)->params)
and the usage is here:
http://www.gnu.org/software/gsl/manual/html_node/Providing-the-function-to-solve.html#Providing-the-function-to-solve
I wonder how one does it in C++?
Thanks. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Dec 04, 2008 6:54 am | All times are GMT
|
|
Mortgage | Libros recomendados | Credit Cards | Loans | Loans
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|