简体   繁体   中英

Exponential fitting in matlab

I have been struggling to fit my data with an exponential in matlab - it ends up looking like a flat line, to a curve.

subset.time = [0:5e-5:.0404]';
subset.voltage = [-125.073333333333 -125.146666666667   -125.145000000000   -125.195000000000   -125.193333333333   -125.243333333333   -125.245000000000   -125.268333333333   -125.291666666667   -125.291666666667   -125.390000000000   -125.390000000000   -125.438333333333   -125.438333333333   -125.463333333333   -125.513333333333   -125.488333333333   -125.561666666667   -125.586666666667   -125.635000000000   -125.635000000000   -125.661666666667   -125.685000000000   -125.708333333333   -125.756666666667   -125.756666666667   -125.806666666667   -125.855000000000   -125.878333333333   -125.828333333333   -125.878333333333   -125.951666666667   -125.951666666667   -125.976666666667   -126.001666666667   -126.025000000000   -126.048333333333   -126.098333333333   -126.098333333333   -126.146666666667   -126.146666666667   -126.196666666667   -126.171666666667   -126.246666666667   -126.243333333333   -126.270000000000   -126.318333333333   -126.320000000000   -126.391666666667   -126.318333333333   -126.366666666667   -126.391666666667   -126.440000000000   -126.488333333333   -126.465000000000   -126.513333333333   -126.561666666667   -126.561666666667   -126.561666666667   -126.660000000000   -126.683333333333   -126.636666666667   -126.710000000000   -126.708333333333   -126.708333333333   -126.758333333333   -126.783333333333   -126.830000000000   -126.830000000000   -126.855000000000   -126.855000000000   -126.880000000000   -126.928333333333   -126.930000000000   -126.953333333333   -126.930000000000   -127.001666666667   -127.003333333333   -127.001666666667   -127.050000000000   -127.100000000000   -127.123333333333   -127.148333333333   -127.123333333333   -127.148333333333   -127.173333333333   -127.246666666667   -127.221666666667   -127.270000000000   -127.246666666667   -127.246666666667   -127.246666666667   -127.245000000000   -127.343333333333   -127.343333333333   -127.416666666667   -127.416666666667   -127.416666666667   -127.416666666667   -127.368333333333   -127.441666666667   -127.490000000000   -127.538333333333   -127.515000000000   -127.515000000000   -127.540000000000   -127.538333333333   -127.613333333333   -127.613333333333   -127.638333333333   -127.686666666667   -127.686666666667   -127.663333333333   -127.638333333333   -127.735000000000   -127.686666666667   -127.735000000000   -127.806666666667   -127.806666666667   -127.808333333333   -127.758333333333   -127.856666666667   -127.881666666667   -127.881666666667   -127.931666666667   -127.931666666667   -127.931666666667   -127.930000000000   -128.001666666667   -128.025000000000   -128.025000000000   -128.100000000000   -128.100000000000   -128.100000000000   -128.050000000000   -128.125000000000   -128.125000000000   -128.150000000000   -128.150000000000   -128.225000000000   -128.200000000000   -128.175000000000   -128.225000000000   -128.248333333333   -128.271666666667   -128.295000000000   -128.318333333333   -128.295000000000   -128.320000000000   -128.368333333333   -128.343333333333   -128.368333333333   -128.418333333333   -128.418333333333   -128.443333333333   -128.443333333333   -128.491666666667   -128.516666666667   -128.491666666667   -128.516666666667   -128.563333333333   -128.516666666667   -128.538333333333   -128.588333333333   -128.563333333333   -128.588333333333   -128.636666666667   -128.636666666667   -128.636666666667   -128.636666666667   -128.710000000000   -128.686666666667   -128.711666666667   -128.758333333333   -128.783333333333   -128.735000000000   -128.735000000000   -128.808333333333   -128.831666666667   -128.856666666667   -128.833333333333   -128.858333333333   -128.833333333333   -128.856666666667   -128.906666666667   -128.906666666667   -128.930000000000   -128.955000000000   -128.930000000000   -128.980000000000   -128.980000000000   -129.028333333333   -129.005000000000   -129.053333333333   -129.051666666667   -129.076666666667   -129.076666666667   -129.100000000000   -129.125000000000   -129.126666666667   -129.150000000000   -129.173333333333   -129.200000000000   -129.175000000000   -129.175000000000   -129.223333333333   -129.248333333333   -129.223333333333   -129.273333333333   -129.248333333333   -129.273333333333   -129.248333333333   -129.323333333333   -129.346666666667   -129.346666666667   -129.395000000000   -129.371666666667   -129.370000000000   -129.346666666667   -129.395000000000   -129.420000000000   -129.445000000000   -129.468333333333   -129.443333333333   -129.445000000000   -129.443333333333   -129.491666666667   -129.516666666667   -129.516666666667   -129.541666666667   -129.516666666667   -129.516666666667   -129.491666666667   -129.591666666667   -129.591666666667   -129.638333333333   -129.615000000000   -129.613333333333   -129.661666666667   -129.615000000000   -129.661666666667   -129.661666666667   -129.661666666667   -129.685000000000   -129.735000000000   -129.685000000000   -129.661666666667   -129.710000000000   -129.735000000000   -129.760000000000   -129.760000000000   -129.785000000000   -129.760000000000   -129.785000000000   -129.835000000000   -129.810000000000   -129.785000000000   -129.835000000000   -129.860000000000   -129.835000000000   -129.835000000000   -129.860000000000   -129.908333333333   -129.883333333333   -129.955000000000   -129.955000000000   -129.908333333333   -129.931666666667   -129.956666666667   -129.955000000000   -129.980000000000   -130.003333333333   -130.003333333333   -130.003333333333   -130.028333333333   -130.030000000000   -130.078333333333   -130.053333333333   -130.076666666667   -130.103333333333   -130.028333333333   -130.103333333333   -130.126666666667   -130.175000000000   -130.126666666667   -130.150000000000   -130.175000000000   -130.151666666667   -130.198333333333   -130.175000000000   -130.200000000000   -130.151666666667   -130.225000000000   -130.223333333333   -130.225000000000   -130.250000000000   -130.225000000000   -130.250000000000   -130.250000000000   -130.248333333333   -130.273333333333   -130.273333333333   -130.273333333333   -130.321666666667   -130.273333333333   -130.296666666667   -130.346666666667   -130.346666666667   -130.346666666667   -130.348333333333   -130.371666666667   -130.371666666667   -130.321666666667   -130.396666666667   -130.421666666667   -130.396666666667   -130.371666666667   -130.396666666667   -130.396666666667   -130.420000000000   -130.445000000000   -130.470000000000   -130.421666666667   -130.468333333333   -130.470000000000   -130.445000000000   -130.470000000000   -130.493333333333   -130.516666666667   -130.468333333333   -130.518333333333   -130.566666666667   -130.518333333333   -130.516666666667   -130.566666666667   -130.518333333333   -130.541666666667   -130.543333333333   -130.591666666667   -130.566666666667   -130.566666666667   -130.616666666667   -130.640000000000   -130.615000000000   -130.640000000000   -130.665000000000   -130.641666666667   -130.640000000000   -130.738333333333   -130.690000000000   -130.665000000000   -130.688333333333   -130.713333333333   -130.690000000000   -130.713333333333   -130.738333333333   -130.738333333333   -130.713333333333   -130.736666666667   -130.738333333333   -130.738333333333   -130.763333333333   -130.763333333333   -130.761666666667   -130.738333333333   -130.761666666667   -130.785000000000   -130.761666666667   -130.786666666667   -130.786666666667   -130.810000000000   -130.810000000000   -130.835000000000   -130.786666666667   -130.810000000000   -130.810000000000   -130.835000000000   -130.835000000000   -130.811666666667   -130.860000000000   -130.860000000000   -130.858333333333   -130.858333333333   -130.908333333333   -130.908333333333   -130.906666666667   -130.908333333333   -130.908333333333   -130.908333333333   -130.933333333333   -130.981666666667   -130.933333333333   -130.931666666667   -130.981666666667   -130.931666666667   -130.933333333333   -131.006666666667   -130.983333333333   -131.006666666667   -130.981666666667   -131.030000000000   -131.030000000000   -131.005000000000   -131.030000000000   -131.030000000000   -131.006666666667   -131.030000000000   -131.055000000000   -131.030000000000   -131.030000000000   -131.055000000000   -131.080000000000   -131.080000000000   -131.080000000000   -131.080000000000   -131.055000000000   -131.030000000000   -131.080000000000   -131.103333333333   -131.080000000000   -131.080000000000   -131.080000000000   -131.128333333333   -131.103333333333   -131.128333333333   -131.178333333333   -131.153333333333   -131.153333333333   -131.153333333333   -131.153333333333   -131.178333333333   -131.203333333333   -131.201666666667   -131.176666666667   -131.201666666667   -131.203333333333   -131.226666666667   -131.203333333333   -131.225000000000   -131.203333333333   -131.178333333333   -131.201666666667   -131.201666666667   -131.226666666667   -131.250000000000   -131.273333333333   -131.298333333333   -131.250000000000   -131.226666666667   -131.248333333333   -131.298333333333   -131.273333333333   -131.323333333333   -131.300000000000   -131.275000000000   -131.323333333333   -131.298333333333   -131.323333333333   -131.323333333333   -131.348333333333   -131.348333333333   -131.348333333333   -131.348333333333   -131.323333333333   -131.348333333333   -131.398333333333   -131.348333333333   -131.396666666667   -131.348333333333   -131.421666666667   -131.348333333333   -131.396666666667   -131.421666666667   -131.446666666667   -131.471666666667   -131.445000000000   -131.446666666667   -131.398333333333   -131.421666666667   -131.470000000000   -131.446666666667   -131.470000000000   -131.471666666667   -131.471666666667   -131.493333333333   -131.446666666667   -131.493333333333   -131.470000000000   -131.495000000000   -131.470000000000   -131.470000000000   -131.493333333333   -131.471666666667   -131.518333333333   -131.516666666667   -131.495000000000   -131.543333333333   -131.543333333333   -131.518333333333   -131.518333333333   -131.566666666667   -131.566666666667   -131.591666666667   -131.566666666667   -131.541666666667   -131.566666666667   -131.566666666667   -131.591666666667   -131.541666666667   -131.566666666667   -131.616666666667   -131.616666666667   -131.591666666667   -131.615000000000   -131.591666666667   -131.593333333333   -131.566666666667   -131.543333333333   -131.568333333333   -131.566666666667   -131.541666666667   -131.541666666667   -131.543333333333   -131.518333333333   -131.543333333333   -131.566666666667   -131.543333333333   -131.543333333333   -131.543333333333   -131.518333333333   -131.543333333333   -131.566666666667   -131.566666666667   -131.615000000000   -131.590000000000   -131.590000000000   -131.616666666667   -131.640000000000   -131.590000000000   -131.615000000000   -131.615000000000   -131.640000000000   -131.590000000000   -131.591666666667   -131.615000000000   -131.640000000000   -131.615000000000   -131.591666666667   -131.591666666667   -131.640000000000   -131.593333333333   -131.615000000000   -131.616666666667   -131.591666666667   -131.591666666667   -131.640000000000   -131.591666666667   -131.591666666667   -131.616666666667   -131.591666666667   -131.591666666667   -131.566666666667   -131.591666666667   -131.591666666667   -131.591666666667   -131.616666666667   -131.591666666667   -131.641666666667   -131.665000000000   -131.665000000000   -131.640000000000   -131.640000000000   -131.690000000000   -131.665000000000   -131.640000000000   -131.640000000000   -131.690000000000   -131.690000000000   -131.688333333333   -131.665000000000   -131.738333333333   -131.738333333333   -131.738333333333   -131.738333333333   -131.715000000000   -131.688333333333   -131.738333333333   -131.715000000000   -131.715000000000   -131.713333333333   -131.738333333333   -131.715000000000   -131.713333333333   -131.761666666667   -131.738333333333   -131.786666666667   -131.811666666667   -131.811666666667   -131.811666666667   -131.763333333333   -131.811666666667   -131.786666666667   -131.715000000000   -131.811666666667   -131.811666666667   -131.786666666667   -131.786666666667   -131.811666666667   -131.835000000000   -131.788333333333   -131.860000000000   -131.835000000000   -131.835000000000   -131.811666666667   -131.885000000000   -131.835000000000   -131.861666666667   -131.861666666667   -131.811666666667   -131.786666666667   -131.811666666667   -131.811666666667   -131.836666666667   -131.810000000000   -131.835000000000   -131.835000000000   -131.786666666667   -131.811666666667   -131.860000000000   -131.836666666667   -131.861666666667   -131.885000000000   -131.885000000000   -131.786666666667   -131.811666666667   -131.811666666667   -131.786666666667   -131.836666666667   -131.786666666667   -131.763333333333   -131.763333333333   -131.788333333333   -131.811666666667   -131.811666666667   -131.763333333333   -131.810000000000   -131.761666666667   -131.736666666667   -131.786666666667   -131.786666666667   -131.786666666667   -131.761666666667   -131.786666666667   -131.761666666667   -131.713333333333   -131.761666666667   -131.786666666667   -131.713333333333   -131.738333333333   -131.738333333333   -131.738333333333   -131.713333333333   -131.738333333333   -131.713333333333   -131.713333333333   -131.715000000000   -131.738333333333   -131.761666666667   -131.761666666667   -131.786666666667   -131.761666666667   -131.811666666667   -131.811666666667   -131.860000000000   -131.860000000000   -131.836666666667   -131.860000000000   -131.786666666667   -131.786666666667   -131.810000000000   -131.836666666667   -131.810000000000   -131.786666666667   -131.786666666667   -131.810000000000   -131.836666666667   -131.810000000000   -131.786666666667   -131.788333333333   -131.786666666667   -131.786666666667   -131.810000000000   -131.786666666667   -131.811666666667   -131.788333333333   -131.761666666667   -131.811666666667   -131.786666666667   -131.738333333333   -131.738333333333   -131.786666666667   -131.811666666667   -131.786666666667   -131.811666666667   -131.786666666667   -131.786666666667   -131.738333333333   -131.761666666667   -131.788333333333   -131.811666666667   -131.835000000000   -131.761666666667   -131.786666666667   -131.763333333333   -131.786666666667   -131.786666666667   -131.810000000000   -131.810000000000   -131.858333333333   -131.858333333333   -131.738333333333   -131.810000000000   -131.811666666667   -131.811666666667   -131.835000000000   -131.811666666667   -131.835000000000   -131.810000000000   -131.810000000000   -131.860000000000   -131.861666666667   -131.908333333333   -131.860000000000   -131.860000000000   -131.835000000000   -131.836666666667   -131.836666666667   -131.835000000000   -131.860000000000   -131.836666666667   -131.836666666667   -131.811666666667   -131.835000000000   -131.908333333333   -131.860000000000   -131.883333333333   -131.860000000000   -131.883333333333   -131.860000000000   -131.860000000000   -131.883333333333   -131.860000000000   -131.883333333333   -131.885000000000   -131.836666666667   -131.861666666667   -131.835000000000   -131.836666666667   -131.786666666667   -131.835000000000   -131.810000000000   -131.835000000000   -131.835000000000   -131.786666666667   -131.835000000000   -131.786666666667   -131.835000000000   -131.811666666667   -131.811666666667   -131.786666666667   -131.761666666667   -131.811666666667   -131.763333333333   -131.811666666667   -131.860000000000   -131.836666666667   -131.860000000000   -131.786666666667   -131.836666666667   -131.810000000000   -131.836666666667   -131.885000000000   -131.885000000000   -131.860000000000   -131.835000000000   -131.835000000000   -131.810000000000   -131.786666666667   -131.835000000000   -131.836666666667   -131.861666666667   -131.860000000000   -131.836666666667   -131.786666666667   -131.811666666667   -131.836666666667   -131.811666666667   -131.836666666667   -131.836666666667   -131.861666666667   -131.836666666667   -131.861666666667   -131.886666666667   -131.886666666667   -131.836666666667   -131.861666666667   -131.836666666667   -131.836666666667   -131.910000000000]';



