LaTeX forum ⇒ 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

Re: Maxwell-Boltzmann Distribution Graph

Postby svend_tveskaeg » Tue Jan 22, 2013 1:43 am

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)

Tags:

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

Postby ghostanime2001 » Tue Jan 22, 2013 1:48 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.

User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Postby svend_tveskaeg » Tue Jan 22, 2013 2:25 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)

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Tue Jan 22, 2013 3:00 am

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

  1. \documentclass{article}
  2.  
  3. \usepackage{pgfplots}
  4. \pgfplotsset{
  5. compat = 1.7 ,
  6. yticklabel style = {/pgf/number format/.cd,fixed,fixed zerofill,precision=4} ,
  7. samples = 100 ,
  8. scaled ticks = false
  9. }
  10.  
  11. \usepackage{chemmacros}
  12.  
  13. \usepackage{siunitx}
  14. \sisetup{per-mode=symbol}
  15.  
  16. \begin{document}
  17.  
  18. \begin{tikzpicture}
  19. % parameter:
  20. \def\kB{1.3806488e-23}% boltzmann constant
  21. \def\temperature{298}% room temperature
  22. \def\Beta{1/(\kB*\temperature)}
  23. \def\amu{1.660538921e-27}% atomar mass unit in kg
  24. \def\HMass{2*\amu}% Hydrogen
  25. \def\HeMass{4*\amu}% Helium
  26. \def\OMass{32*\amu}% Oxygen
  27. % plot:
  28. \begin{axis}[
  29. domain = 0:5000 ,
  30. xlabel = $v$ in \si{\metre\per\second} ,
  31. ylabel = $P(v)$ ,
  32. title =
  33. Maxwell-Boltzmann distribution of different gases at room temperature
  34. ]
  35. \addplot[color=red]
  36. {sqrt(2/pi)*(\HMass*\Beta)^(3/2)*x^2*exp(-.5*\HMass*\Beta*x^2)} ;
  37. \addplot[color=yellow]
  38. {sqrt(2/pi)*(\HeMass*\Beta)^(3/2)*x^2*exp(-.5*\HeMass*\Beta*x^2)} ;
  39. \addplot[color=blue]
  40. {sqrt(2/pi)*(\OMass*\Beta)^(3/2)*x^2*exp(-.5*\OMass*\Beta*x^2)} ;
  41. \legend{\ch{H2},\ch{He},\ch{O2}}
  42. \end{axis}
  43. \end{tikzpicture}
  44.  
  45. \begin{tikzpicture}
  46. % parameter:
  47. \def\kB{1.3806488e-23}% boltzmann constant
  48. \def\hundredK{100}% 100 K
  49. \def\rt{300}% ~ room temperature
  50. \def\thousandK{1000}% 100 K
  51. \def\Beta#1{1/(\kB*#1)}
  52. \def\amu{1.660538921e-27}% atomar mass unit in kg
  53. \def\HMass{2*\amu}% Hydrogen
  54. % plot:
  55. \begin{axis}[
  56. domain = 0:8000 ,
  57. xlabel = $v$ in \si{\metre\per\second} ,
  58. ylabel = $P(v)$ ,
  59. title =
  60. Maxwell-Boltzmann distribution for Hydrogen at different temperatures
  61. ]
  62. \addplot[color=red]
  63. {sqrt(2/pi)*(\HMass*\Beta{\hundredK})^(3/2)*x^2*exp(-.5*\HMass*\Beta{\hundredK}*x^2)} ;
  64. \addplot[color=yellow]
  65. {sqrt(2/pi)*(\HMass*\Beta{\rt})^(3/2)*x^2*exp(-.5*\HMass*\Beta{\rt}*x^2)} ;
  66. \addplot[color=blue]
  67. {sqrt(2/pi)*(\HMass*\Beta{\thousandK})^(3/2)*x^2*exp(-.5*\HMass*\Beta{\thousandK}*x^2)} ;
  68. \legend{\SI{100}{\kelvin},\SI{300}{\kelvin},\SI{1000}{\kelvin}}
  69. \end{axis}
  70. \end{tikzpicture}
  71.  
  72. \end{document}


mbd.png
mbd.png (33.88 KiB) Viewed 6558 times


Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

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

Postby ghostanime2001 » Tue Jan 22, 2013 7: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 ?

User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Postby svend_tveskaeg » Tue Jan 22, 2013 7:53 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)

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Tue Jan 22, 2013 11:37 am

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>}.

  1. \def\foo{bar} = \newcommand*\foo{bar}
  2. \long\def\ff{bar} = \newcommand\foo{bar}
  3. \def\foo#1{bar: #1} = \newcommand\foo[1]{bar: #1}
  4. \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
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

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

Postby ghostanime2001 » Sun Mar 24, 2013 7:15 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:
  1. \documentclass{article}
  2. \usepackage{etex}
  3. \usepackage{pgfplots}
  4. \begin{document}
  5. \begin{tikzpicture}
  6. \begin{axis}
  7. \addplot[red] {sin(deg(x))};
  8. \end{axis}
  9. \end{tikzpicture}
  10. \end{document}
Attachments
untitled-1.pdf
(24.65 KiB) Downloaded 201 times

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Sun Mar 24, 2013 1: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:

  1. \documentclass{article}
  2. \usepackage{etex}
  3. \usepackage{pgfplots}
  4. \begin{document}
  5. \begin{tikzpicture}
  6. \begin{axis}
  7. \addplot[red,samples=100] {sin(deg(x))};
  8. \end{axis}
  9. \end{tikzpicture}
  10. \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
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

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

Postby ghostanime2001 » Sun Mar 24, 2013 9:41 pm

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.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 3 guests