Fitting exponential curve in data

I have a txt file with data corresponding to the number of atoms trapped as a function of time. How can I create a function (in a separate file) with
EDecay(t,τ,A,B) = A*exp(-t/τ)+B and then use the function fit to fit the data, using certain starting points? And then how can I deduce the lifetime τ?

Antworten (1)

Matt J
Matt J am 6 Jun. 2021

0 Stimmen

A more efficient and direct way would be to use fminspleas (Download)
load data
funlist={@(tau,t)exp(-t/tau),1};
idx=tdata>0;
[tau,AB]=fminspleas(funlist,1,tdata(idx),ydata(idx));
tau,
tau = 3.0246
A=AB(1),
A = 9.8728e+05
B=AB(2)
B = 2.5888e+04
fn=@(t) A*funlist{1}(tau,t)+B;
plot(tdata,ydata,'o', tdata, fn(tdata));
xlabel 't';
ylabel 'EDecay';
ylim([0,2*max(ydata)])

2 Kommentare

gps
gps am 6 Jun. 2021
Bearbeitet: gps am 6 Jun. 2021
@Matt J thank you very much, this method does work, but would it also be possible to see how this can be achieved by creating a separate file with the function EDecay and using the fit function?
Matt J
Matt J am 7 Jun. 2021
Why? If it works, why do more work than is necessary?

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Gefragt:

gps
am 6 Jun. 2021

Kommentiert:

am 7 Jun. 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by