SVDFIT Function
Standard Library function that uses the singular value decomposition method of least-squares curve fitting to fit a polynomial function to data.
Usage
result = SVDFIT(x, y, m)
Input Parameters
x—A vector containing the independent x-coordinates of the data.
y—A vector containing the dependent y-coordinates of the data. This vector should have the same number of elements as x.
m—The number of coefficients in the fitted function. For polynomials, m is one more than the degree of the polynomial.
Returned Value
result—A vector containing the coefficients of the polynomial equation which best approximates the data. It has a length of m.
Keywords
Chisq—The sum of the squared errors, multiplied by the weights, if Weight is specified.
Covar—The covariance matrix of the m coefficients.
Funct—The name of a user-supplied basis function with m coefficients (see User-Supplied Basis Function).
Singular —The number of singular values (i.e., the number of values that are inconsistent with the other data) encountered in evaluating the fit. Should be 0; if not, the computed polynomials probably do not accurately reflect the data.
Variance—The estimated variance (sigma squared) for each of the m coefficients.
Weight—A vector of weighting factors for determining the weighting of the least-squares fit. Must have the same number of elements as x.
Yfit—A vector containing the calculated y values of the fitted function.
Discussion
You must define any keywords to be returned by SVDFIT before calling it. The value or structure of the variable doesn’t matter, since the variable will be redefined dynamically in the function call. For example:
; Define the output variable yf.
yf = 1
; Do the SVD fit and return the Yfit vector in the variable yf.
c = SVDFIT(x, y, m, Yfit=yf)
User-Supplied Basis Function
If Funct is not supplied, a polynomial function is used as the basis function. This function is of the form:
result(i, j) = x(i) j
The function is called with two parameters in the following fashion:
result = FUNCT(x, m)
where x and m are as defined above.
The file containing Funct should reside in the current working directory or in the search path defined by the system variable !Path.
If Funct does not have the file extension .pro, it should be compiled before it is called in SVDFIT.
See the Standard Library function cosines.pro, which defines a basis function of the form:
result(i, j) = COS(j * x(i))
Weighting is useful when you want to correct for potential errors in the data you are fitting to a curve. The weighting factor, Weight, adjusts the parameters of the curve so that the error at each point of the curve is minimized. For more information, see the section CURVEFIT Function under the CURVEFIT function in Volume 1 of this reference.
See Also
For more examples of basis functions, see Numerical Recipes in C: The Art of Scientific Computing, by Flannery, Press, Teukolsky, and Vetterling, Cambridge University Press, Cambridge, MA, 1988.