lsqcurvefit not working properly

Hi all, I have multiple sets of data that are to be fitted by my fitting function. Since these data sets are kind of related, what I did was to use an inital guess to find the parameter values for the first dataset, and then use the parameter values as the guess for the second dataset so on and forth. However, the fitting was really bad. May I ask if there is another way around this kind of problem involving fitting of multiple datasets?
tic
%% Preparation
clear; clc
data = importdata("Experimental data\Transient Absorption\FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
%% Preamble
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
wavelength = data(1:end, 1); % contains all of the wavelengths
delay_t = data(1, 1:end); % conatains all of the delay times
E = (h*c)./(wavelength*10^-9); % contains all of the probe energies
% Range of data needed
Range_E = E>=1.5 & E<=2.2;
Range_W = wavelength >= (h*c)/(2.2*10^-9) & wavelength <= (h*c)/(1.5*10^-9);
Range_T = delay_t>=0.5 & delay_t<=1000;
E_p = E(Range_E); % probe energies for scatterplot
w_p = wavelength(Range_W);
delay_T = delay_t(Range_T);
Range_Efit = E_p>=1.62 & E_p<=max(E_p);
Range_Wfit = w_p >= (h*c)/(2.2*10^-9) & w_p <= (h*c)/(1.62*10^-9);
E_fit = E_p(Range_Efit); % probe energies for fitting
W_fit = w_p(Range_Wfit);
t_min = min(delay_T);
t_max = max(delay_T);
w_min = min(w_p);
w_max = max(w_p);
[row1, col1] = find(data == w_min);
[row2, col2] = find(data == w_max);
[row3, col3] = find(data == t_min);
[row4, col4] = find(data == t_max);
% New cleaned up data
data_new = data(row1:row2, col3:col4);% new data containing required delta A
% for n = 1:length(delay_T)
% delta_Abs(:,n) = -1*data_new(:,n);
% delta_Abs_norm(:,n) = delta_Abs(:,n)/max(delta_Abs(:,n));
% delta_Abs_fit(:,n) = data_new(Range_Wfit,n);
% delta_Abs_norm_fit(:,n) = delta_Abs_fit(:,n)/max(delta_Abs_fit(:, n));
% % plot command
% plot(E_p, delta_Abs_norm)
% xlabel('Probe Energy (eV)')
% ylabel('Normalised \Delta A (a.u.)')
% legend('Experimental Data')
% end
% Fitting function: Maxwell-Boltzmann distribution
function F = MB(y, e_fit)
data = importdata("Experimental data\Transient Absorption\FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv");
h = 4.0135667696*10^-15;
c = 3*10^8;
kB = 8.617333268*10^-5;
delay_t = data(1, :);
Range_T = delay_t>=0.5 & delay_t<=1000;
delay_T = delay_t(Range_T);
wavelength = data(1:end, 1);
E = (h*c)./(wavelength*10^-9);
Range_E = E>=1.5 & E<=2.2;
E_p = E(Range_E);
Range_Efit = E_p>=1.62 & E_p<=max(E_p);
E_fit = E_p(Range_Efit);
for i = 1:length(E_fit)
E_fit = e_fit(i);
F(i) = y(1).*exp(-(E_fit./(kB.*y(2)))) + y(3);
end
F = F(:);
end
% For loop to create required datasets for plotting
for n = 2:length(delay_T)
delta_Abs(:,1) = -1*data_new(:,1);
delta_Abs_norm(:,1) = delta_Abs(:,1)./max(abs(delta_Abs(:,1)));
delta_Abs_fit(:,1) = data_new(Range_Wfit,1);
delta_Abs_norm_fit(:,1) = delta_Abs_norm(Range_Wfit);
delta_Abs(:,n) = -1*data_new(:,n);
delta_Abs_norm(:,n) = delta_Abs(:,n)./max(abs(delta_Abs(:,n)));
delta_Abs_fit(:,n) = data_new(Range_Wfit,n);
delta_Abs_norm_fit(:,n) = delta_Abs_norm(Range_Wfit);
% lsqcurvefit
optim_lsq = optimoptions('lsqcurvefit', 'Algorithm', 'levenberg-marquardt', 'MaxFunctionEvaluations',10^20, 'MaxIterations', 10^20, 'FunctionTolerance',10^-20, 'StepTolerance', 10^-20);
lb = [0, 293, -1]; ub = [Inf, 6000, 1];
lb1 = [0, 293, -1]; ub1 = [Inf, 2000, 1];
lb2 = [0, 293, -1]; ub2 = [Inf, 1200, 1];
lb3 = [0, 293, -1]; ub3 = [Inf, 1000, 1];
lb4 = [0, 293, -1]; ub4 = [Inf, 750, 1];
y1 = [2*10^7, 1000, 0.5];
y2 = [2*10^7, 800, 0.5];
y3 = [2*10^10, 800, 0.5];
y4 = [2*10^11, 600, 0.5];
y5 = [2*10^14, 600, 0.5];
y(1,:) = lsqcurvefit(@MB, y1, E_fit, delta_Abs_norm_fit(:, 1), lb1, ub1, optim_lsq);
y(n,:) = lsqcurvefit(@MB, y(n-1, :), E_fit, delta_Abs_norm_fit(:, n), lb, ub, optim_lsq);
% plot command
plot(E_p, delta_Abs_norm)
hold on
plot(E_fit, MB(y(1,:), E_fit), 'red')
plot(E_fit, MB(y(n,:), E_fit), 'red')
xlabel('Probe Energy (eV)')
ylabel('Normalised \Delta A (a.u.)')
legend('Fitted curve')
end
carrier_T = y(:,2);
disp(carrier_T)
toc
%% Miscellaneous
% For a rectangular pic:
% drag horizontally until it just covers the letter 'c' in the word 'col'
% For a square pic:
% drag horizontall until it just covers the letter 'o' in the word 'Contribution' in the next line)
% legend('Experimental Data', 'Fitted Curve', 'Carrier Contribution','Excitonic Contribution')

 Accepted Answer

