曲线拟合

已知离散点上的数据集

,即已知在点集

上的函数值

,构造一个解析函数(其图形为一曲线)使

在原离散点

上尽可能接近给定的

值,这一过程称为曲线拟合。最常用的曲线拟合方法是最小二乘法,该方法是寻找函数

使得

最小。

MATLAB函数:p=polyfit(x,y,n)

[p,s]=

polyfit(x,y,n)

说明:x,y为数据点,n为多项式阶数,返回p为幂次从高到低的多项式系数向量p。x必须是单调的。矩阵s用于生成预测值的误差估计。(见下一函数polyval)

多项式曲线求值函数:polyval( )

调用格式: y=polyval(p,x)

[y,DELTA]=polyval(p,x,s)

说明:y=polyval(p,x)为返回对应自变量x在给定系数P的多项式的值。

[y,DELTA]=polyval(p,x,s) 使用polyfit函数的选项输出s得出误差估计Y

DELTA。它假设polyfit函数数据输入的误差是独立正态的,并且方差为常数。则Y DELTA将至少包含50%的预测值。

=========================

练习:如下给定数据的拟合曲线,x=[0.5,1.0,1.5,2.0,2.5,3.0],

y=[1.75,2.45,3.81,4.80,7.00,8.60]。

解:MATLAB程序如下:

x=[0.5,1.0,1.5,2.0,2.5,3.0];

y=[1.75,2.45,3.81,4.80,7.00,8.60];

p=polyfit(x,y,2)

x1=0.5:0.05:3.0;

y1=polyval(p,x1);

plot(x,y,'*r',x1,y1,'-b')

计算结果为:

p =0.5614 0.8287

1.1560

即所得多项式为y=0.5614x^2+0.8287x+1.15560

另:matlab

polyval与polyvalm的区别是什么?

在坛子里发个网址真费劲,感谢原帖的几位大侠。

http://www.ilovematlab.cn/viewthread.php?tid=2538

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

polyval 只是计算一个多项式,这个你应该明白吧,help里的例子很清楚:

就是把x值带进去。

polyvalm比较特别的。但是明白这个之前,你需要明白什么是 characteristic

polynomial:

In linear algebra, one associates

a polynomial to

every square matrix,

its characteristic

polynomial. This polynomial encodes several important

properties of the matrix, most notably

its eigenvalues,

its determinant and

its trace.

Suppose we want to compute the characteristic polynomial of the

matrix

 We

have to compute the determinant of

 and

this determinant is

 The

latter is the characteristic polynomial

of A.

现在回到我们自己的问题, 对于Y = polyvalm(p,X), 他的计算方法是:

Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1)*I

如果写出for循环是:

for i = 1:np %多项式长度,m是X的维数

Y = X * Y +

diag(p(i) * ones(m,1));

end

这个循环比较简单,不要我解释吧?

举个例子给你看,我把循环拆开:

复制内容到剪贴板代码:

p=[1 2 3]

X=[1 2; 3 4]

np = length(p);

[m,n] = size(X);

Y = zeros(m,m)

i = 1

Y = X * Y +

diag(p(i) * ones(m,1))

i = 2

Y = X * Y +

diag(p(i) * ones(m,1))

i = 3

Y = X * Y +

diag(p(i) * ones(m,1))

你再运行:

p=[1 2 3]

X=[1 2; 3 4]

polyvalm(p,X)

(By

math)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

总结一下:

polyval(p, t)是计算出来:

p(1)*t^n + p(2)*t^(n-1) + .... + p(n)

polyvalm(p, X)是计算出来:

p(1)*X^n + p(2)*X^(n-1) + .... + p(n)*I

这里要注意最后的I就是单位阵,不要忘了,否则会出错,比如:

>> p=[1 2 3];

>> X=[1 2; 3 4];

>> polyvalm(p, X)

ans =

12 14

21 33

>> p(1)*X*X+p(2)*X+p(3)

ans =

12 17

24 33

>> p(1)*X*X+p(2)*X+p(3)*eye(2,

2)

ans =

12 14

21 33

===============================

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] =

POLYFIT(X,Y,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

repeated, or

nearly

repeated, points, or if X might need centering and scaling.

Class

support for inputs X,Y:

float: double, single

给个例子。

clc;clear

x=-1:0.1:1

for k=1:length(x)

y(k)=x(k)^2+0.1*rand

end

[p,s]=polyfit(x,y,2)

s.R

plot(x,y,'o',x,polyval(p,x))

结果:

p =

1.0072 0.0091 0.0439

s =

R: [3x3 double]

df: 18

normr: 0.1153

ans =

-2.2509 -0.0000 -3.4208

0 2.7749 0.0000

0 0 -3.0492

s是个结构数组。

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)【范数】.

