num_fit INDEX

NUM_FIT _ _ _ _ _ _ _ _ _ _ _ _ operator

The operator num_fit finds for a set of points the linear combination of a given set of functions (function basis) which approximates the points best under the objective of the least squares criterion (minimum of the sum of the squares of the deviation). The solution is found as zero of the gradient vector of the sum of squared errors.

syntax:

num_fit(<vals>,<basis>,<var>=<pts>)

where <vals> is a list of numeric values, <var> is a variable used for the approximation, <pts> is a list of coordinate values which correspond to <var>, <basis> is a set of functions varying in var which is used for the approximation.

The result is a list containing as first element the function which approximates the given values, and as second element a list of coefficients which were used to build this function from the basis.

examples:


 
pts:=for i:=1 step 1 until 5 collect i$

vals:=for i:=1 step 1 until 5 collect

            for j:=1:i product j$

num_fit(vals,{1,x,x**2},x=pts);

                     2
      {14.571428571*X   - 61.428571429*X + 54.6,{54.6,
           - 61.428571429,14.571428571}}