MATLAB的拟合函数polyfit 的程序代码是什么啊

来源:百度知道 编辑:UC知道 时间:2024/06/13 03:33:39

polyfit.m 在MATLAB安装目录下 \toolbox\matlab\polyfun

function [p,S,mu] = polyfit(x,y,n)
%POLYFIT Fit polynomial to data.
% P = POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of
% degree N that fits the data Y best in a least-squares sense. P is a
% row vector of length N+1 containing the polynomial coefficients in
% descending powers, P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1).
%
% [P,S] = POLYFIT(X,Y,N) returns the polynomial coefficients P and a
% structure S for use with POLYVAL to obtain error estimates for
% predictions. S contains fields for the triangular factor (R) from a QR
% decomposition of the Vandermonde matrix of X, the degrees of freedom
% (df), and the norm of the residuals (normr). If the data Y are random,
% an estimate of the covariance matrix of P is (Rinv*Rinv')*normr^2/df,
% where Rinv is the inverse of R.
%
% [P,S,MU] = POLYF