It is difficult for me to understand what you are doing in this version of your code.
You have a curve that is in part an exponential decay, so one option to estimate tthe initial parameters would be to linearise it, do a linear regression on it, re-transform the estimated parameters to use with your nonlinear regression function.
Lv = any(delta_Abs_norm_fit > 0,2);
B = [log(E_fit(Lv)) ones(size(E_fit(Lv)))] \ log(delta_Abs_norm_fit(Lv,:));
figure
plot(E_fit, delta_Abs_norm_fit)
hold on
plot(E_fit(Lv), exp([log(E_fit(Lv)) ones(size(E_fit(Lv)))]*B(:,1)))
hold off
title('Linear Regression Parameter Estimate Results')
The transformation would then be:
y1 = [exp(B(2,1)) B(1,1) rand]
The purpose of the ‘Lv’ calculation is to avoid taking the logarithms of negative numbers.
When I experimented with that approach with your other version of your code, it worked. The upside is that it’s reasonably efficient.
Experiment with it to see if it works in this version of your code.
.

8 Comments

Hi Star, thanks for the Ans! But do I need the for loop to do the fittings? I'm asking this becasue my original data file (named data in my code) is very large and each of the column corresponds to one set of data that needs to be used for fitting. I tried using the for loop and the computational time is really long. Is there another way around it?
Within the loop
y(1,:) = lsqcurvefit(@MB, y1, E_fit, delta_Abs_norm_fit(:, 1), lb1, ub1, optim_lsq);
You fit your first data set again and again. Why ?
Jack
Jack on 4 Jul 2024
Edited: Jack on 4 Jul 2024
Yeah I think I have made a mistake. I should fit the first data set outside the loop.
My pleasure!
I believe your code coiuld be more efficient, however I¹m not certain how it works, so I’m hesitant to alter it. I would do all data transformations that need to be done first, just after reading the file. Fittinbg the columns would be relatively straightforward after that.
Then, I would loop through the rows, and do the regression on each column. I do nott understand your data. If I did, I would attemp a column-wise parameter estimation in a loop.
data = readmatrix('FCPIB-293K-2.5...bg -chirp.csv');
wavelength = data(:,1);
goodcols = any(~ismissing(data(2:end,2:end)),1);
numel(goodcols)
ans = 300
goodcolsn = find(goodcols);
figure
% plot(data(2:end,1),data(2:end,2:end))
plot(data(2:end,1), data(2:end,goodcolsn(3:50:end)))
xlabel('Wavelength')
ylim([min(ylim) 0.025])
grid
function F = MB(y, E_fit)
F = y(1).*exp(-(E_fit./(8.617333268*10^-5.*y(2)))) + y(3);
end
.
Hi Star, appreciate your ans! I hope this will make clear of how to read my data:
  1. The first row contains quantities called delay time and I am only interest in the delay times within the range 0.5 - 1000
  2. The first column contians quantities called wavelength (with their units in nano-meters)
  3. For each entry in the first row, the remaining entries in the column is this quantity called "Absorbance" and hence each column corresponds to one dataset
  4. What I am doing now is that I will transform the first column (wavelength) into this quantity call energy (given by the formula (h*c)/(wavelength*10^-9)) the values for h and c may be found in my code in the header fundamental constants
  5. And again, I will only need energies ranging between 1.5 to 2.2 for my scatter plot
  6. However, for the fitting of my data, I will only need energies ranging between 1.65 to 2.2