f = fittype('exp1') 
[fitresult, gof] = fit( subset.time, subset.voltage, f);    
figure 
plot(fitresult, subset.time, subset.voltage)

I have also tried it just with code, same result. One guess is that the problem is that it is trying to fit this section from -infinity to + infinity, when I really just want to constrain it to the data points? When I do the exact same fit doing Igor, it fits it quite well. What are these programs doing differently? It looks like there is an additional coefficient in igor (W_coeff[0]) ...?

I am incredibly confused as to why these results are so different.

Code in igor:

CurveFit exp wave0 /X=wave1 /D

Fit converged properly
  fit_wave0= W_coef[0]+W_coef[1]*exp(-W_coef[2]*x)
  W_coef={-118.82,2.4409,141.98}
  V_chisq= 0.20919; V_npnts= 370; V_numNaNs= 0; V_numINFs= 0; 
  V_startRow= 0; V_endRow= 369; V_startCol= 0; V_endCol= 0; 
  W_sigma={0.00575,0.00522,0.968}
  Coefficient values ± one standard deviation
    y0      = -118.82 ± 0.00575
    A       = 2.4409 ± 0.00522
    invTau  = 141.98 ± 0.968

You need an offset term. I can't figure out how to just do an offset however, here's a workaround.

options = fitoptions('exp2', 'Lower', [-Inf 0 -Inf -Inf], 'Upper', [Inf 0 Inf Inf]);
[ftr, gof] = fit(subset.time, subset.voltage, 'exp2', options);
figure
plot(ftr, time, voltage)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM