Re: Curve fitting (was Re: Python Plugins)



On Fri, May 17, 2002 at 11:54:22AM -0400, Daniel Carrera wrote:
I want to use LU-decomposition.
We've got lu decomposition routines in place.

Excellent!  Where can I find them?

I looked in 'gnumeric-1.0.6/src/functions/fn-math.c' and couldn't find
it.

The next thing I need is a routine for approximating partial derivatives.

The main thing here is to figure out how to pass a user-defined function
to the derivative function.  I don't use C very much.  Maybe this is
really easy and I just don't know it).


In pseudo-code, the derivative would just be something like this:

/* 'f' is some sort of pointer to a user-defined function.
 *
 * 'parameters' are the values at which the function is evaluated at.
 *
 * E.g.
 * Take   f(x; a, b, c) = a*sin(b*x + c)
 *
 * Here (x,a,b,c) are the parameters I'm talking about.
 *
 * I would be interested in, for instance, df/da
 * evaluated at (x,a,b,c).
 *
 * 'index' is the index of the parameter to differentiate with
 * respect to.  In this case, 'a' is parameter 1 (x is parameter 0).
 */

double
diff(function f, double[] parameters, int index)
{
        double[] x,dx;

        x = parameters;
        dx = x;
        dx[index] += MACHINE_EPSILON;

        return (f(dx) - f(x))/MACHINE_EPSILON;
}


Cheers,
Daniel.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]