Last change
on this file since 17 was
17,
checked in by zhangj, 10 years ago
|
To have a stable version on the server.
|
-
Property svn:executable set to
*
|
File size:
1.1 KB
|
Line | |
---|
1 | % profil de perte |
---|
2 | |
---|
3 | function [estimates, model] = fitprofil(xdata, ydata) |
---|
4 | % Call fminsearch with a random starting point. |
---|
5 | start_point = [2 -2 10 90]; % sig et zb chambre et amplitude |
---|
6 | model = @expfun; |
---|
7 | options = optimset('MaxFunEvals',2000); |
---|
8 | estimates = fminsearch(model, start_point,options); |
---|
9 | % expfun accepts curve parameters as inputs, and outputs sse, |
---|
10 | % the sum of squares error for A * exp(-lambda * xdata) - ydata, |
---|
11 | % and the FittedCurve. FMINSEARCH only needs sse, but we want to |
---|
12 | % plot the FittedCurve at the end. |
---|
13 | function [sse, FittedCurve] = expfun(params) |
---|
14 | sig = params(1); |
---|
15 | zb = params(2); |
---|
16 | chambre= params(3); |
---|
17 | A = params(4); |
---|
18 | z =xdata; |
---|
19 | |
---|
20 | ch=min(abs(chambre-z-zb),abs(-chambre-z-zb)); |
---|
21 | for i=1:length(z) |
---|
22 | x=z(i); |
---|
23 | if (x+zb)>chambre |
---|
24 | ch(i)=0; |
---|
25 | elseif (x+zb)<-chambre |
---|
26 | ch(i)=0; |
---|
27 | end |
---|
28 | end |
---|
29 | profil=erf(ch/sqrt(2)/sig); |
---|
30 | FittedCurve = A*(profil); |
---|
31 | ErrorVector = FittedCurve - ydata; |
---|
32 | sse = sqrt(sum(ErrorVector .^ 2))/length(z); |
---|
33 | end |
---|
34 | end |
---|
35 | |
---|
36 | |
---|
Note: See
TracBrowser
for help on using the repository browser.