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