I'm trying to plot a maxwell-boltzman velocity distribution in matlab.
I have also asked this question at cross validated without much luck
The PDF is
f(v)=sqrt(m/2*pi*k*T) * exp(-m*v^2/2*k*T)
I have defined the following function:
(This simple function is split over so many lines for debugging purposes.)
function [ output_args ] = mypdf( V_i ) m=2.18e-25; k=1.38e-23; T=500; intm = m/(2*pi*k*T); intmsqr = sqrt(intm); exponent = -m*V_i .*V_i; exponent = exponent/(2*k*T); exponent = exp(exponent); output_args = intmsqr*exponent; end
I then ran this function for a variety of input velocities, saved them and plotted them like this:
>> velocities=-1000:1000; >> results=mypdf(velocities); >> plot(results)
To my horror I simply get a perfectly symmetrical distribution rather than classic maxwell-boltzman shape.
I also tried simply plotting the speeds of particles using another matlab function:
function [ output_args ] = mb_speed( V_i ) %UNTITLED Summary of this function goes here % Detailed explanation goes here m=2.18e-25; k=1.38e-23; T=500; term1 = m/(2*pi*k*T); term1 = term1* term1 * term1; term1 = sqrt(term1); term2 = 4*pi*V_i .* V_i; term3 = -m*V_i.*V_i; term3= term3/2*k*T; term3 = exp(term3); output_args = term1 * term2 .* term3; end
I then plotted it using
>> speeds=0:1000; >> r2=mb_speed(speeds); >> plot(r2)
This just produces an exponential curve and not the classic shape.
What am I doing wrong in both of these cases?