[Pgfplots-features] calculating coordinates

View: New views
1 Messages — Rating Filter:   Alert me  

[Pgfplots-features] calculating coordinates

by Stefan Pinnow :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,
I have to create come plots like the one below, where I have to mark
some of the points along the path with nodes.

As an example I attached the Maxwell-Boltzmann distribution of the room
symmetric velocities. A point of interest now could be the most probable
velocity which can be directly calculated.

I tried to precalculate this value and use it later on as a coordinate, but
without success. I also tried to use the fpu library to avoid "Dimension too
large" errors also without success. And when we are at that topic I also tried
some other stuff and have some questions about them.

I tried to document as much as possible with a single comment sign (%) so you
can follow the code. My comments and questions for you start with double
comment signs (??).

Thank you in advance for your help and comments.


Best regards
Stefan Pinnow


\documentclass{article}
    \usepackage{amsmath}
    \usepackage{tikz,pgfplots}
        \usetikzlibrary{calc,fpu}
\begin{document}
    \begin{tikzpicture}[
    % just a style to use it later on
        dot/.style={
            inner sep=0pt,
            circle,
            minimum size=6pt,
            fill=red,
        }
    ]

            % calculation of the distribution of the room symmetric velocities
            %
(http://en.wikipedia.org/wiki/Maxwell%E2%80%93Boltzmann_distribution)
            %
            \def\M{0.028}       % molar mass in kg/mol
            \def\R{8.3145}      % universal gas constant in J/(mol*K)
            \def\TT{1000}       % temperature in K

            %% to try to avoid the "Dimension too large" error the fpu library
is activated
            %% but this doesn't work ...
                \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=sci}
%                    \def\XX{\pgfmathparse{sqrt(8/pi*\R*\TT/\M)}\pgfmathresult}
 
\def\XX{\pgfmathparse{sqrt(8/pi*\R/10000*\TT/\M)*100}\pgfmathresult}
                %% \ZZ is result of \XX, but because \XX can't be used later in
coordinates (see below)
                    \def\ZZ{867.2}
%                %% would be nice if this would work
%                    \def\YY{\pgfmathparse{4*pi * (\M/2/pi/\R/\TT*1e8)^1.5 *
\XX^2 * exp(-\M*\XX^2/(2*\R*\TT)) * 1e-8}\pgfmathresult}
                %% only because the above doesn't work
                    \def\YY{10.45}
%                %% now jsut follows a test which doesn't work.
%                %% Is there a possibility to (pre-)calculate values from other
values?
%                %% --> uncomment the node below to see the error
%                    \def\WW{\pgfmathparse{\XX*2}\pgfmathresult}
                \pgfkeys{/pgf/fpu=false}

        % values as \def so they can be reused inside the picture later on
            \def\xmin{0}
            \def\xmax{2500}
            \def\ymin{0}
            \def\ymax{20}

        \begin{axis}[
                no markers,
                %
                xmin=\xmin,     xmax=\xmax,
                ymin=\ymin,     ymax=\ymax,
                %
                xlabel={$u$ \big/ $\dfrac{\text{m}}{\mathrm{s}}$},
                ylabel={$10^4 \, \dfrac{\mathrm{d} N(u)}{N \mathrm{d} u}$ \big/
$\dfrac{\mathrm{s}}{\mathrm{m}}$},
                %
                domain=\xmin:\xmax,
                samples=101,
                %
                name=Maxwell-Boltzmann_u
        ]

        % function plot with nodes
            \addplot plot [id=MB_u_T1000]  function
                {4*pi * (\M/2/pi/\R/\TT)**1.5 * x**2 * exp(-\M*x**2/(2*\R*\TT))
* 1e4}
                %% node at the end of the plot is ok
                    node [dot,fill=green]         {$\TT\,\text{K}$}
                %% node at the beginning of the plot is not ok.
                %% I think that is because of the way the plot is drawn,
correct?
                    node [dot,fill=green,pos=0.5] {$\TT\,\text{K}$};

        %% because the line above doesn't work as thought, the label has to be
set by hand
            \node [anchor=west] at (axis cs: 1300,5) {$\TT\,\text{K}$};

%        %% just a test node for the above \WW
%            \node [align=center] at (axis cs:\WW,10) {test not \\ successful};

        %% here I want to calculate the most propable value, but I can only
calculate the
        %% x value, because I need to insert the complete equation here. But for
sake I need the
        %% calculated x value to calculate its y value ...
        %% (and in addition I have to trick a little bit with some 1eX, so I
don't get the
        %%  "Dimension too large" error --> see the /10000 inside the sqrt and
*100 afterwards
        %%  this wouldn't be needed, if the values could be precalculated.)
            \node [anchor=north west,align=left] at
                ($ sqrt(8/pi*\R/10000*\TT/\M)*100*(axis cs:1,0) + (axis cs:0,20)
$) {\XX \\ \YY};

        % help line from point to the xaxis
            \draw [help lines] (axis cs:\ZZ,0)   to
                               (axis cs:\ZZ,\YY) node [dot] {};

%        %% leads to error: "Incomplete \iffalse; all text was ignored after
line [...]"
%        %% is there another way of using some precalculated values for
coordinates?
%            \node at ($ (axis cs:\XX,0) + (axis cs:0,15) $) {\XX};
%        %% the precalculated value is needed, because here I need it to
calculate the Y value
%            \node [dot,minimum size=3pt,fill=yellow]
                 at ($ sqrt(8/pi*\R/10000*\TT/\M)*100*(axis cs:1,0) +
%
4*pi*(\M/2/pi/\R/\TT*1e8)^1.5*x^2*exp(-\M*x**2/(2*\R*\TT))*(axis cs:0,1e-8) $)
{};
%
%        %% the last question is: Can one somehow access a certain index in the
created gnuplot file?
%        %% so let's say for some reason the 5th row coordinate needs a node
%        %% the same question holds for \addplot table's

        \end{axis}
    \end{tikzpicture}
\end{document}


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

smime.p7s (5K) Download Attachment