Something doesn’t work for me in fit
Hello friends.
A little introduction:
I do a simulation for particles moving inside a box, as part of the simulation I measure the speed of the particles, and the idea is that in the end I get the Maxwell-Boltzmann distribution of the speed.
I wanted to do a fit to the histogram of the velocity, according to the Boltzmann equation, so that I could find the temperature of the system, but for some reason the fit does not fit exactly on the data. it’s similar, but not enough.
this is the fit that I get:
I’m uploading code with the histogram data, so you can run it yourself and see what you get.
I only change the histogram() in the figure, to plot(), so that it matches the data I uploaded.
This is the equation of Boltzmann distribution that I want to fit:
I will be happy if you can understand what is the problems..thanks!
This is the code, you can simple run it and see what is happening:
%my data:
hist_x=[10 30 50 70 90 110 130 150 170 190 210 230 250,…
270 290 310 330 350 370 390 410 430 450 470 490];
hist_y=[20 60 83 88 108 117 113 94 77 63 65 51 26,…
19 9 3 1 2 0 0 0 0 0 0 1];
%fit the velocity to Boltzmann distribution:
%parameters:
K_B=1.38e-23; %[m^2Kg/s^2K]
m=39.948*1.660e-27 ; %mass of Ar, convert from atomic mass to Kg [Kg]
boltzmann = fittype…
( @(T,v) (m/K_B*T)*v.*exp(((-m)/(2*K_B*T))*v.^2)…
, ‘coefficient’, ‘T’…
, ‘independent’, ‘v’) ;
[fitted_curve] = fit(hist_x’,hist_y’,boltzmann, ‘startPoint’, 100) ;
%plot histogram and fit:
figure;
plot(hist_x,hist_y);
hold on
plot(fitted_curve)
title(‘histogram of velocity and fitted curve – Boltzmann distribution’)
legend(‘histogram’, ‘fitted curve’);
xlabel(‘velovity [m/s]’)
ylabel(‘particles amount’)
disp(fitted_curve);Hello friends.
A little introduction:
I do a simulation for particles moving inside a box, as part of the simulation I measure the speed of the particles, and the idea is that in the end I get the Maxwell-Boltzmann distribution of the speed.
I wanted to do a fit to the histogram of the velocity, according to the Boltzmann equation, so that I could find the temperature of the system, but for some reason the fit does not fit exactly on the data. it’s similar, but not enough.
this is the fit that I get:
I’m uploading code with the histogram data, so you can run it yourself and see what you get.
I only change the histogram() in the figure, to plot(), so that it matches the data I uploaded.
This is the equation of Boltzmann distribution that I want to fit:
I will be happy if you can understand what is the problems..thanks!
This is the code, you can simple run it and see what is happening:
%my data:
hist_x=[10 30 50 70 90 110 130 150 170 190 210 230 250,…
270 290 310 330 350 370 390 410 430 450 470 490];
hist_y=[20 60 83 88 108 117 113 94 77 63 65 51 26,…
19 9 3 1 2 0 0 0 0 0 0 1];
%fit the velocity to Boltzmann distribution:
%parameters:
K_B=1.38e-23; %[m^2Kg/s^2K]
m=39.948*1.660e-27 ; %mass of Ar, convert from atomic mass to Kg [Kg]
boltzmann = fittype…
( @(T,v) (m/K_B*T)*v.*exp(((-m)/(2*K_B*T))*v.^2)…
, ‘coefficient’, ‘T’…
, ‘independent’, ‘v’) ;
[fitted_curve] = fit(hist_x’,hist_y’,boltzmann, ‘startPoint’, 100) ;
%plot histogram and fit:
figure;
plot(hist_x,hist_y);
hold on
plot(fitted_curve)
title(‘histogram of velocity and fitted curve – Boltzmann distribution’)
legend(‘histogram’, ‘fitted curve’);
xlabel(‘velovity [m/s]’)
ylabel(‘particles amount’)
disp(fitted_curve); Hello friends.
A little introduction:
I do a simulation for particles moving inside a box, as part of the simulation I measure the speed of the particles, and the idea is that in the end I get the Maxwell-Boltzmann distribution of the speed.
I wanted to do a fit to the histogram of the velocity, according to the Boltzmann equation, so that I could find the temperature of the system, but for some reason the fit does not fit exactly on the data. it’s similar, but not enough.
this is the fit that I get:
I’m uploading code with the histogram data, so you can run it yourself and see what you get.
I only change the histogram() in the figure, to plot(), so that it matches the data I uploaded.
This is the equation of Boltzmann distribution that I want to fit:
I will be happy if you can understand what is the problems..thanks!
This is the code, you can simple run it and see what is happening:
%my data:
hist_x=[10 30 50 70 90 110 130 150 170 190 210 230 250,…
270 290 310 330 350 370 390 410 430 450 470 490];
hist_y=[20 60 83 88 108 117 113 94 77 63 65 51 26,…
19 9 3 1 2 0 0 0 0 0 0 1];
%fit the velocity to Boltzmann distribution:
%parameters:
K_B=1.38e-23; %[m^2Kg/s^2K]
m=39.948*1.660e-27 ; %mass of Ar, convert from atomic mass to Kg [Kg]
boltzmann = fittype…
( @(T,v) (m/K_B*T)*v.*exp(((-m)/(2*K_B*T))*v.^2)…
, ‘coefficient’, ‘T’…
, ‘independent’, ‘v’) ;
[fitted_curve] = fit(hist_x’,hist_y’,boltzmann, ‘startPoint’, 100) ;
%plot histogram and fit:
figure;
plot(hist_x,hist_y);
hold on
plot(fitted_curve)
title(‘histogram of velocity and fitted curve – Boltzmann distribution’)
legend(‘histogram’, ‘fitted curve’);
xlabel(‘velovity [m/s]’)
ylabel(‘particles amount’)
disp(fitted_curve); curve fitting MATLAB Answers — New Questions