matlab曲线拟合 新浪,Matlab曲线拟合相关推荐

  1. gammatone滤波器 matlab,Sleepwalking_新浪博客

    标签: octave dsp 在Octave 3.6以上的版本中使用fir1设计低通/高通/带通/带阻滤波器时,往往发现通带增益不正常,严重影响滤波器性能.例如以下代码设计一个20阶的低通滤波器并绘制 ...

  2. matlab 图像处理 新浪 应变,[转载]Matlab图像处理小结

    经常做做图像处理的东西,时间长了,有些函数就忘了,看到网上有人总结,收藏了. 1. 图像和图像数据 缺省情况下,MATLAB将图像中的数据存储为双精度类型(double),64位浮点数,所需存储量很大 ...

  3. MATLAB曲线拟合灵敏度,用Matlab曲线拟合工具箱curve fitting曲线拟合,原来是这样的...

    在使用Matlab软件时,对于曲线拟合来说,有两种方式,其一是编写程序代码,其二是利用Curve fitting工具箱进行.本例通过一个多项式拟合的小试验,向您介绍利用curve fitting工具箱 ...

  4. matlab对矩阵拟合,matlab曲线拟合与矩阵计算.ppt

    matlab曲线拟合与矩阵计算 Matlab应用重点(1)曲线拟合 曲线拟合定义 在实际工程应用和科学实践中,经常需要寻求 两个(或多个)变量间的关系,而实际去只能 通过观测得到一些离散的数据点.针对 ...

  5. matlab从flove,Matlab玩出新高度,变身表白女友神器_善良995的博客-CSDN博客

    原文作者:善良995 原文标题:Matlab玩出新高度,变身表白女友神器 发布时间:2021-03-19 13:36:02 Matlab还可以这样玩儿?每逢节日愁哭程序员,不知道该送什么给女朋友,在这 ...

  6. matlab 汽车 流场,matlab画流场图

    基于 Matlab 分布式工具箱的流场计算及其可视化 蔡群;周美莲;段杰峰;李青... 基于 MATLAB 和 CFD 数据库的流场可视化的实现 [J], 晏畅 5.基于 VB 与 MATLAB 混合 ...

  7. 阿当姆斯matlab,数值计算方法与MATLAB应用

    第1篇 数值计算的基本方法和概念 第1章 算法与误差 1.1 算法 1.2 误差 第2章 方程求解 2.1 引言 2.2 二分法 2.3 迭代法 2.4 牛顿法 2.5 弦截法 2.6 解非线性方程组 ...

  8. matlab课程目的,《Matlab应用》课程教学大纲.doc

    <Matlab应用>课程教学大纲 <Matlab工程应用>课程教学大纲 课程名称:Matlab工程应用 学分:3 总学时:48 讲课学时:40 实验学时:8 考核方式:考查 先 ...

  9. matlab中模块封装,MATLAB/simulink模块的封装

    编辑推荐: 本文来自于新浪博客,介绍的是关于模块的封装:搭建模型,设计参数,编辑参数框等. 今天重新回到MATLAB/simulink,介绍的是关于模块的封装的介绍. 首先搭建一个简单的模型: 全选, ...

最新文章

  1. XCTF联赛“出海计划”开启,八月新加坡站国际赛蓄势待发
  2. F5 Priority Group Activation
  3. 记一次CTF实验吧的代码审计
  4. 最高标号预留与推进算法 --- 就是要比 Dinic 快!
  5. 黑龙江认识电子计算机ppt,《第22课 不断发展的现代社会》优秀教案(黑龙江县级优课).docx...
  6. 什么是rip协议其优缺点_南京课工场IT培训:常见动态路由协议之———RIP动态路由实验...
  7. 计算机机房建设标准.doc,计算机机房建设标准(部分2)
  8. 如何在数字化转型战略中真正获得价值?浅谈数字化转型的四个层级
  9. c#chart背景透明_C#+Layui开发后台管理系统
  10. SWUST OJ(953)
  11. 吉他音阶训练——问题解答
  12. 王者战力查询接口,四大战区(文字版)
  13. Pollard rho整数分解法
  14. 《深入理解计算机系统》Lab2-Bomblab
  15. 浅谈如何使用Google reCAPTCHA进行人机验证
  16. GitHub 上受欢迎的 Android UI Library 整理
  17. 路透社:韩国游戏巨头Nexon欲出售控股权 腾讯将扮演关键角色
  18. 静态html加减乘除计算器代码,html+js实现简单的计算器代码(加减乘除)
  19. 手写数字识别系统 基于python
  20. Python async模块使用(杂文)

热门文章

  1. Cisco路由器交换机配置命令详解
  2. XP下卸载IE8还原到IE7的解决方法
  3. Coolite Toolkit学习笔记三:基本控件之Button、TextField、DataField、ComboBox
  4. raft算法mysql主从复制_mysql主从复制原理
  5. 为什么OpenStack与其他开源项目不同
  6. 开源xen对比_女实习生在Xen Project上摇摆开源
  7. (2)Node.js介绍
  8. bootstrap-table使用 带条件查询翻页及数据更新的问题。
  9. Bootstrap 编码规范之编辑工具配置
  10. es6 Reflect对象的静态方法