Hi Andrew,
I understand you wish to fit a Weibull curve to your data.
Due to lack of the exact data, I created a comparable dataset using a 2 parameter Weibull distribution with a=10 and b=2, with the x coordinates shifted by 35 units:
When a Weibull curve is fitted to this data (using default starting points), the following result is obtained:
This is very similar to the result you are getting with your data.
The standard Weibull distribution, as specified in the Curve Fitting Toolbox, is characterized by two parameters: the Shape parameter (b) and the Scale parameter (a). However, this 2-parameter version of the Weibull distribution could fall short in fully capturing your data if the data is shifted from the origin.
For a more precise fit, you might want to use a 3-parameter Weibull distribution that includes an extra parameter for location/threshold, denoted as "c":
The Curve Fitting Toolbox does not provide the 3-parameter Weibull distribution as part of its model library, but you can create a custom equation to use it.
Please refer to the following code:
x=linspace(1,10,nSamples);
createFit.m:
function [fitresult, gof] = createFit(x, y)
[xData, yData] = prepareCurveData( x, y );
ft = fittype( @(a,b,c,x) a*b*(x-c).^(b-1).*exp(-a*(x-c).^b));
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.StartPoint = [0.779051723231275 0.715037078400694];
opts.StartPoint = [opts.StartPoint 34];
[fitresult, gof] = fit( xData, yData, ft, opts );
figure( 'Name', '3 param Weibull fit' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', 'fitted Weibull curve', 'Location', 'NorthEast', 'Interpreter', 'none' );
xlabel( 'x', 'Interpreter', 'none' );
ylabel( 'y', 'Interpreter', 'none' );
This following result is obtained when the Weibull curve is fitted to the data now:
The new model perfectly captures the data. As emphasized in the comments, it is very important that you provide a suitable initial value for the location parameter otherwise the model will not converge.
Please refer to the following MATLAB documentation for further reference:
Hope this helps!
Best regards,
Saarthak