Draw best fitting Maxwell Boltzmann PDF
Afficher commentaires plus anciens
I got a dataset with values corresponding to velocities.
I need to obtain the PDF for those velocities. I'm not sure if I'm doing it correctly but here's my code for that:
input1 = dlmread('velocities_test.txt', ''); %dataset
input1([1,1],:) = [];
col1 = input1(:,1); %col1 has the values I want
[p,t] = hist(col1, 30);
d = (p/sum(p)); %this is my PDF
After that I want to draw the best fitting Maxwell Boltzmann PDF for the PDF I obtained before.
The formula is the following:
What I need to do is to try several values for the 'a' parameter and find the best fitting ecuation.
a = (1.0:0.01:5.0); % generating values for a between 1.0 and 5.0
for i=1:length(a)
for j = 1:length(t)
%Matriz de valor de 'ym'. Columnas = y(t) Filas = Cada Ym
y(i,j) = sqrt(2/pi)*((t(j)*exp((-t(j)^2)/(2*(a(i)^2))))/(a(i)^3)) ; %this is the formula staten above
endfor
endfor
figure(1)
for i = 1:length(a)
plot(t,y(i,:),'m-')
hold on
end
xlabel('Velocidad [m/s]')
ylabel('y(t)')
figure(1)
plot(t,d,'r-', "linewidth", 2)
set(gca, 'FontSize', 20)
Turns out this looks terrible and none of the functions seems to be the best fitting one.
Here they are in comparison to the original values:

What can I do to make the pink lines better? They look so small in comparison to the red one.
1 commentaire
the cyclist
le 24 Sep 2019
Not directly answering your question, but ...
Is there a reason you are doing this "fitting" manually, rather than using one of MATLAB's fitting functions (e.g. fitnlm from the Statistical and Machine Learning Toolbox).
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spline Postprocessing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!