
Regarding the graph, I would use pst-plot myself but many people use TikZ these days.
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
\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.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}
Then I suggest you start be reading some introduction manuals before going on to plotting functions. The following are excellent starting points IMHO:ghostanime2001 wrote:I am not familiar at all with tex sadly
ghostanime2001 wrote:what is /def ? I am not familiar at all with tex sadlyAlso 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}
\newcommand
doesn't overwrite existing commands for instance but \def
does) but that's it basically.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}
Not indefinitely but increasing the samples (i.e. the resolution at with the curve points are calculated) helps:ghostanime2001 wrote:[...] it draws corners at curves of functions. Is there a way to draw functions which has smooth points indefinitely ...
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}
I've never heard of it before but my favorite search engine tells me Reverse Polish Notation.ghostanime2001 wrote:By the way, what is RPN notation ?
svend_tveskaeg wrote:If you are not familiar with RPN notation, you can use the algebraic option for the plot command.
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