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)@+E W&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}$JA~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]
w yB`l
8z4k4R7L$h+E:Q
[attach]961[/attach][5f"JflJ-LLUa
&y/apX mKB0G[
The goal is to fit the following function with two linear parameters and two nonlinear parameters to the data:
ksU'~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