"Olw" <an***********@kommtek.comwrote in message

news:45******@news.broadpark.no...

Clever Monkey wrote:
>Olw wrote:

>>Does anyone have a nice link to some code for calculating the gradient

of a function in C?

Google knows all. I bet "Numerical Recipes in C" might also be a safe

bet for a start, but it is not handy at the moment.

Well, as far as I can see Numerical Recipes in C asks you to write the

command yourself (dfunc?). Also, googling does not seem to yield any

immediate answers.

This should be such a common task, that I bet some C users out there has

some nice code to share? Anyone ;)

Thanks,

Olw

If you know your function, you should be able to determine its gradient.

For example, if

f(x,y,z) = 2*x + 3*y**2 -sin(z)

then the gradient is the vector

( 2, 6*y, -cos(z) )

If you only have a bunch of points and do not explicitly know

the function, you have to decide how you are going to compute

the gradient. You have to decide how to create the approximation

of the data fit - linear, piecewise linear, least squares, polynomial,

cubic spline, quaternary spline, piecewise continuous multivariate

spline interpolation, ... there are literally an infinite number of

ways you could choose to fit the data. But YOU have to choose.

Check the Linpack, Mathlib, etc., libraries for some possibilities.

--

Fred L. Kleinschmidt

Boeing Associate Technical Fellow

Technical Architect, Software Reuse Project