Linfit

Linear regression. Attempt to find best fit y=ax+b function given multiple x/y points.

Description

Linfit( Float:x[], Float:y[], points, &Float:a, &Float:b )

Find the best fitting y=ax+b function using least-square method.

Parameters

x[] Array of x-values
y[] Array of y-values
points Size of the x and y arrays (number of points)
a The variable to receive the a (slope) value
b The variable to receive the b (offset) value

Return value

Returns 1 if successful. 0 otherwise (if less than 2 x/y points given).

Example usage

 
   new Float:x[10], Float:y[10];
   new Float:a, Float:b;
 
   // assign 10 points to x/y
 
   Linfit(x, y, 10, a, b);
 
   // a and b now holds the calculated slope/offset values