From 839054da4b57efed09a7d12bb13938de470c323a Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Fri, 25 Jul 2008 12:22:15 -0400 Subject: [PATCH] Adding an example to the Fit documentation --- Fit.i | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Fit.i b/Fit.i index afe8894..0a4fccf 100644 --- a/Fit.i +++ b/Fit.i @@ -62,6 +62,36 @@ Here is a list of all the functions in this module : =head1 EXAMPLES +This example shows how to use the function gsl_fit_linear. It's important to see that the array passed to to function must be an array reference, not a simple array. Also when you use strides, you need to initialize all the value in the range used, unless you will get warnings. + + my @norris_x = (0.2, 337.4, 118.2, 884.6, 10.1, 226.5, 666.3, 996.3, + 448.6, 777.0, 558.2, 0.4, 0.6, 775.5, 666.9, 338.0, + 447.5, 11.6, 556.0, 228.1, 995.8, 887.6, 120.2, 0.3, + 0.3, 556.8, 339.1, 887.2, 999.0, 779.0, 11.1, 118.3, + 229.2, 669.1, 448.9, 0.5 ) ; + my @norris_y = ( 0.1, 338.8, 118.1, 888.0, 9.2, 228.1, 668.5, 998.5, + 449.1, 778.9, 559.2, 0.3, 0.1, 778.1, 668.8, 339.3, + 448.9, 10.8, 557.7, 228.3, 998.0, 888.8, 119.6, 0.3, + 0.6, 557.6, 339.3, 888.0, 998.5, 778.9, 10.2, 117.6, + 228.9, 668.4, 449.2, 0.2); + my $xstride = 2; + my $wstride = 3; + my $ystride = 5; + my ($x, $w, $y); + for my $i (0 .. 175) + { + $x->[$i] = 0; + $w->[$i] = 0; + $y->[$i] = 0; + } + + for my $i (0 .. 35) + { + $x->[$i*$xstride] = $norris_x[$i]; + $w->[$i*$wstride] = 1.0; + $y->[$i*$ystride] = $norris_y[$i]; + } + my ($status, @results) = gsl_fit_linear($x, $xstride, $y, $ystride, 36); =head1 AUTHOR -- 2.11.4.GIT