# plot line, combine graphics and Plot in Maxwell distribution

i'm trying to plot Maxwell distribution and draw a line where average speed varg, most probable speed vm, and rms speed vrms, and label those lines.

my struggle how to plot these lines and combine graphics with plot in Show.

here is the code easy and short!

k = 1.38064852*10^(-23);
m = 28*1.660538782*10^(-27);
t = 300;

max[v_] := ((m/2 Pi k t)^3/2 )*(4 Pi v^2) Exp[-((m*v^2)/(2 k t))]

p1 = Plot[max[v], {v, 0, 1200}]

vm = Sqrt[2 k t/m]
vrms = Sqrt[3 k t/ m]
vavg = Sqrt[8/Pi]*Sqrt[k t /m]

l1 = Graphics[Line[{vm, 0}, {vm, y}]]
l2 = Line[{0, vrms}]
l3 = Line[{0, vavg}]

Show[p1, l1] • Have you defined $y$? With no $y$ yet defined, l1 = Graphics[Line[{vm, 0}, {vm, y}]] will not be well defined. – mjw Mar 26 at 22:15
• Note the syntax for Line[{{x1, y1}, {x2, y2}}]: you are missing a set of braces; you should also probably use InfiniteLine here. – MarcoB Mar 26 at 22:54

With your definitions, consider something like this:

l1 = InfiniteLine[{{#, 0}, {#, 1}}] &[vm];
l2 = InfiniteLine[{{#, 0}, {#, 1}}] &[vrms];
l3 = InfiniteLine[{{#, 0}, {#, 1}}] &[vavg];

Show[
p1,
Graphics[{Red, l1, Blue, l2, Black, l3}]
] • One might also consider using GridLines. – J. M. is away Mar 27 at 1:25
• how do i label them !? – Alrubaie Mar 27 at 14:02

Your definition for max is not a valid PDF

max[v_] := ((m/2 Pi k t)^3/2)*(4 Pi v^2) Exp[-((m*v^2)/(2 k t))]


The total probability should be 1

Assuming[m > 0 && k > 0 && t > 0,
Integrate[max[v], {v, 0, Infinity}]]

(* (m^(3/2) π^(9/2) (k t)^(9/2))/(4 Sqrt) *)


You probably intended to use

max[v_] := (m/(2 Pi k t))^(3/2)*(4 Pi v^2) Exp[-((m*v^2)/(2 k t))]


This is a valid PDF

Assuming[m > 0 && k > 0 && t > 0,
Integrate[max[v], {v, 0, Infinity}]]

(* 1 *)


You would be better off using the built-in MaxwellDistribution

dist = MaxwellDistribution[Sqrt[k t/m]];


This has the same PDF as the revised max

Assuming[m > 0 && k > 0 && t > 0 && v > 0,
PDF[dist, v] == max[v] // Simplify]

(* True *)

vavg = Mean[dist]

(* 2 Sqrt[2/π] Sqrt[(k t)/m] *)

vrms = RootMeanSquare[dist]

(* Sqrt Sqrt[(k t)/m] *)


The mode is

vm = v /. Solve[{D[PDF[dist, v], v] == 0 &&
m > 0 && k > 0 && t > 0 && v > 0}, v][] //
Simplify[#, m > 0 && k > 0 && t > 0] &

(* Sqrt Sqrt[(k t)/m] *)

• Additionally, the "magic constants" in the OP are k = QuantityMagnitude[UnitConvert[Quantity[1, "BoltzmannConstant"]]] and m = QuantityMagnitude[UnitConvert[Quantity[28, "AtomicMassUnit"]]]. – J. M. is away Mar 27 at 1:22
• Thanks guys so much – Alrubaie Mar 27 at 14:21