NR Validation?


meyerx
12-16-2008, 10:50 AM
Hello NR,

We're currently using Numerical Recipes in C within our product's
implementation (with permission). We've been forced to isolate the
used recipes and show proof that they provide correct results through
some sort of validation (specifically svdfit).
I just stumbled across an old copy of the Numerical Recipes in C Example
Book. For svdfit, with a given set of generated input data the expected results are
described as:
a[i] approximately equal to i
and for Legendre polynomials
a[1] approximately equal to 3.0
a[2] approximately equal to 4.4
a[3] approximately equal to 4.9
a[4] approximately equal to 1.6
a[5] approximately equal to 1.1

Even though "approximately equal to" may be interpreted as vague, we were
hoping to possibly leverage this data set for at least a part of the validation.
NR, do you know how these results were determined to be correct?

Thanks,
Alex

Saul Teukolsky
12-16-2008, 06:48 PM
Dear Alex,

The function that is fit is
1 + 2x + 3x^2 + 4x^3 +5x^4
This is equal to
3P_0(x) + 22/5 P_1(x) + 34/7 P_2(x) + 8/5 P_3(x) + 8/7 P_4(x)

Saul Teukolsky

meyerx
12-17-2008, 10:29 AM
Without Gaussian noise in the data set, the expected outcome
falls into the bounds given by the book:

polynomial fit:
1.000000 +- 0.017224
2.000001 +- 0.231274
2.999995 +- 0.817602
4.000005 +- 0.966313
5.000000 +- 0.343227

With Gaussian noise in the data set (as the text suggests), the output
doesn't seem to match the expected results as defined by the book:

polynomial fit:
1.033055 +- 0.017488
1.740046 +- 0.232731
3.703167 +- 0.820020
3.069303 +- 0.967989
5.389239 +- 0.343813

Saul Teukolsky
12-18-2008, 11:02 AM
The results look fine to me - within one or two standard deviations. If you compute the chi squared you'll get around 100, the number of degrees of freedom (which is actually 100 - 5 = 95 in this case). This shows the goodness of fit is fine. See the discussion in the book.

Saul Teukolsky