## 源码简介

% function [p,S,mu] = polyfitLU(x,y,n)

% The regression problem is formulated in matrix format as:
%
%    y = V*p    or
%
%          3  2
%    y = [x  x  x  1] [p3
%                      p2
%                      p1
%                      p0]
%
% where the vector p contains the coefficients to be found.  For a
% 7th order polynomial, matrix V would be:
%
% V = [x.^7 x.^6 x.^5 x.^4 x.^3 x.^2 x ones(size(x))];

n=5;
x=1:100;
y=x+10*rand(1,100);

if ~isequal(size(x),size(y))
error('MATLAB:polyfit:XYSizeMismatch',...
'X and Y vectors must be the same size.')
end

x = x(:);
y = y(:);

if nargout > 2
mu = [mean(x); std(x)];
x = (x - mu(1))/mu(2);
end

% Construct Vandermonde matrix.
V(:,n+1) = ones(length(x),1,class(x));
for j = n:-1:1
V(:,j) = x.*V(:,j+1);
end

% Solve least squares problem, and save the Cholesky factor.
[Q,R] = qr(V,0);
ws = warning('off','all');
p = R\(Q'*y);    % Same as p = V\y;
warning(ws);
if size(R,2) > size(R,1)
warning('MATLAB:polyfit:PolyNotUnique', ...
'Polynomial is not unique; degree >= number of data points.')
elseif condest(R) > 1.0e10
if nargout > 2
warning('MATLAB:polyfit:RepeatedPoints', ...
'Polynomial is badly conditioned. Remove repeated data points.')
else
warning('MATLAB:polyfit:RepeatedPointsOrRescale', ...
['Polynomial is badly conditioned. Remove repeated data points\n' ...
'         or try centering and scaling as described in HELP POLYFIT.'])
end
end
r = y - V*p;
p = p.';          % Polynomial coefficients are row vectors by convention.

% S is a structure containing three elements: the Cholesky factor of the
% Vandermonde matrix, the degrees of freedom and the norm of the residuals.

S.R = R;
S.df = length(y) - (n+1);
S.normr = norm(r);

## 本站长期招聘程序代写高手，欢迎加入华南地区matlab团队 想创业却没有经验的人 无论你是否有过网上开店的经验，都可以随时联系在线客服，建立自己独立的网站 想开网店却不知道如何入手 淘宝创业成本低而且风险小，如果想开淘宝店的朋友可以联系在线客服。 想兼职创业，却不擅长交际与服务的人 在家创业月入5000元。网站程序+百套群发工具+网赚资料+域名+空间+本站终身代理资格，这样你网赚的条件全具备了。每天3小时管理、推广、收钱。 缺乏能快速赢利型产品的人 导入多种最新流行营销软件+网赚教程，让入驻者轻松加盟、复制有效成交技巧、快速赚钱。

## 源码评论评论内容只代表网友观点，与本站立场无关！

评论摘要(共 0 条，得分 0 分，平均 0 分) 查看完整评论

## 浏览说明

* 本站所有源码全部公开，随时随地浏览!
* MATLAB软件如用于商业用途，请购买正版!
* 如果您发现下载链接错误，请点击报告错误谢谢！
* 站内提供的所有软件包含破解及注册码均是由网上搜集，若侵犯了你的版权利益，敬请来信通知我们!