查看完整版本: Optimal Fit of a Non-linear Function非线性函数的优化拟合

michael 2007-8-20 12:21

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.
rv,soO1b1_t First, create some sample data and plot it.l6^J)@+EW&S(V9t
x&|f8UFH
[code]t = (0:.1:2)';
O,\;M T?Z5u;v y = [5.8955 3.5639 2.5173 1.9790 1.8990 1.3938 1.1359 1.0096 1.0343 ...b6m%A9P#st!]o.?k
     0.8435 0.6856 0.6100 0.5392 0.3946 0.3903 0.5474 0.3459 0.1370 ...RKW}$J A~g
     0.2211 0.1704 0.2636]';s:Dw7Zz-UL
plot(t,y,'ro'); hold on; h = plot(t,y,'b'); hold off;SQ+[&Y"U3t
title('Input data'); ylim([0 6])[/code]
wy B`l
8z4k4R7L$h+E:Q [attach]961[/attach][5f"Jf lJ-LLUa
&y/apX mKB0G[
The goal is to fit the following function with two linear parameters and two nonlinear parameters to the data:
k sU'~0aS B    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). ,fm3ZSB3D!@-j6Yep"g z

l9Q:_E;r_/ibE [code]type fitfun[/code],mGF!I}
'}U#t7{k
function err = fitfun(lambda,t,y)%FITFUN Used by FITDEMO.%   FITFUN(lambda,t,y) 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-2004 The MathWorks, Inc.%   $Revision: 5.8.4.1 $  $Date: 2004/11/29 23:30:50 $A = zeros(length(t),length(lambda));for j = 1:length(lambda)   A(:,j) = exp(-lambda(j)*t);endc = A\y;z = A*c;err = norm(z-y);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. Use an output function to plot intermediate fits. C;D(KiY3q X4q

;N s:h~4vv o [code]start = [1;0];
1G4f QS;K#a&ga SE % We use an anonymous function to pass additional parameters t, y, h to the
_-O;k/tCLs % output function.
cf!WeV*_$B} outputFcn = @(x,optimvalues,state) fitoutputfun(x,optimvalues,state,t,y,h);ln_/uO9_b
options = optimset('OutputFcn',outputFcn,'TolX',0.1);
zE,x+GT@X estimated_lambda = fminsearch(@(x)fitfun(x,t,y),start,options)[/code])R_5Z M YY \#wXS

Nj\| [ estimated_lambda =
}5uc%T@2\L;{ aMHAXa
    3.5897
;Te`m"K#a.e3O!N,A     0.0030
JK1U3D U x$sdu.A
[attach]962[/attach]

aduktxj 2008-1-5 13:26

请问,我想拟合一个椭圆比如我只是知道椭圆上的某些点,怎么进行椭圆的拟合呢?在matlab的拟合工具箱里面没有椭圆的方程。%S-H2\_*p
另外:在一般的曲线拟合这块,用1stopt是最好的,如果不知道拟合方程的形式,1stopt中还能够进行公式的最佳搜索。

fghi651 2008-8-2 18:44

★卓越平台数据采集软件

[size=2][size=4][color=black]★QQ:511765061股票开户免费送top软件,手续费最低
3[Rn nxSl 期货开户免费PYMT d3^e5wVE8A

}Wu&cs9Tu&\ [/color][size=4][color=black]b/T!H6HA&h
提供:卓越商品采集系统QQ:511765061淘宝网站辅助软件-S F)o H8Ypc8el(N
[/color][/size][url=http://www.muyuchating.cn/][size=4][color=black]www.muyuchating.cn[/color][/size][/url]{{|UJ$c4E)T)s{
送群发软件及其注册机。[/size];m9PUD(})fN5S H:B:O
[size=4][/size]A)b%X9Rn}oM
[size=4]n4rI0O\pMhQA2yk8t C
(l*h-pUq
[size=4][color=black]在我们这边开户的朋友,HTg`?
需要top赢富数据软件请找我(免费) m I$ER Re
◆淘宝店铺[/color][/size][url=http://shop34172635.taobao.com/][size=4][color=black]http://shop34172635.taobao.com/[/color][/size][/url][size=4][color=black]代理正版淘宝店铺辅助软件,帮你方便管理店铺,采集商品。更多介绍请到店铺查看。
.l2}'AQ q#a@ ★[color=red]卓越平台数据采集软件,20个分类[/color] ZZ aG3{l/n-U)w
1.卓越平台数据采集软件是一款专门针对卓越网的数据采集
A0Y6D^} 2.可以生成淘宝助理文件,拍拍助理文件,易趣助理文件,shopex数据文件,ecshop数据文件;
#vNphU/]UlX 3.全自动采集轻松简便。Pxj#P4Y;YHC4IXD
★淘宝店铺重复商品处理软件
0U ID+}1`Y ★淘宝大管家,新品,促销 EwyqUc
★卓越代购小秘书,新品上架,促销
1ya%S.fV!r ★淘宝商品自动上架
m_#X3n5h4kxB*_ t!ELY2}i;Uz'g-M
[/color][/size][/size][/size]
页: [1]
查看完整版本: Optimal Fit of a Non-linear Function非线性函数的优化拟合