The Statistics library contains the Fit() command. This command performs linear or non-linear fits. The syntax is simple:
With( Statistics );
p := Fit( m * t + b, X, Y, t );
f := unapply( p , t );
In the Fit() call, the first argument is the function to fit. X and Y are Maple vectors containing the data points. The variable t identifies the function independent variable. Fit() identifies and finds the value of the parameters in the fitting function, m and b in the example above, that best fit the data set.
Fit() returns the fitted function as a character string. A simple call to unapply() makes a Maple function out of the fitted function.
Maple creates Maple vectors (see help) from lists via the syntax
X := Vector([1, 2, 3, 4, 5, 6], datatype = float );
y := Vector([2.0, 3.0, 4.5, 10.2, 15.6, 30.8], data type = float );
This is very closely related to arrays. The latter are formed when data points are read in via readdata(). The data points must be transferred from array to vectors.This is easy.
L := readdata ( data_xy.dat, float, 2 );
N := nops(L);
X : Vector( L[k] $1k=1...N], datatype = float );
Y : Vector( L[k] $1k=1...N], datatype = float );
Any questions or suggestions should be directed to
Michel Vallières at vallieres@drexel.edu