## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Maxwell-Boltzmann Distribution Graph

Information and discussion about graphics, figures & tables in LaTeX documents.
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

### Re: Maxwell-Boltzmann Distribution Graph

Regarding the graph, I would use pst-plot myself but many people use TikZ these days.
In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Tags:

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am
is there a tikz generated package made for graphing functions of maxwell boltzmann graphs ? I have checked pst-plot but didn't find anything relevant.

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am
There are loads of relevant stuff for you in pst-plot; the graph can be drawn using the \psplot command. (See for example page 8--9 in the manual.) If you are not familiar with RPN notation, you can use the algebraic option for the plot command.

I do not know TikZ so I cannot help with this.
In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
This is easily done with the aforementioned pgfplots which is based on TikZ:

\documentclass{article} \usepackage{pgfplots}\pgfplotsset{   compat = 1.7 ,   yticklabel style = {/pgf/number format/.cd,fixed,fixed zerofill,precision=4} ,   samples = 100 ,   scaled ticks = false } \usepackage{chemmacros} \usepackage{siunitx}\sisetup{per-mode=symbol} \begin{document} \begin{tikzpicture}  % parameter:  \def\kB{1.3806488e-23}% boltzmann constant  \def\temperature{298}% room temperature  \def\Beta{1/(\kB*\temperature)}  \def\amu{1.660538921e-27}% atomar mass unit in kg  \def\HMass{2*\amu}% Hydrogen  \def\HeMass{4*\amu}% Helium  \def\OMass{32*\amu}% Oxygen  % plot:  \begin{axis}[     domain  = 0:5000 ,     xlabel  = $v$ in \si{\metre\per\second} ,     ylabel  = $P(v)$ ,     title   =       Maxwell-Boltzmann distribution of different gases at room temperature   ]   \addplot[color=red]     {sqrt(2/pi)*(\HMass*\Beta)^(3/2)*x^2*exp(-.5*\HMass*\Beta*x^2)} ;   \addplot[color=yellow]     {sqrt(2/pi)*(\HeMass*\Beta)^(3/2)*x^2*exp(-.5*\HeMass*\Beta*x^2)} ;   \addplot[color=blue]     {sqrt(2/pi)*(\OMass*\Beta)^(3/2)*x^2*exp(-.5*\OMass*\Beta*x^2)} ;   \legend{\ch{H2},\ch{He},\ch{O2}}  \end{axis}\end{tikzpicture} \begin{tikzpicture}  % parameter:  \def\kB{1.3806488e-23}% boltzmann constant  \def\hundredK{100}% 100 K  \def\rt{300}% ~ room temperature  \def\thousandK{1000}% 100 K  \def\Beta#1{1/(\kB*#1)}  \def\amu{1.660538921e-27}% atomar mass unit in kg  \def\HMass{2*\amu}% Hydrogen  % plot:  \begin{axis}[     domain  = 0:8000 ,     xlabel  = $v$ in \si{\metre\per\second} ,     ylabel  = $P(v)$ ,     title   =       Maxwell-Boltzmann distribution for Hydrogen at different temperatures   ]   \addplot[color=red]     {sqrt(2/pi)*(\HMass*\Beta{\hundredK})^(3/2)*x^2*exp(-.5*\HMass*\Beta{\hundredK}*x^2)} ;   \addplot[color=yellow]     {sqrt(2/pi)*(\HMass*\Beta{\rt})^(3/2)*x^2*exp(-.5*\HMass*\Beta{\rt}*x^2)} ;   \addplot[color=blue]     {sqrt(2/pi)*(\HMass*\Beta{\thousandK})^(3/2)*x^2*exp(-.5*\HMass*\Beta{\thousandK}*x^2)} ;   \legend{\SI{100}{\kelvin},\SI{300}{\kelvin},\SI{1000}{\kelvin}}  \end{axis}\end{tikzpicture} \end{document}

mbd.png (33.88 KiB) Viewed 6973 times

Regards
site moderator & package author

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am
what is /def ? I am not familiar at all with tex sadly Also the x-axis is in velocity (m/s) but I wanted kinetic energy so shouldn't the equation used to compute the graph be different as well ?

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am
ghostanime2001 wrote:I am not familiar at all with tex sadly

Then I suggest you start be reading some introduction manuals before going on to plotting functions. The following are excellent starting points IMHO:

In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
ghostanime2001 wrote:what is /def ? I am not familiar at all with tex sadly Also the x-axis is in velocity (m/s) but I wanted kinetic energy so shouldn't the equation used to compute the graph be different as well ?



There are more differences (\newcommand doesn't overwrite existing commands for instance but \def does) but that's it basically.

About the question of energy versus velocity distribution: that's really up to you which function to plot. I wanted to show you an example of how plotting a function could be done. If you want to plot a different function just do so. All the settings I used you can find in pgfplots documentation so you at least have the chance to get started.

You can always ask follow up question if you're struggling with the details.

Regards
site moderator & package author

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am
What I don't like about latex and these packages (pst-plot, pgfplots etc..) is that when you try to plot a function, it draws corners at curves of functions. Is there a way to draw functions which has smooth points indefinitely so that when you try to zoom on a portion of that function, the points are not zig-zagged (for example with sin function)? Please see attached example. Maybe there's a software that allows me to customize latex parameters just like if I was drawing a function with latex only ?

By the way, what is RPN notation ? Also, in pst-plot the pi x-axis ticks are a bit offset to the right, does the package automatically do this ? or can it be perfectly center aligned with the x-axis tick mark ?

here is the code I compiled to get the attached PDF:
\documentclass{article}\usepackage{etex}\usepackage{pgfplots}\begin{document}\begin{tikzpicture}\begin{axis}\addplot[red] {sin(deg(x))};\end{axis}\end{tikzpicture}\end{document}
Attachments
untitled-1.pdf

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
ghostanime2001 wrote:[...] it draws corners at curves of functions. Is there a way to draw functions which has smooth points indefinitely ...

Not indefinitely but increasing the samples (i.e. the resolution at with the curve points are calculated) helps:

\documentclass{article}\usepackage{etex}\usepackage{pgfplots}\begin{document}\begin{tikzpicture}\begin{axis}\addplot[red,samples=100] {sin(deg(x))};\end{axis}\end{tikzpicture}\end{document}

ghostanime2001 wrote:By the way, what is RPN notation ?
I've never heard of it before but my favorite search engine tells me Reverse Polish Notation.

Regards
site moderator & package author

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am