Dear Community,
I have been trying to fit my data using lsqcurvefit but I have had trouble with the internal limits. Currently I am getting this prompt when I run the system
Can anyone help me with this prompt? And how I can go about fixing it. If you need my code please let me know and I will provide it ASAP
Any help would be greatly appreciated! Thank you!

Antworten (1)

Walter Roberson
Walter Roberson am 10 Apr. 2023

1 Stimme

There is nothing to fix.
Ideally the sum of squares would be exactly 0, which would require a perfect fit of parameters to the model and would require there be no round-off error.
lsqcurvefit knows that is not likely to happen, so it has several different stopping criteria. Some of the criteria cause a stop if the fit is taking longer than the maximum it has been configured for. Some of the criteria cause a stop if nan or infinities are encountered, making a solution impossible. Some of the criteria cause a stop if it can tell that the current location is unlikely to be an actual solution but it cannot figure out how to improve the solution.
And then there are criteria that lead to stopping when the result looks to be as good as you are likely to be able to get, that it does not seem worth looking for a better result anymore.
The particular criteria you are encountering is one that is in effect when the fit looks quite good and it doesn't seem worth chasing a better fit.
In some cases you need even more precise values; if so then there are options you can adjust to wait longer before deciding that further improvements are pointless.
In some cases, if your model deals with fairly small numbers, your fit might not really be any good and you need to adjust the options or scale the values. You need to have some understanding of the model to know whether a fit to within 10^-6 is good enough.
There is only one case in which lsqcurvefit could say definitively that it has found the model coefficients: that would be the case where the fit was exact right down to the last possible decimal place. That rarely happens. Instead the normal way for lsqcurvefit to end is to figure out that it has done as good of a fit as you are likely to get -- and then to say "but of course it is always possible that this is not really the best set of model parameters, that just maybe there is a better set of parameters somewhere".
Unless you get a fit right down to the last possible decimal place, then you will never know for sure that you really found the global minima -- not when you are doing numeric calculations. (In some cases it is possible to use symbolic calculations to prove that you have reached a global minima, but that gets difficult except for polynomials.)

5 Kommentare

Daniel Alejandro Diaz
Daniel Alejandro Diaz am 10 Apr. 2023
Thank you! That makes sense. For this one this limit seems to be okay but for my next release it is not as good. This is what i got for the next graph
Could this be a case where the limits, step, or tolerance should be changed to improve the fitting? Any help woul dbe greatly appreciated!
Walter Roberson
Walter Roberson am 11 Apr. 2023
Bearbeitet: Walter Roberson am 11 Apr. 2023
I have to wonder whether the model is correct for that data.
But that said: lsqcurvefit is fairly sensitive to initial point, especially when exponentials are involved. (We can tell from the asymtope that either an exponential is involved or maybe a ratio of two polynomials.)
You could try multiple curve fits from different initial points. Or you could construct a residue function and try it with fmincon() and with ga() to see if you can get better results.
HI Walter,
Thank you for the response!
Maybe it is that the function is incorrect but I have plotted them and they have similar behavior. This is what I was using as my code.
%% Fitting experimental data to mathematical model %%
% Dab is found to be around 8.124E-8 cm^2/s (Source: Preparation & characterization
% of chitosan membrane for the permeation of 5FU - Jen Ming Yang)
clear all
%Calling data from excel
filename = 'Data Sheet.xlsx'; % Call the file we are using
sheet = 'Run 1'; % Call the sheet we are using
xlRange = 'A2:A12'; % Call time values in seconds
x2Range = 'B2:B12'; % Call concentration in mg/mL
t = xlsread(filename, sheet, xlRange); % t = xlsread(filename, sheet, xlRange); % Reads x-axis specified with above variables
c = xlsread(filename,sheet, x2Range); % c = xlsread(filename, sheet, x2Range); % Reads y-axis specified with above variables
figure
plot(t,c,'-')
hold on
x0 = 0.00000000001;
optimoptions(@lsqnonlin,'StepTolerance',1e-12);
Dab = lsqcurvefit(@f, x0, t, c) % fitting Dab to function(@f) defined below
% to data t & c starting at 0 by using x0
% and will be in units (cm^2/s)
plot(t,f(Dab,t),'--')
hold off
grid
title('Release')
legend('Experimental','Theoretical')
xlabel('Time (sec)')
ylabel('Concentration (mg/mL)')
function Cal = f(Dab,t)
n = 0:250; % Number of sumations
RE = 0.10; % Release Efficieny for Chitosan is 6% so report value might be overestimated
Co = 187.*(RE); % Initial concentration of drug inside patch (mg/cm^3) (11.5 matches data!!!!)
L = 0.11; % Distance from middle of patch to surface (cm)
Vp = 1*1*2*L; % Volume of patch (cm^3)
Vl = 40; % Volume of liquid reservoir (cm^3)
%Belows is the average concentration profile <Ca>
lambdan = (((2.*n+1).*pi)./(2.*L)) ;
sum_parts = (((-1).^n)./(lambdan.^2)) .* exp(-(lambdan.^2).*Dab.*t) .* sin(lambdan.*L) ; %Summation
Cal = ((Co.*Vp)./Vl).*(1-(2./(L.^2)).*sum(sum_parts,2)); %Final Function
end
Also, Here is the expression i am fitting to the data
Walter Roberson
Walter Roberson am 11 Apr. 2023
Can you attach your data for testing?
Daniel Alejandro Diaz
Daniel Alejandro Diaz am 11 Apr. 2023
Bearbeitet: Daniel Alejandro Diaz am 11 Apr. 2023
Hi Walter,
Absolitely! I apologize. I thopught I attached it but here it is! Also, I have been switching RE to change the height of the system. In other words Co control the height of the film and I change RE to change its eficiency thus changng the height. This is similar to the one I posted last night that you helped me with and said had a good fit. Only differency it that this has a different height and release behavior but the same expression to fit... I excpect Dab and RE to change to fit the data but currently I am using trial and error to get RE and use MATLAB to find DAB through the fit. I believe finding RE and Dab simultaneously with lsqcurvefit but I am not sure how to do that and have been unsuccessful when i try

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by