注册 登录
编程论坛 Matlab

[讨论]曲线拟合的方法

abingchem 发布于 2006-11-30 10:34, 4220 次点击

在我们的实验中经常遇到的就是数据拟合成曲线的问题,而Matlab在这方面具有极为强大的功能

今天特开一帖,希望大家总结一下经常遇到的拟合情况,版主将予以不同程度的奖励,望大家踊跃发言!


回帖格式:

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

【拟合 目标】:
【函数|方法】:
【具体 实例】:

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

9 回复
#2
abingchem2006-11-30 10:43

来个最简单的:

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

【拟合 目标】:多项式
【函数|方法】:polyfit,polyval
【具体 实例】:

x=0:0.1:5;
y=exp(-5*x)+x.*x;
subplot(2,1,1),plot(x,y,'r+'),hold on
p=polyfit(x,y,2)
yp=polyval(p,x);
plot(x,yp,'bo')
subplot(2,1,2),plot(yp-y,'*')

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

#3
尘埃1222006-11-30 12:38

呵呵,我也说说吧

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

【拟合 目标】:模型参数拟合
【函数|方法】:beta=lsqcurvefit(@fun,beta0,xdata,ydata) 返回求解参数值
beta= nlinfit(xdata,ydata,@fun,beta0)

【具体 实例】:

根据给定数据集合,模型,参数初值,拟合模型中需要确定的参数值

具体实例太长,就不列出来了,

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

[此贴子已经被作者于2006-11-30 12:43:37编辑过]

#4
abingchem2006-11-30 14:10
奖励
  尘埃122

金币 :10
经验 :10
魅力 :10
金钱 :20
#5
ydgsl2006-11-30 23:39
matlab曲线拟合的能力有限。下为一简例:
模型:y=b1+b2*x.^b3+b4*x.^b5+b6*x.^b7;
数据:
x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y=[8.2, 4.6, 4.3, 4.6, 5.1, 5.5, 5.7, 5.5, 5, 3.8]
#6
abingchem2006-12-01 09:03
ydgsl是这方面的大牛,给大家系统说说非线性拟合的情况啊
#7
abingchem2006-12-06 09:31

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

【拟合 目标】:多元线性拟合y=a1*x1+a2*x2+..+am*xm
【函数|方法】:pinv,\

【具体 实例】:数据点{x1i,x2i,…xmi,yi},

A=|x12,x22,…xm2|
|…………… |
|x1n,x2n,…xmn|

Y={y1,y2,y3,…,yn}'

则系数{a1,a2,…,am}'=pinv(A)*Y
在matlab中使用
coeff=A\Y
则可以得到最小二乘意义上的拟合系数

〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓

#8
abingchem2006-12-06 10:18
【转】Matlab中如何作圆回归
:#Peter Boettcher (boettcher@ll.mit.edu),2002/5/16, comp.soft-sys.matlab#

Q5.5: How can I fit a circle to a set of XY data?
=================================================

An elegant chunk of code to perform least-squares circle fitting was
written by Bucher Izhak and has been floating around the newgroup for
some time. The first reference to it that I can find is in:

function [xc,yc,R,a] = circfit(x,y)
%CIRCFIT Fits a circle in x,y plane
%
% [XC, YC, R, A] = CIRCFIT(X,Y)
% Result is center point (yc,xc) and radius R.A is an optional
% output describing the circle's equation:
%
% x^2+y^2+a(1)*x+a(2)*y+a(3)=0

% by Bucher izhak 25/oct/1991

n=length(x); xx=x.*x; yy=y.*y; xy=x.*y;
A=[sum(x) sum(y) n;sum(xy) sum(yy) sum(y);sum(xx) sum(xy) sum(x)];
B=[-sum(xx+yy) ; -sum(xx.*y+yy.*y) ; -sum(xx.*x+xy.*y)];
a=A\B;
xc = -.5*a(1);
yc = -.5*a(2);
R = sqrt((a(1)^2+a(2)^2)/4-a(3));

Tom Davis provided a more sophisticated approach that works for more
cases in and Code included.

#9
hitzhang2006-12-08 17:29
介绍一种能以人已精度逼近任意函数的方法:神经网络



1.BP网络





>> a=1:10;
b=rand(1,10);
net=newff(minmax(a),[6,1],{'tansig','purelin'},'trainlm');
>> net=train(net,a,b);
TRAINLM, Epoch 0/100, MSE 2.4582/0, Gradient 28.1399/1e-010 TRAINLM, Epoch 25/100, MSE 0.0100718/0, Gradient 0.0645639/1e-010 TRAINLM, Epoch 50/100, MSE 0.00279072/0, Gradient 0.0371558/1e-010 TRAINLM, Epoch 75/100, MSE 0.000259069/0, Gradient 0.000950231/1e-010 TRAINLM, Epoch 100/100, MSE 0.000246122/0, Gradient 0.00282375/1e-010 TRAINLM, Maximum epoch reached, performance goal was not met.
>> b1=sim(net,a);%预测
>> b-b1;%误差
ans = Columns 1 through 7 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 Columns 8 through 10 0.0351 -0.0351 0.0003


2.径向基函数网络


>> net=newrb(a,b,1);
NEWRB, neurons = 0, SSE = 0.587343
>> b2=sim(net,a);%预测
>> b-b2
ans = Columns 1 through 7 0.0891 0.0611 -0.2402 0.2367 -0.1718 -0.1205 -0.0118 Columns 8 through 10 0.2286 -0.1139 0.0427


3.零误差径向基函数网络


>> net=newrbe(a,b,1);
>> b2=sim(net,a);%预测
>> b-b2
ans = 1.0e-015 * Columns 1 through 7 -0.1110 0.3331 0.1665 -0.6661 -0.1249 -0.0555 0.2220 Columns 8 through 10 0 -0.2776 0.3331
#10
hitzhang2006-12-08 17:32
当然,真正的预测并不如此,还需做区间估计这一部分比较难
1