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
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.
采纳的回答
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)
% 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 个评论
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 Center 和 File Exchange 中查找有关 Bessel functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!