Graphics, Figures & TablesMaxwell-Boltzmann Distribution Graph

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

Maxwell-Boltzmann Distribution Graph

Post by svend_tveskaeg »

Please ask in physics fora for questions like the last one. ;)

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)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

Re: Maxwell-Boltzmann Distribution Graph

Post by ghostanime2001 »

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.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Maxwell-Boltzmann Distribution Graph

Post by svend_tveskaeg »

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)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Maxwell-Boltzmann Distribution Graph

Post by cgnieder »

This is easily done with the aforementioned pgfplots which is based on TikZ:

Code: Select all

\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
mbd.png (33.88 KiB) Viewed 11514 times
Regards
site moderator & package author
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Maxwell-Boltzmann Distribution Graph

Post by ghostanime2001 »

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 ?
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Maxwell-Boltzmann Distribution Graph

Post by svend_tveskaeg »

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)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Maxwell-Boltzmann Distribution Graph

Post by cgnieder »

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 ?
\def is a TeX's low level command for LaTeX's \newcommand*. It can be replaced by the latter in every case except \def#1{<foo bar>} which needs to be replaced with \newcommand*\foo[1]{<foo bar>}.

Code: Select all

\def\foo{bar} = \newcommand*\foo{bar}
\long\def\ff{bar} = \newcommand\foo{bar}
\def\foo#1{bar: #1} = \newcommand\foo[1]{bar: #1}
\def\foo#1#2{bar: #1 and #2} = \newcommand\foo[2]{bar: #1 and #2}
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

Maxwell-Boltzmann Distribution Graph

Post by ghostanime2001 »

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:

Code: Select all

\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
(24.65 KiB) Downloaded 487 times
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Maxwell-Boltzmann Distribution Graph

Post by cgnieder »

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:

Code: Select all

\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

Maxwell-Boltzmann Distribution Graph

Post by ghostanime2001 »

I asked about RPN because another member said this.
svend_tveskaeg wrote:If you are not familiar with RPN notation, you can use the algebraic option for the plot command.
Post Reply