MATLAB-曲线拟合
2015-08-20 03:32
531 查看
曲线拟合
曲线拟合函数列表
polyfit
polyval
subplot
plot
代码
X | 0.1 | 0.2 | 0.15 | 0.0 | -0.2 | 0.3 |
---|---|---|---|---|---|---|
Y | 0.95 | 0.84 | 0.86 | 1.06 | 1.50 | 0.72 |
函数列表
polyfit
函数功能多项式的拟合运算
调用方法
polyfit(x,y,n)。
x为横坐标,y为纵坐标,n为拟合阶数。
例子
x = (0: 0.1: 2.5) ;1
y = erf(x);
p = polyfit(x,y,6)
p =
0.0084 -0.0983 0.4217 -0.7435 0.1471 1.1064 0.0004
则y=0.0084x^6-0.0983x^5+0.4217x^4-0.7435x^3+0.1471x^2+1.1064x+0.0004
polyval
函数功能多项式的估值运算
调用方法
polyval(p,x).
返回n次多项式p在x处的值。 输入变量p是一个长度为n+1的向量,其元素为按降幂排列的多项式系数。
例子
对多项式p(x)=3*x^2+2*x+1,计算在x=5,7,9的值。
p = [3 2 1];
x=[5,7,9];
polyval(p,x)
%结果为 ans = 86 162 262
subplot
函数功能分割figure,创建子坐标系
调用方法
h = subplot(m,n,p) or subplot(mnp);
subplot(m,n,p,’replace’);
subplot(m,n,P);
subplot(h);
subplot(‘Position’,[left bottom width height]);
subplot(…, prop1, value1, prop2, value2, …);
h = subplot(…) ;
subplot(m,n,P)此时p为向量,表示将P中指定的小块合并成一个大块创建坐标系,P中指定的小块可以不连续,甚至不相连。
例子
t=0:0.001:1;
y1=sin(10*t);
y2=sin(15*t);
subplot(211)
plot(t,y1)
subplot(212)
plot(t,y2)1.7432 -1.6959 1.0850
plot
函数功能绘制线性二维图
调用方法
plot(X,Y)
当X,Y均为实数向量,且为同维向量
例子
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y)
结果得到的是正弦函数曲线
代码
>> x=[0.1 0.2 0.15 0.0 -0.2 0.3]; >> y=[0.95 0.84 0.86 1.06 1.50 0.72]; >> p=polyfit(x,y,2) p = 1.7432 -1.6959 1.0850 >> xi=-0.2:0.01:0.3; >> yi=polyval(p,xi); >> subplot(2,2,1); >> plot(x,y,'o',xi,yi,'k'); >> title('polyfit');
从0至2.5,每隔0.1取一个数。
如:0,0.1,0.2,…,2.3,2.4,2.5。 ↩
相关文章推荐
- Linux下XWindow图形界面的基本概念
- 什么是Mac OS X?跟Linux有什么区别
- 一步一步跟我学易语言之第二个易程序菜单设计
- Mootools 1.2教程 函数
- autoit InputBox 函数
- 文件遍历排序函数
- Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
- ASP下经常用的字符串等函数参考资料
- PostgreSQL教程(五):函数和操作符详解(1)
- DOS批处理 函数定义与用法
- asp Chr 函数 数字转字母的方法
- Lua中的函数精讲笔记
- Lua中的闭合函数、非全局函数与函数的尾调用详解
- Lua中调用C++函数示例
- Lua实现split函数
- Lua常用时间函数使用实例
- Lua函数与字符串处理简明总结
- Lua学习笔记之表和函数
- Lua中实现sleep函数功能的4种方法
- Lua函数用法研究