In the following script a SCAN, named RND, is created and filled with random numbers. The SCAN is copied to LR which is replaced by a linear regression of the data. The result is displayed, see below.
#!/usr/bin/perl -w
use Spectra;
use GQE;
use strict;
#
# delete everything
#
Spectra::delete();
#
# create the arrays
#
my @x_arr = ( 0 .. 100);
my @y_arr = ( 0 .. 100);
#
# fill the arrays
#
foreach my $x (@x_arr)
{
$x = $x/10;
}
foreach my $y (@y_arr)
{
$y = 10 + $y + Spectra::random()*10;
}
#
# create the SCAN
#
my $rnd = SCAN->create( name => "Rnd",
title => "Rnd",
x_ptr => \@x_arr,
y_ptr => \@y_arr,
colour => "red") or
die " Failed to create Rnd ";
my $lr = SCAN->copy( from => $rnd,
to => "LR");
$lr->linearRegression();
Spectra::autoscale();
Spectra::display();
Spectra::gra_input();