473,785 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_st ruct
{
double (* function) (double x, void * params);
void * params;
};

typedef struct gsl_function_st ruct gsl_function ;

#define GSL_FN_EVAL(F,x ) (*((F)->function))(x,( F)->params)

and the usage is here:
http://www.gnu.org/software/gsl/manu...ction-to-solve

I wonder how one does it in C++?

Thanks.

Jul 21 '06 #1
2 2468
da*******@gmail .com wrote:
Hi, I would like to know how to define a arbitrary mathematical
double (* function) (double x, void * params);
http://www.gnu.org/software/gsl/manu...ction-to-solve
I wonder how one does it in C++?
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.

Jul 21 '06 #2
da*******@gmail .com wrote:
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_st ruct
{
double (* function) (double x, void * params);
void * params;
};

typedef struct gsl_function_st ruct gsl_function ;

#define GSL_FN_EVAL(F,x ) (*((F)->function))(x,( F)->params)

and the usage is here:
http://www.gnu.org/software/gsl/manu...ction-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

Jul 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3697
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
9
2068
by: Andrew | last post by:
It seems that in C#, given an instance "a" of some value type "A", one can pass a by reference to functions with signatures of either "void f(object obj)" or "void g(ref A obj)". But passing a into a function with signature "void f(ref object obj)" gives a compile error -- why (This is part of solving the original problem posed here: http://www.csharp-station.com/ShowPost.aspx?PostID=3625 What I need now is a method that accepts a ref to an...
5
2963
by: Honestmath | last post by:
Hello everyone, I'm using a root finding algorithm in a function that only takes as arguments a function pointer and two variables that represent guesses at the roots of the function. int zbrac(float (*func)(float), float *x1, float *x2) { float f1,f2; f1=(*func)(*x1);
8
3193
by: Steve Neill | last post by:
Can anyone suggest how to create an arbitrary object at runtime WITHOUT using the deprecated eval() function. The eval() method works ok (see below), but is not ideal. function Client() { } Client.prototype.fullname = "John Smith"; var s = "Client"; eval("var o = new " + s + "();"); alert(o.fullname);
12
2872
by: Chadwick Boggs | last post by:
I need to perform modulo operations on extremely large numbers. The % operator is giving me number out of range errors and the mod(x, y) function simply seems to return the wrong results. Also, my numerator is in the format of a quoted string, which the mod function can't take. Desparately searching for solutions, Chadwick. ---------------------------(end of broadcast)---------------------------
5
1454
by: Steven D'Aprano | last post by:
I have a problem and I don't know where to start looking for a solution. I have a class that needs to call an arbitrary function and wait for a result. The function, being completely arbitrary and not under my control, may be very time consuming and possibly may not even halt. My class needs to be able to give up waiting for a result after a specified amount of time. I'm thinking something conceptually like this:
3
1470
by: Curtis | last post by:
Hello everyone: Recently, I've come across the need to accept an arbitrary amount of arguments in my function, but I also need to alter the data in the calling scope. I have been trying to toy around with the func_get_args function, however, it seems the data is copied before I can access it, as I tried to globalize the values in the argument array and use references, but neither worked.
2
1693
by: John O'Hagan | last post by:
Hi Pythonistas, I'm looking for the best way to pass an arbitrary number and type of variables created by one function to another. They can't be global because they may have different values each time they are used in the second function. So far I'm trying to do something like this: def process_args( ):
0
1107
by: John O'Hagan | last post by:
On Tue Sep 30 11:32:41 CEST 2008, Steven D'Aprano Thanks, both to you and Bruno for pointing this out, I'll certainly be using it in future.
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.