REDUCE

17.8 General Curve Fitting

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.

Example:


     % approximate a set of factorials by a polynomial
    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.5714285714*x  - 61.4285714286*x + 54.6,{54.6,

         - 61.4285714286,14.5714285714}}

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

    {2.20833333343*x  - 20.2500000011*x

      + 67.7916666713*x  - 93.7500000077*x

      + 45.0000000042,

     {45.0000000042, - 93.7500000077,67.7916666713,

      - 20.2500000011,2.20833333343}}


Hosted by Download REDUCE Powered by MathJax