H
Honestmath
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);
f2=(*func)(*x2);
// other stuff here
}
Problem is, I'm not sure how to pass parameters to the root finding function.
For example, if I have an Nth-order polynomial, I could have loads of different
coefficients, but obviously the coefficients will change from function to
function.
I don't want to use global variables, but figured there was a way to modify the
above root-finder to accept and then pass a variable number of parameters to
the polynomial (or whatever) function.
How would I do this? Or, is there a better way?
Thanks!
Math
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);
f2=(*func)(*x2);
// other stuff here
}
Problem is, I'm not sure how to pass parameters to the root finding function.
For example, if I have an Nth-order polynomial, I could have loads of different
coefficients, but obviously the coefficients will change from function to
function.
I don't want to use global variables, but figured there was a way to modify the
above root-finder to accept and then pass a variable number of parameters to
the polynomial (or whatever) function.
How would I do this? Or, is there a better way?
Thanks!
Math