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