function HC_Fitting(app)
if exist('Graph')
delete(app.Graph)
end
xData = app.q;
yData= app.r;
ft = fittype("HC(x,Radius,Amp,Background,Pd)");
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'final';
opts.MaxFunEvals = 60000;
opts.MaxIter = 40000;
opts.TolFun=1e-6;
opts.TolX=1e-6;
Radius=app.CoreRadiusEditField.Value;
Amp=app.AmplitudeEditField.Value;
Background=app.BackgroundEditField.Value;
Pd=app.PolydispersityEditField.Value;
opts.StartPoint = [Amp Background Pd Radius];
opts.Lower = [0 0 0 0];
opts.Upper = [Inf 50 0.5 Inf];
[fitresult, ~] = fit( xData, yData, ft, opts );
app.CoreRadiusEditField.Value=fitresult.Radius;
app.AmplitudeEditField.Value=fitresult.Amp;
app.BackgroundEditField.Value=fitresult.Background;
app.PolydispersityEditField.Value=fitresult.Pd;
HC_plot(app);
end
function y=HC(app,q,Radius,Amp,Background,Pd)
syms z;
y1 = @(z) HC_formfactor(app,q,z);
va = Radius - app.NumptsEditField.Value*Pd;
vb = Radius + app.NumptsEditField.Value*Pd;
if(va<0)
va=0;
end
D =@(z) LN_Distribution(app,z,Radius,Pd);
fun = @(z) y1(z).*D(z);
y1=integral(D,va,vb,'ArrayValued',true);
y=integral(fun,va,vb,'ArrayValued',true)/y1;
y=abs(y.*Amp-Background);
end