may I please ask for you kind advice in the approach to column wise parameter estimation within a loop?
%% Preparation
clear;clc
data = importdata("FCPIB-293K-2.5...bg -chirp.csv"); % insert file path within parenthesis
%% Preamble
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Clean up of data to select range of values
wavelength = data(1:end, 1);
delay_t = data(1, 1:end); % conatains all of the delay times
E = (h*c)./(wavelength*10^-9); % contains all of the probe energies
Range_E = E>=1.5 & E<=2.2;
Range_T = delay_t>=0.5 & delay_t<=1000;
% for one delay time
T = find(Range_T);
T_min = min(T)
T_min = 56
T_max = max(T)
T_max = 241
% Fitting function
function F = MB(y, E_fit)
F = y(1).*exp(-(E_fit./(8.617333268*10^-5.*y(2)))) + y(3);
end
for t = T_min:T_max
% t = 57; % choose an integer b/w T_min and T_max
delaytime = delay_t(1, t);
disp(delaytime)
% Initial parameter guess and bounds
lb = [0, 293, -1]; ub = [Inf, 1200, 1];
y0 = [2*10^9, 1000, 0.5];
% Data for fitting
E_p = E(Range_E); % selected probe energies
delta_Abs = -1*data(Range_E,t);
delta_Abs_norm = delta_Abs./max(abs(delta_Abs)); % normalised delta_Abs
Range_Efit = E_p>=1.62 & E_p<=max(E_p);
E_fit = E_p(Range_Efit);
delta_Abs_norm_fit = delta_Abs_norm(Range_Efit);
Lv = any(delta_Abs_norm_fit > 0,2);
B = [log(E_fit(Lv)) ones(size(E_fit(Lv)))] \ log(delta_Abs_norm_fit(Lv,:));
%% Curve fitting options
% % Initial parameter guess and bounds
% lb = [0, 293, -1]; ub = [Inf, 800, 1];
% y0 = [1.2*10^9, 700, 0.5];
% lsqcurvefit and choose between different algorithm that lsqcurvefit employs (3C1, comment those lines that are not choosen and uncomment the line that is choosen, if not, matlab will take the last line of "optim_lsq" by default)
optim_lsq = optimoptions('lsqcurvefit', 'Algorithm', 'levenberg-marquardt', 'MaxFunctionEvaluations',10^10, 'MaxIterations', 10^10, 'FunctionTolerance',10^-10, 'StepTolerance', 10^-10);
% optim_lsq = optimoptions('lsqcurvefit', 'Algorithm', 'trust-region-reflective', 'MaxFunctionEvaluations',10^10, 'MaxIterations',10^10, 'FunctionTolerance',10^-20, 'StepTolerance', 10^-20);
% optim_lsq = optimoptions('lsqcurvefit', 'Algorithm', 'interior-point', 'MaxFunctionEvaluations',1000, 'MaxIterations', 1000, 'FunctionTolerance',10^-20, 'StepTolerance', 10^-20);
Lv = any(delta_Abs_norm_fit > 0,2);
B = [log(E_fit(Lv)) ones(size(E_fit(Lv)))] \ log(delta_Abs_norm_fit(Lv));
y0 = [exp(B); rand];
% figure
% plot(E_fit, delta_Abs_norm_fit)
% hold on
% plot(E_fit(Lv), exp([log(E_fit(Lv)) ones(size(E_fit(Lv)))]*B))
% hold off
% title("Linear Regression Parameter Estimate Results "+t)
% Solver for lsqcurvefit
[y, residualnorm, residual, exitflag, output, lambda, jacobian] = lsqcurvefit(@MB, y0, E_fit, delta_Abs_norm_fit, lb, ub, [], [], [], [], [], optim_lsq);
y_mtx(:,t-55) = y;
r_nrm(T-55,:) = residualnorm;
t_vct(t-55,:) = t;
%% Plot command
if rem(t-56,10) == 0
figure
plot(E_p, delta_Abs_norm,'Black')
hold on
plot(E_fit, MB(y, E_fit), 'LineWidth', 1.0, 'Color', 'red')
xlabel('Probe Photon Energy (eV)')
ylabel('Normalised \Delta A (a.u.)')
legend('Experimental Data', 'Fitted Curve')
title("t = "+t)
textx = min(xlim)+mean(xlim)/15;
texty = min(ylim)+mean(ylim)/2;
text(textx,texty, sprintf('F = %9.3E \\cdot e^{(-(E\\_fit/(8.617\\cdot10^{-5}\\cdot%.1f)))} + %.3f',y))
% disp(y)
% disp(y(1,1))
% disp(y(1,2))
% disp(y(1,3))
end
end
0.5342
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
0.5976
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum found. Optimization completed because the size of the gradient is less than 1e-4 times the value of the function tolerance.
0.6635
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
0.7311
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
0.8003
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
0.8727
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
0.9484
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
1.0257
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.1071
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.1901
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.2763
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.3634
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.4578
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.5522
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.6523
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.7524
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.8590
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
1.9673
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.0804
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.1976
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.3180
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.4417
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.5727
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.7062
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.8445
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
2.9870
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
3.1351
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
3.2897
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
3.4476
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
3.6111
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
3.7804
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
3.9554
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
4.1377
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
4.3257
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
4.5193
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
4.7203
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
4.9287
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
5.1443
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
5.3673
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
5.5976
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
5.8353
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
6.0818
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
6.3366
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
6.6002
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
6.8737
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
7.1552
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
7.4474
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
7.7485
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
8.0618
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
8.3849
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
8.7194
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
9.0644
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
9.4233
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
9.7936
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
10.1769
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
10.5724
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
10.9817
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
11.4057
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
11.8444
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
12.2993
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
12.7689
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
13.2522
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
13.7568
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
14.2768
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
14.8139
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
15.3698
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
15.9459
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
16.5416
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
17.1577
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
17.7949
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
18.4541
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
19.1352
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
19.8416
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
20.5716
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
21.3260
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
22.1072
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
22.9153
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
23.7511
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
24.6154
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
25.5089
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
26.4367
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
27.3937
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
28.3833
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
29.4087
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
30.4682
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
31.5644
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
32.6989
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
33.8724
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
35.0874
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
36.3431
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
37.6403
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
38.9871
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
40.3779
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
41.8167
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
43.3060
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
44.8457
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
46.4367
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
48.0846
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
49.7911
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
51.5538
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
53.3792
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
55.2648
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
57.2195
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
59.2394
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
61.3284
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
63.4883
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
65.7270
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
68.0407
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
70.4341
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
72.9088
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
75.4715
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
78.1220
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
80.8629
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
83.6990
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
86.6336
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
89.6699
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
92.8095
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
96.0582
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
99.4176
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
102.8950
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
106.4910
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
110.2130
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
114.0620
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
118.0430
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
122.1630
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
126.4240
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
130.8340
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
135.3940
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
140.1130
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
144.9940
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
150.0440
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
155.2670
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
160.6720
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
166.2620
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
172.0470
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
178.0310
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
184.2210
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
190.6230
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
197.2500
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
204.1020
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
211.1930
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
218.5270
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
226.1150
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
233.9640
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
242.0860
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
250.4860
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
259.1780
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
268.1680
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
277.4710
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
287.0930
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
297.0470
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
307.3460
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
318.0010
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
329.0190
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
340.4220
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum found. Optimization completed because the size of the gradient is less than 1e-4 times the value of the function tolerance.
352.2180
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
364.4210
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
377.0430
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
390.1020
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
403.6140
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
417.5870
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
432.0490
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
447.0070
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
462.4820
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
478.4880
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
495.0520
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
512.1850
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
529.9080
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
548.2430
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
567.2120
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
586.8350
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
607.1370
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
628.1390
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
649.8640
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum found. Optimization completed because the size of the gradient is less than 1e-4 times the value of the function tolerance.
672.3390
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
695.5940
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
719.6490
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum found. Optimization completed because the size of the gradient is less than 1e-4 times the value of the function tolerance.
744.5340
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
770.2780
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
796.9110
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
824.4630
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
852.9630
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
882.4530
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
912.9580
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum found. Optimization completed because the size of the gradient is less than 1e-4 times the value of the function tolerance.
944.5160
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
977.1620
Warning: Initial point is not feasible. Initializing x0 at nearest feasible point.
Local minimum found. Optimization completed because the size of the gradient is less than 1e-4 times the value of the function tolerance.
Parameters = table(t_vct, y_mtx(1,:).', y_mtx(2,:).', y_mtx(3,:).', r_nrm, 'VariableNames',{'t','y1','y2','y3','resid_norm'})
Parameters = 186x5 table
t y1 y2 y3 resid_norm __ __________ ______ _________ __________ 56 2.1481e+06 1198.8 -0.048583 0.15882 57 2.2743e+06 1200 -0.055101 0.15882 58 2.961e+06 1187.1 -0.064151 0.15882 59 6.2943e+06 1139.1 -0.07204 0.15882 60 3.0488e+07 1043.3 -0.076711 0.15882 61 3.3322e+08 923.88 -0.080706 0.15882 62 2.5387e+09 841.1 -0.086548 0.15882 63 4.5132e+10 746.28 -0.091154 0.15882 64 5.8557e+10 738.3 -0.099297 0.15882 65 7.4922e+10 730.4 -0.10548 0.15882 66 8.4157e+10 725.8 -0.11023 0.15882 67 9.2389e+10 721.81 -0.11345 0.15882 68 9.5319e+10 719.26 -0.11483 0.15882 69 9.7492e+10 716.9 -0.11578 0.15882 70 9.856e+10 714.81 -0.11617 0.15882 71 9.3988e+10 714.22 -0.11527 0.15882
Some of these worked better than others. My approximation method for the initial parameter estimates is reasonably robust for the earlier data, however less so for the last several, probably because they do not follow the same sort of exponential curve that the earlier ones did, and may not be modeled by ‘MB’ as well as the earlier ones. I leave that consideration (and necessary tweaks) to you. I added the ‘Parameters’ table to summarise the results.
.
Thank you Star!
As always, my pleasure!

Sign in to comment.

More Answers (1)

It would be helpful to run your script in the window to show that the "really bad" fit looks like. Post only the minimum code and data necessary to illustrate the issue. Modify your script so it runs in the Matlab answers window.
The value of Planck constant in eV/Hz is incorrect by a few percent; fixed below.
I had an error when I tried to run. The error went away when I changed the filename to something more simple.
Then the code timed out ("Your code took longer than 235 seconds to run. Simplify code and then run again.").
Your data file has >300 columns and 1024 rows of data. Plus a header line (the delay times) and lines of metadata at the end. Much of the data is NaNs.
You select data at a range of wavelengths (i.e. a range of rows) for plotting, from 547.8 to 802.5 nm. You select a subset of this data for fitting. The dashed line in plot below shows the begigning of the range for fitting. I edited the data file to eliminate rows and columns outside this range of plotting interest. And I adjusted Range_T so that only 3 spectra (3 columns) would be fitted.
The fitting function has 3 parameters: p(1:3). The fitting function is a decaying exponential function of energy, with parameters p(1)=amplitude of exponential, p(2)=temperature [K], which determines the energy constant for decay of the exponential, and p(3)=vertical offset of the baseline.
The absorbance data, in the energy range of interest, looks like an upside-down decaying exponential. The absorbance data wavelength increases with row number, so the energy decreases with row number. So the highest energies are the lowest number rows, and the lowest energy is the last row.
For the three columns plotted below, it looks like a good initial guess for the parameters is p0(2)=0.3 eV/kB~=3500 K, p0(3)=+0.002, and p0(1)=(ydata(end)-p0(3))/exp(-E(end)/(kB*p0(2))). A better initial guess for p0(3) is the mean value of the absorbance at the highest energy range being fitted.
data=importdata('spectrum1a.csv');
fprintf('Size(data)=%d x %.d.\n',size(data))
Size(data)=430 x 247.
%data = importdata("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv");
%% Preamble
% Fundamental constants
h = 4.135667696*10^-15; % units: eV/ Hz
%h = 4.0135667696*10^-15;
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
wavelength = data(1:end, 1); % wavelengths [nm]
delay_t = data(1, 1:end); % delay times
E = (h*c)./(wavelength*10^-9); % probe energies [eV]
% Range of data needed
Range_E = E>=1.5 & E<=2.2; % [eV]
%Range_T = delay_t>=0.5 & delay_t<=1000;
Range_T = delay_t>=0.5 & delay_t<=0.7;
E_p = E(Range_E); % probe energies for scatterplot
w_p = wavelength(Range_E);
% w_p = wavelength(Range_W);
delay_T = delay_t(Range_T);
%Range_Efit = E_p>=1.62 & E_p<=max(E_p);
Emin=1.62; % minimum energy for fitting [eV]
Range_Efit = E_p>=Emin;
E_fit = E_p(Range_Efit); % probe energies for fitting
t_min = min(delay_T);
t_max = max(delay_T);
w_min = min(w_p);
w_max = max(w_p);
[row1, ~] = min(find(data(:,1) == w_min));
[row2, ~] = max(find(data(:,1) == w_max));
[~, col1] = find(data == t_min);
[~, col2] = find(data == t_max);
% New cleaned up data
data_new = data(row1:row2, col1:col2);% new data containing required delta A
fprintf('Size(data_new)=%d x %.d.\n',size(data_new))
Size(data_new)=401 x 3.
fprintf('Size(E_Fit)=%d x %d.\n',size(E_fit))
Size(E_Fit)=340 x 1.
% Plot columns 1-3
figure
plot(E_p,data_new(:,1),'-r',E_p,data_new(:,2),'-g',E_p,data_new(:,3),'-b')
hold on; xline(Emin,'--k');
grid on; xlabel('Energy (eV)'); ylabel('\Delta Absorbance')
legend(['delay=',num2str(delay_T(1))],['delay=',num2str(delay_T(2))],['delay=',num2str(delay_T(3))],'Location','southeast')
% Fitting function: Maxwell-Boltzmann distribution
function F = MB(p, e)
kB = 8.617333268*10^-5; % [eV/K]
F = p(1).*exp(-(e./(kB.*p(2)))) + p(3);
end
% For loop to fit the data
figure
p=zeros(length(delay_T),3); % allocate array for fitted parameters
for n = 1:length(delay_T)
ydata=data_new(Range_Efit,n);
p0(3)=mean(ydata(1:10)); % initial guess
p0(2)=0.3/kB; % initial guess [deg K]
p0(1)=(ydata(end)-p0(3))/exp(-E_fit(end)/(kB*p0(2))); % initial guess
optim_lsq = optimoptions('lsqcurvefit', 'Algorithm', 'levenberg-marquardt', 'MaxFunctionEvaluations',10^20, 'MaxIterations', 10^20, 'FunctionTolerance',10^-20, 'StepTolerance', 10^-20);
lb = [-Inf, 293, -1]; ub = [Inf, 6000, 1];
p(n,:) = lsqcurvefit(@MB, p0, E_fit, ydata, lb, ub, optim_lsq);
fprintf('n=%d: p0=[%.2e %.0f %.4f]; p=[%.2e %.0f %.4f]\n',n,p0,p(n,:))
end
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
n=1: p0=[-5.79e+00 3481 0.0014]; p=[-7.52e+09 710 0.0007]
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
n=2: p0=[-6.58e+00 3481 0.0019]; p=[-1.14e+10 703 0.0009]
Local minimum possible. lsqcurvefit stopped because the relative size of the current step is less than the value of the step size tolerance.
n=3: p0=[-7.34e+00 3481 0.0022]; p=[-3.54e+09 739 0.0013]
% Plot data and fitted curves
figure
plot(E_fit,data_new(Range_Efit,1),'-r',E_fit,data_new(Range_Efit,2),'-g',E_fit,data_new(Range_Efit,3),'-b')
hold on
plot(E_fit,MB(p(1,:),E_fit),'--r',E_fit,MB(p(2,:),E_fit),'--g',E_fit,MB(p(3,:),E_fit),'--b')
grid on; xlabel('Energy (eV)'); ylabel('\Delta Absorbance')
legend(['delay=',num2str(delay_T(1))],['delay=',num2str(delay_T(2))],['delay=',num2str(delay_T(3))],...
'fit 1','fit 2','fit 3','Location','southeast')
The three fits look reasonable. The fitted p(1) and p(2) are not close to the initial gueeses, but it seems to work, i.e. the fitting routine finds a reasonable fit.

2 Comments

Thank you William!
To add on, I think I should have been mroe specific when I say that my fit is not good. Basically, I tried to fit all the 186 delay times, the resulting fitting is far off from the data points. That's what I meant. Hope this is clear.

Sign in to comment.

Products

Release

R2024a

Asked:

on 4 Jul 2024

Commented:

on 5 Jul 2024

Community Treasure Hunt

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

Start Hunting!