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

44 次查看(过去 30 天)
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 个评论
the cyclist
the cyclist 2021-4-12
Can you upload the code that gave the unexpected result?
If you have the Statistics and Machine Learning Toolbox, another option would be to use the fitnlm function.
SA
SA 2021-4-12
编辑:SA 2021-4-12
[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
the cyclist 2021-4-12
编辑:the cyclist 2021-4-12
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;
  13 个评论
SA
SA 2021-4-26
Now, I've tried to fit the data with 'fitnlm' I got close result with the 'cftool'. The parametr for the 'fitnlm', I've received
Nonlinear regression model:
y ~ F(k,x)
Estimated Coefficients:
Estimate SE tStat pValue
________ ________ ______ ___________
b1 0.83826 0.014496 57.826 1.3692e-148
Number of observations: 256, Error degrees of freedom: 255
Root Mean Squared Error: 0.43
R-Squared: 0.136, Adjusted R-Squared 0.136
F-statistic vs. zero model: 50.4, p-value = 1.24e-11
with 'cftool' I got the following data
General model:
f(x) = besselj(0,k*x)
Coefficients (with 95% confidence bounds):
k = 0.8385 (0.8099, 0.867)
Goodness of fit:
SSE: 47.14
R-square: 0.1356
Adjusted R-square: 0.1356
RMSE: 0.43
@Walter Roberson, how can you get the value of GG & GG7, you consider (guess randomly) those values or get from any derivation? Could you please comment on those data? Thank you.
Walter Roberson
Walter Roberson 2021-5-4
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Bessel functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by