matlab---数据拟合
2016-02-22 22:18
459 查看
指数曲线拟合
多项式拟合
function [a, resnorm] = fit t = 0: 60: 1800; f = [100 96.1111 92.7778 89.4444 86.6667 84.4444 82.2222 80 77.7778 76.1111 ... 74.4444 72.7778 71.1111 69.4444 68.3333 67.2222 66.1111 65 63.8889 ... 62.7778 61.6667 60.5556 59.4444 58.3333 57.2222 56.1111 55 53.8889 ... 52.7778 51.6667 51.1111]; grid; fun = inline('a(1) * exp(-1 * a(2) * t) + 40', 'a', 't'); a0 = zeros(1, 31); [a, resnorm] = lsqcurvefit(fun, a0, t, f); plot(t, f, '*'); hold on; g = a(1) * exp(-1 * a(2) * t) + 40; plot(t, g, 'r-'); xlabel('t'); ylabel('f1'); title('f1(t)'); end
function [a, resnorm ] = fitN x = [11 15 20 21 22 23 25 26 27]; t = [0.053 0.36 2.3 5.1 10.9 16.8 87.5 132.3 188.6]; fun = inline('a(1) * a(2).^x + a(3)', 'a', 'x'); a0 = [1 1 1]; [a, resnorm] = lsqcurvefit(fun, a0, x, t); plot(x, t, '*'); hold on; g = a(1) * a(2).^x + a(3); plot(x, g, 'r-'); xlabel('x'); ylabel('t'); title('时间'); end
多项式拟合
function [a, c ] = fitN x = [5 11 15 19 20 21 22 23 24 25 26 27]; t = [0.0036 0.053 0.36 1.3 2.3 5.1 10.9 16.8 36.1 87.5 132.3 188.6]; syms c; for i = 1:18 y2 = polyfit(x, t, i); Y = polyval(y2, x); %计算拟合函数在x处的值。 if sum((Y-t).^2)<0.1 c = i; %c为求得的多项式最高阶数, 误差平方和精度范围为0.1 break; end end plot(x, t, '*'); hold on; a = polyfit(x, t, c); %得到系数,按次数从高到低排列 y = polyval(a, x); %y = poly2sym(a, x); %在主窗口输入,系数数组转换为多项式 %vpa(y) %在主窗口输入,分数转换为小数 %y = 0.000001*x.^11 - 0.0002*x.^10 + 0.02*x.^9 - 1.1*x.^8 + 41.55*x.^7 - 1039.46*x.^6 + 18254.16*x.^5 - 224494.33*x.^4 + 1888238.89*x.^3 - 10294775.069*x.^2 + 32510012.84*x - 44542021.91; %得到的多项式,从主窗口中粘贴而来 plot(x, y, 'r-'); xlabel('x'); ylabel('t'); title('时间'); end
相关文章推荐
- 论文"Gradient Domain Guided Image Filtering" matlab实现代码
- MATLAB常用命令
- matlab常用函数
- matlab 判断两个矩阵是否相等
- MATLAB R2015安装及破解
- matlab练习程序(非负矩阵分解)
- 中值滤波 matlab实现
- [Matlab]使用Simulink进行UDP通讯2
- MATLAB与ISE联合仿真的必备流程
- [Matlab]使用Simulink进行UDP通讯1
- paper 24 :matlab的cat函数
- matlab重定向命令行输出的内容
- 图像拉普拉斯金字塔(laplacian pyramid)并从金字塔重建原图 matlab程序实现
- VLFeat-使用matlab版本计算HOG
- Hough变换检测圆(附:MATLAB程序) - mhjerry的专栏(子水) - 博客频道 - CSDN.NET
- Matlab默认精度设置和更改──设置小数点位数_我的资料_百度空间
- 接触Matlab10年后的一个总结,随时使用Matlab要掌握的一些要点
- 【分享】Matlab R2015a 发布啦!
- 【原创】开源Math.NET基础数学类库使用(03)C#解析Matlab的mat格式
- 国内第一部C#.Net调用Matlab混合编程视频教程