Changing step tolerance for lsqcurvefit

55 views (last 30 days)
Dear Community
I have been trying to change my step tolerance but I have been unsuccessful. Currently, I am using
options = optimoptions(options,'StepTolerance',1e-10);
But I keep getting this error:
Can someone please help me in getting this to work to match my data? I believe since my step is currently set to 1.0e-6 and since my Dab is smaller than this at 7.9e-8 it runs into an issue that it cant match
  2 Comments
Daniel Alejandro Diaz
Daniel Alejandro Diaz on 11 Apr 2023
Here is the code I am using
%% Fitting experimental data to mathematical model %%
% Dab is found to be around 8.124E-8 cm^2/s
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;
Dab = lsqcurvefit(@f, x0, t, c) % fitting Dab to function(@f) defined below
Local minimum possible. lsqcurvefit stopped because the size of the current step is less than the value of the step size tolerance.
Dab = 2.2298e-06
% to data t & c starting at 0 by using x0
% and will be in units (cm^2/s)
options = optimoptions(options,'StepTolerance',1e-10);
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.06; % 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.01; % 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
Torsten
Torsten on 11 Apr 2023
Edited: Torsten on 11 Apr 2023
Didn't you read my response to a previous question of yours ?
The end concentration of your model function is Co*Vp/Vl. If this value doesn't equal the asymptotic value of your measurement data, you won't be able to fit your data with the model function. In the case above, the end concentration of your model function is 0.0056 which is not consistent with your measurement data.

Sign in to comment.

Accepted Answer

dpb
dpb on 11 Apr 2023
opt=optimoptions('lsqcurvefit');
opt.StepTolerance=1E-8
opt =
lsqcurvefit options: Options used by current Algorithm ('trust-region-reflective'): (Other available algorithms: 'interior-point', 'levenberg-marquardt') Set properties: StepTolerance: 1.0000e-08 Default properties: Algorithm: 'trust-region-reflective' CheckGradients: 0 Display: 'final' FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' FunctionTolerance: 1.0000e-06 JacobianMultiplyFcn: [] MaxFunctionEvaluations: '100*numberOfVariables' MaxIterations: 400 OptimalityTolerance: 1.0000e-06 OutputFcn: [] PlotFcn: [] SpecifyObjectiveGradient: 0 SubproblemAlgorithm: 'factorization' TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('trust-region-reflective')
in your code above
...
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)
options = optimoptions(options,'StepTolerance',1e-10);
...
it does no good to set the optimization options object after you've already called the optimizer/fitting function...
...
opt=optimoptions('lsqcurvefit'); % create default object for given fitter
opt=optimoptions(opt,'StepTolerance',1e-10); % set the step tolerance to something other than default
Dab = lsqcurvefit(@f, x0, t, c,[],[],opt)
% to data t & c starting at 0 by using x0
% and will be in units (cm^2/s)
...

More Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!