下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、关于polyfit 函数使用介绍文章来源:不详 作者:佚名 -该文章讲述了关于polyfit 函数使用介绍. polyfit函数的使用 MATLAB软件提供了基本的曲线拟合函数的命令 多项式函数拟合:P=polyfit(x,y,n) 其中n表示多项式的最高阶数,x,y为将要拟合的数据,它是用数组的方式输入输出参数P为拟合多项式 P(1)*XN + P(2)*X(N-1) +.+ P(N)*X + P(N+1).的系数 多项式在x处的值y可用下面程序计算 y=polyval(P,x,m) 线性:m=1, 二次:m=2, polyfit的输出是一个多项式系数的行向量。为了计算在xi数据点的多项式值
2、,调用MATLAB的函数polyval。 例: x=0:0.1:1; y=-0.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2; A=polyfit(x,y,2) Z=polyval(A,x); Plot(x,y,r*,x,z,b) polyfit不能保证你每次都能得到最优解,math的答案是使用数值计算。个人认为,对于这种非线性的曲线,尽量不要使用ployfit, ployfit多项式抑合适合线性方程! 用polyfit()函数去拟合这么复杂的曲线不太合适,polyfit()函数对于数据遵循多项式分布是比较好的,一般来说,利用po
3、lyfit()函数拟合的阶数不要超过5阶。如果是不需要得到拟合曲线的函数,只是把这些点利用一些光滑曲线连接,建议使用三次样条函数spline()进行插值即可。帮助: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 c
4、oefficients in descending powers, P(1)*XN + 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 Van
5、dermonde 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)*normr2/df, where Rinv is the inverse of R. P,S,MU = POLYFIT(X,Y,N) finds the coefficients of a polynomial in XHAT = (X-MU(1)/MU
6、(2) where MU(1) = MEAN(X) and MU(2) = STD(X). This centering and scaling transformation improves the numerical properties of both the polynomial and the fitting algorithm. Warning messages result if N is = length(X), if X has repeated, or nearly repeated, points, or if X might need centering and sca
7、ling. Class support for inputs X,Y: float: double, singlepolyfit.m 在MATLAB安装目录下 toolboxmatlabpolyfunfunction 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
8、% row vector of length N+1 containing the polynomial coefficients in% descending powers, P(1)*XN + 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 th
9、e 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)*normr2/df,% where Rinv is the inverse of R.% P,S,MU = POLYFIT(X,Y,
10、N) finds the coefficients of a polynomial in% XHAT = (X-MU(1)/MU(2) where MU(1) = MEAN(X) and MU(2) = STD(X). This% centering and scaling transformation improves the numerical properties% of both the polynomial and the fitting algorithm.% Warning messages result if N is = length(X), if X has repeate
11、d, or% nearly repeated, points, or if X might need centering and scaling.% Class support for inputs X,Y:% float: double, single% See also POLY, POLYVAL, ROOTS.% Copyright 1984-2004 The MathWorks, Inc.% $Revision: 5.17.4.5 $ $Date: 2004/07/05 17:01:37 $% The regression problem is formulated in matrix
12、 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);if isequal(size(x),size(y) error(MATLAB:polyfit:XYSizeMismatch,. X and Y vectors must be the
13、 same size.)endx = 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.Q,R = qr(V,0);ws = warning(off,all); p = R(Q*y); % Same as p = Vy;warni
14、ng(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 pointsn . or try centering and scaling as described in HELP POLYFIT.) endendr = y - V*p;p = p.; % Polynomial coefficients are row vectors by convention.% S is a structu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026 年高职音乐教育(音乐教学实践)试题及答案
- 2026 年高职移动通信技术(5G 技术应用)试题及答案
- 无性生殖课件-人教版生物八年级下册-1
- 手机通信合作协议书
- 安全组工作助理培训计划课件
- 水产养殖潜水工测试验证竞赛考核试卷含答案
- 听觉口语师岗后强化考核试卷含答案
- 微生物农药生产工岗前面试考核试卷含答案
- 未来五年塔吊企业数字化转型与智慧升级战略分析研究报告
- 未来五年研发和技术服务企业数字化转型与智慧升级战略分析研究报告
- 手术室护理中精细化管理的应用与手术安全及护理质量保障研究答辩
- 第四章 对数与对数函数(原卷版及全解全析)
- TCABEE《零碳办公建筑评价标准》
- JJG(交通) 070-2006 混凝土超声检测仪
- 2025新加坡教育服务(私立教育)行业市场现状供需分析及投资评估规划分析研究报告
- 合作销售矿石协议书
- 年终档案管理总结
- 2025上海初三各区一模、二模作文题、主题归纳及审题分析指导
- 2025-2026学年苏教版(2024)小学科学二年级上册期末测试卷附答案(共三套)
- 城市生命线安全工程建设项目可行性研究报告
- 基于小波分析与神经网络融合的船舶同步发电机智能诊断体系研究
评论
0/150
提交评论