# How can I fit Bessel function of 1st kind with the scatter plot?

46 views (last 30 days)
SA on 12 Apr 2021
Commented: Walter Roberson on 4 May 2021
x1=[2.68, 3.34, 8.72, 11.04, 10.18, 6.83 6.24, 10.8, 10.04, 11.88, 10.51, 16.8, 16.98, 12.62, 8.2];
x2=[2.68, 2, 6.04, 9.08, 8.85, 4.44 5.7, 10.51, 11.8, 13.53, 10.85, 17, 16.8, 12.99, 8.61];
y1=[0.2387, 0.081755, -5.0995e-04, -0.1520, -0.1754, -0.1058, -0.1037, 0.1137, -0.1630, -0.080563, 0.1234, 0.1987, 0.092261, -0.066794, -0.091546];
y2=[0.2391, 0.9008, 0.3703, -0.3438, -0.7476, -0.0771, 0.3984, -0.0655, -0.2668, -0.2699, 0.3175, 0.3178, 0.3893, 0.3537, 0.4677];
[sx, idx] = sort(x2); sy = y2(idx); %//Sorting the distance value (x2)
c = linspace(1,10,length(sx));
scatter(sx,sy,[],c,'filled');
grid on; hold on;
[sx, idx] = sort(x1); sy = y1(idx);
scatter(sx,sy,[],c,'filled');
I wish to fit Bessel's function of 1st kind {J_0(kx)}. Then use different types of basic fitting by exploiting 'cftool'- GUI elementary one. With this scatter plot I want to fit the Bessel function. Can you tell me how to fit Bessel function of the first order. The script is generated by Matlab (attached). Can anyone help me out from here ? Thank you.
##### 2 CommentsShowHide 1 older comment
SA on 12 Apr 2021
[sx, idx] = sort(x2); sy = y2(idx); %//Sorting the values
c = linspace(1,10,length(sx));
scatter(sx,sy,[],c,'filled')
grid on; hold on;
and then use different types of basic fitting by exploiting 'cftool'- GUI elementary one. With this scatter plot I want to fit the Bessel function. Can you tell me how to fit Bessel function of the first order. The script is generated by Matlab (attached).

the cyclist on 12 Apr 2021
Edited: the cyclist on 12 Apr 2021
I don't have the Curve Fitting Toolbox, so I cannot help with that.
However, I used fitnlm, and I see a couple strange things about your data. The main problem is that your x data is length 14, and your y data are length 15. What is the correct way to make the correspondence between them? Your code does some that seems unlikely to be correct.
The data as plotted don't look like they're going to be fit well by J0. (Also, the fit is highly dependent on the initial guess of the fitted parameter, which is a bad sign.) Why do you think it is a good function to use? But, maybe, it is just that the wrong data are being used, because of the above issue.
% % Unused data
% x1=[2.68, 3.34, 8.72, 11.04, 10.18, 6.24, 10.8, 10.04, 11.88, 10.51, 16.8, 16.98, 12.62, 8.2];
% y1=[0.2387, 0.081755, -5.0995e-04, -0.1520, -0.1754, -0.1058, -0.1037, 0.1137, -0.1630, -0.080563, 0.1234, 0.1987, 0.092261, -0.066794, -0.091546];
% Used data
x2=[2.68, 2, 6.04, 9.08, 8.85, 5.7, 10.51, 11.8, 13.53, 10.85, 17, 16.8, 12.99, 8.61];
y2=[0.2391, 0.9008, 0.3703, -0.3438, -0.7476, -0.0771, 0.3984, -0.0655, -0.2668, -0.2699, 0.3175, 0.3178, 0.3893, 0.3537, 0.4677];
% Seems to be needed because x vector in length 14, and y is 15 ????
[sx, idx] = sort(x2);
sy = y2(idx); %//Sorting the distance value (x2)
% Define Bessel function with free parameter
f = @(k,x) besselj(0,k.*x);
% Initial guess at free parameter.
k0 = 1;
% Fit the model
mdl = fitnlm(sx',sy',f,k0)
mdl =
Nonlinear regression model: y ~ F(k,x) Estimated Coefficients: Estimate SE tStat pValue ________ ________ ______ __________ b1 1.0931 0.057519 19.004 7.2286e-11 Number of observations: 14, Error degrees of freedom: 13 Root Mean Squared Error: 0.406 R-Squared: 0.072, Adjusted R-Squared 0.072 F-statistic vs. zero model: 2, p-value = 0.18
% Define points for plotting model fit
xq = (0:0.01:20)';
yq = predict(mdl,xq);
% Plot data and model
figure
hold on
scatter(sx,sy)
plot(xq,yq)
grid on; hold on;
Walter Roberson on 4 May 2021
I constructed
Err = @(G) sum((besselj(0,G*x2)-y2).^2)
and minimized Err. Plotting Err over G values helped to be sure that I got the actual minima. This gives you the GG7 value.
I got the GG = 0.434526903246627 by reading locations off of your plot and running a fit to match the points, or something like that. I do not recall now exactly what I did. I might have done an initial estimate based upon the known points and then looked for a local minima nearby.