Matlab自带的曲线拟合程序
这个函数的功能是能自动搜索参数的取值,从而使得方程的误差最小。
效果如下
代码如下
%% Optimal Fit of a Non-linear Function % This is a demonstration of the optimal fitting of a non-linear function to a % set of data. It uses FMINSEARCH, an implementation of the Nelder-Mead simplex % (direct search) algorithm, to minimize a nonlinear function of several % variables. % % Copyright 1984-2002 The MathWorks, Inc. % $Revision: 5.15 $ $Date: 2002/04/02 17:52:33 $%% % First, create some sample data and plot it.% t = (0:.1:2)'; % y = [5.8955 3.5639 2.5173 1.9790 1.8990 1.3938 1.1359 1.0096 1.0343 ... % 0.8435 0.6856 0.6100 0.5392 0.3946 0.3903 0.5474 0.3459 0.1370 ... % 0.2211 0.1704 0.2636]';function [coeff,estimated_lambda] = fitdemo(XData, YData)if nargin<1,XData = (0:.1:2)';YData = [5.8955 3.5639 2.5173 1.9790 1.8990 1.3938 1.1359 1.0096 1.0343 ...0.8435 0.6856 0.6100 0.5392 0.3946 0.3903 0.5474 0.3459 0.1370 ...0.2211 0.1704 0.2636]';clc; endif ( size(XData) ~= size(YData) )error('The two input matrices have to be of the same sizes'); endplot(XData,YData,'ro'); hold on; h = plot(XData,YData,'b'); hold off; title('Input data');if ( size(XData, 1) == 1 )t = XData';y = YData'; elseif(size(XData, 2) == 1)t = XData;y = YData; end%% % The goal is to fit the following function with two linear parameters and two % nonlinear parameters to the data: % % y = C(1)*exp(-lambda(1)*t) + C(2)*exp(-lambda(2)*t) % % To fit this function, we've create a function FITFUN. Given the nonlinear % parameter (lambda) and the data (t and y), FITFUN calculates the error in the % fit for this equation and updates the line (h).% type fitfun%% % Make a guess for initial estimate of lambda (start) and invoke FMINSEARCH. It % minimizes the error returned from FITFUN by adjusting lambda. It returns the % final value of lambda.start = [1;0]; options = optimset('TolX',0.1); estimated_lambda = fminsearch('fitfun',start,options,t,y,h); %estimated_lambda = [estimated_lambda guidata(gcf)]; coeff = guidata(h); % C1,C2 'estimated_lambda = estimated_lambda'; 'coeff = coeff';
要拟合的函数为
function err = fitfun(lambda,t,y,handle) %FITFUN Used by FITDEMO. % FITFUN(lambda,t,y,handle) returns the error between the data and the values % computed by the current function of lambda. % % FITFUN assumes a function of the form % % y = c(1)*exp(-lambda(1)*t) + ... + c(n)*exp(-lambda(n)*t) % % with n linear parameters and n nonlinear parameters.% Copyright 1984-2002 The MathWorks, Inc. % $Revision: 5.8 $ $Date: 2002/04/08 20:04:42 $A = zeros(length(t),length(lambda)); for j = 1:length(lambda)A(:,j) = exp(-lambda(j)*t); end c = A\y; z = A*c; err = norm(z-y);set(gcf,'DoubleBuffer','on'); set(handle,'ydata',z) guidata(handle, c); drawnow pause(.04)
因为这种拟合方法用的比较少,所以特此总结出来,希望后来对自己的道路段的拟合会有用处!
2016-1-23 1059
转载于:https://www.cnblogs.com/arxive/p/5152950.html
Matlab自带的曲线拟合程序相关推荐
- matlab中ode指令,matlab自带的ballode程序
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 function ballode tstart = 0; tfinal = 30; y0 = [0; 20]; refine = 8; options = ...
- 图像拼接:matlab自带的拼接示例程序
matlab自带的拼接示例函数,可以拼接多张图像,效果一般,用的surf特征 % step1 Load images. buildingDir =('F:\stitching\imagess\or\l ...
- MATLAB可视化实战系列(四十)-基于MATLAB 自带手写数字集的CNN(LeNet5)手写数字识别-图像处理(附源代码)
一.前言 利用MATLAB实践MNIST手写数字识别,下载手写数据集的准备工作有些麻烦. 以下是我为大家准备的几个精品专栏,喜欢的小伙伴可自行订阅,你的支持就是我不断更新的动力哟! MATLAB-30 ...
- matlab中提供滤波器的种类有,求MATLAB巴特沃思低通滤波器程序
公告: 为响应国家净网行动,部分内容已经删除,感谢读者理解. 话题:求MATLAB巴特沃思低通滤波器程序.回答:击响应不变法函数 [bz,az]=impinvar(b,a,Fs) [bz,az]=im ...
- matlab 画非线性曲线,MATLAB实例:非线性曲线拟合
MATLAB实例:非线性曲线拟合 用最小二乘法拟合非线性曲线,给出两种方法:(1)指定非线性函数,(2)用傅里叶函数拟合曲线 1. MATLAB程序 clear clc xdata=[0.1732;0 ...
- 干货分享 基于MATLAB的带噪图像的高斯滤波论文
基于MATLAB的带噪图像的高斯滤波 摘要:图像常常被强度随机信号(也称为噪声)所污染.一些常见的噪声有椒盐(Salt & Pepper)噪声.脉冲噪声.高斯噪声等.椒盐噪声含有随机出现的黑白 ...
- 基于MATLAB的带噪图像的高斯滤波
基于MATLAB的带噪图像的高斯滤波 摘要:图像常常被强度随机信号(也称为噪声)所污染.一些常见的噪声有椒盐(Salt & Pepper)噪声.脉冲噪声.高斯噪声等.椒盐噪声含有随机出现的黑白 ...
- matlab自带滤波器函数小结(图像处理)
matlab自带滤波器函数小结(图像处理) 1 线性平滑滤波器 用MATLAB实现领域平均法抑制噪声程序: I=imread(' c4.jpg '); subplot(231) imshow(I) ...
- matlab自带滤波器函数
matlab自带滤波器函数小结(图像处理) 注:原文链接:http://www.ilovematlab.cn/forum.php?mod=viewthread&tid=215671 1 .线性 ...
- 使用matlab编写人脸识别的程序,并制作UI界面
使用 MATLAB 编写人脸识别程序可以使用 MATLAB 自带的图像处理工具箱,如 Image Processing Toolbox 来实现. 首先,需要导入人脸数据库并进行预处理,包括对图像进行预 ...
最新文章
- 三星E1200R语言设置_三星 S20 系列评测:依旧是 Android 阵营最高水平
- boost::type_erasure::less_than_comparable相关的测试程序
- Hybris CronJob.
- 计算机应用技术自创ppt,教师必备:超好用的课件制作工具
- RedHat系列软件管理(第二版) --源码包安装
- mysql客户端centos离线安装_mysql离线安装部署centos
- button点击事件不响应的解决方法(子视图大小超过父视图)
- nacos配置中心信息 nacos版本2.0.3
- MAML-CNN代码笔记
- 举例mysql中group_concat()函数使用
- 第三方rom 6.0刷机后,网络连接叹号处理方法
- android one a2,小米第二代 Android One 机种小米 A2 与平价版小米 A2 Lite 于西班牙发表...
- Nginx网站服务与LNMP架构部署(详解)
- python气泡图的地图_Python数据可视化:香港地图、房价可视化,绘制气泡图
- 解决vs2013编译时scanf报错的方法
- 深入理解C与C++ (0.1)
- jad通过命令生成java文件
- 论文研究记录----数据整理
- java中read方法
- 与阿尔茨海默病不一样 最新研究出现新型痴呆症