[go: up one dir, main page]

Menu

[r56]: / docs / eqc-tour.eqc  Maximize  Restore  History

Download this file

855 lines (748 with data), 31.9 kB

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{../examples/eqc}
\usepackage{pstricks}
\usepackage{pst-plot}

\pagestyle{headings}
\setlength{\parindent}{0pt}
\setlength{\parskip}{5pt plus 2pt minus 3pt}
\frenchspacing
\sloppy

% Einstellungen für 2.5 cm Rand links, 1.5 cm Rand rechts, 2 cm Rand oben und
% unten
\addtolength{\oddsidemargin}{-22mm} %-4mm bei 600dpi
\addtolength{\textwidth}{48.5mm}
\addtolength{\topmargin}{-14mm} %+15mm bei 600dpi
\addtolength{\textheight}{37mm}

\newcommand{\kw}[1]{{\bf$\backslash$#1}}

\begin{document}


\newcommand{\Euler}{\gamma_E}% *** added in 1.3.0
\newcommand{\e}{e}%

% Different version of tangent function
%*** added in 1.0
\newcommand{\mindex}[3]{#1\left[ #2 , #3\right]}%for raw printing mode
\newcommand{\transpose}[1]{\left(#1\right)^T}% for raw printing mode
\newcommand{\vecprod}[2]{#1 \times #2}% for raw printing mode
\newcommand{\scalprod}[2]{#1 #2}% for raw printing mode
\newcommand{\ifelse}[3]{#1 ? #2 : #3}% for raw printing mode
\newcommand{\vmax}[1]{\vmax(#1)}% for raw printing mode
%         
\newcommand{\vmin}[1]{\vmin(#1)}% for raw printing mode
\newcommand{\diff}[3]{\frac{d^{#3} #1}{d #2^{#3}}}%for raw printing mode
 % This must be defined first because it is used by the other functions!
\newcommand{\arccot}{{\ensuremath\mbox{arccot}}}%






\defunit{\m}{\metre}
\defunit{\kg}{\kilogram}
\defunit{\s}{\second}
\defunit{\A}{\ampere}
\defunit{\K}{\kelvin}
\defunit{\mol}{\mole}
\defunit{\cd}{\candela}


\defunit{\rad}{rad}
\defunit{\sr}{\steradian}
\defunit{\Hz}{\hertz}
\defunit{\N}{\newton}
\defunit{\Pa}{\pascal}
\defunit{\J}{\joule}
\defunit{\W}{\watt}
\defunit{\C}{\coulomb}
\defunit{\V}{\volt}
\defunit{\F}{\farad}
\defunit{\S}{\siemens}
\defunit{\Wb}{\weber}
\defunit{\T}{\tesla}
\defunit{\H}{\henry}
\defunit{\lm}{\lumen}
\defunit{\lx}{\lux}
\defunit{\Bq}{\becquerel}
\defunit{\Gy}{\gray}
\defunit{\Sv}{\sievert}


\defunit{\min}{\minute}
\defunit{\h}{\hour}
\defunit{\d}{\dday}
\defunit{\t}{\tonne}
\defunit{\u}{\atomicmass}

\defunit{\nauticalmile}{nauticalmile}
\defunit{\knot}{knot}
\defunit{\rd}{rd} %to avoid confusion with angular unit rad

\defunit{\mm}{\milli\metre}
\defunit{\cm}{\centi\metre}
\defunit{\sqmm}{\square{\mm}}
\defunit{\Nm}{\N\usk\m}
\defunit{\Nosqmm}{{\ensuremath{\frac{\N}{\sqmm}}}}%added \ensuremaths in 0.4
\defunit{\percent}{\%}%added in 0.5
\defunit{\kW}{\kilo\watt}
\defunit{\kWh}{\kilo\watt \hour}
\defunit{\kN}{\kilo\newton}
\defunit{\rpm}{RPM}
\defunit{\hp}{HP}
\defunit{\ft}{ft}





\title{Tour of EQC functionality}
\author{Jan Rheinländer}
\maketitle
\tableofcontents \clearpage
\setcounter{section}{0}

\section{Numeric evalution of equations}
EQC adds the power of a spreadsheet to Latex. It is possible to write down equations and
obtain the numerical value of variables:
\begin{verbatim}
$$\eq{x = 3}$$
$$\eq{y = 4}$$
$$\eq{z = \sqrt{x^2 + y^2}} = \val{z}$$
\end{verbatim}
$${}x = 3$$
$${}y = 4$$
$${}z = \sqrt{x^2 + y^2} = 5$$

If you only want to do a numerical calculation in your text, using the \kw{val} keyword is sufficient. 
\begin{verbatim}
The square root of two is \val{\sqrt{2}}.
\end{verbatim}
The square root of two is 1.414.

Equations can be assigned a label to reuse them later on:

\begin{verbatim}
\begin{equation}
\eq[eq:important]{a = x + 2}
\end{equation}
\centerline{\emph{Equation \ref{eq:important} defines the value of a
to be $\printeq{"eq:important"} = \val{a}$.}}
\end{verbatim}

\begin{equation}
{}a = x + 2\label{eq:important}
\end{equation}
\centerline{\emph{Equation \ref{eq:important} defines the value of a
to be ${}a = x + 2 = 5$.}}

If you want to use mathematical or physical constants in your equations, define them with the
\kw{constant} keyword. The file mathconstants.tex contains definitions for the most common constants
$\pi$ and $e$.

\begin{verbatim}
$$\constant{\Pi = 3.141}$$
$$\eq{r = 3}$$
$$\eq{d = 2\Pi r} = \val{d}$$
\end{verbatim}

$${}\Pi = 3.141$$
$${}r = 3$$
$${}d = 2\Pi r = 18.85$$

Equations can take an optional list of options, for example,
\verb|\eq[label=eq:x; eqraw=false]{x = y^2}|. The options will apply only to
this specific equation. Some of the available options are:
\begin{description}
\item[units = \{unit; unit; ...\}] Tell EQC what units it should use in the output. 
\item[precision = integer] The precision (total number of digits) with which floating
  point numbers are printed. 
\item[fixeddigits = true|false] You can decide whether you want to round
  all numbers to a fixed number of digits (e.g., 12345 rounded to a precision of
  three would be 12300) or whether to display
  a fixed number of digits after the decimal marker.
\item[lowsclimit = real] It is possible to control which numbers are printed in
  scientific notation (e.g., $1.23 \cdot 10^5$). This options give the smallest
  number that is still printed normally.
\item[highsclimit = real] This options give the largest
  number that is still printed normally.
\item[eqalign = none|eqnarray|ams] This option controls equation
  formatting. \verb|none| prints no ampersands, 
  \verb|eqnarray| prints ampersands on both sides of the equals sign
  (\verb|&=&|), and \verb|ams| prints an ampersand before the equals sign
  (\verb|&=|). By default, EQC automatically adds ampersands to your equations
  depending on the environment they appear in.
\item[eqchain = true|false] Omits the left hand side of an equation if it is
  identical to the left hand side of the equation directly preceding it in an
  \verb|eqnarray| or AMS environment.
\item[eqraw = true|false] Print equations as you typed them (if possible), or
  with EQC formatting.
\end{description}
The keyword \kw{eqcoptions} can be used to set these options globally.

\section{Working with physical quantities}
EQC adds the class Unit to the functionality of the GiNaC library. This means that you can use units
in a natural way inside equations:

\begin{verbatim}
\clearequations
\eqcoptions{units = {\mm}}
$$\eq{x = \unit{3}{\mm}}$$
$$\eq{y = \unit{4}{\mm}}$$
$$\eq{z = x + y} = \quantity{z}$$
\end{verbatim}

$${}x = \unit{3}{\mm}$$
$${}y = \unit{4}{\mm}$$
$${}z = x + y = \unit{7}{\,\mm }$$

Upon startup, EQC knows only the base SI units. To get full support for all units defined in the
SIunits.sty package, include units.tex at the beginning of your document. New units can easily be
defined using the \kw{defunit} keyword. For example:

\begin{verbatim}
\defunit['']{\inch}{2.54\mm}
\eqcoptions{units = {\inch}}
$$z = x + y = \quantity{z}$$
\end{verbatim}

\defunit{\inch}{''}
$$z = x + y = \unit{2.756}{\,\inch }$$

The option \verb|units| tells EQC what units it should use in the output. If no
units are given, EQC will use the SI base units. The units can also be given as an optional
argument to the \kw{val} keyword (and will only apply to that specific value):

\begin{verbatim}
\defunit['']{\inch}{2.54\mm}
\eqcoptions{units = {\inch}}
$$z = x + y = \quantity{z} = \quantity[units = {\mm}]{z}$$
\end{verbatim}

$$z = x + y = \unit{2.756}{\,\inch } = \unit{7}{\,\mm }$$
A short form also exists, with the syntax \verb|\quantity[\mm]{z}|.

Note that there are four different keywords that can be used for finding the
value of a variable: 
\begin{description}
\item[numval] This prints a numeric value, or prints an error if the
  variable does not have one.
\item[units] Prints only the units of the variable.
\item[quantity] Prints a numeric value plus units (if there are any).
\item[val] Prints any kind of symbolic expression
\end{description}


\section{User defined functions}
EQC extends GiNaC by offering user-defined functions which can be created at runtime in the Latex
file. A function is declared using the \kw{function} keyword. A definition for the function may
be given with \kw{deffunc}, but this is not strictly necessary. Of course, only functions with
definitions can be evaluated!

Functions can be given ``hints'' when they are defined using the syntax
\verb|\function[hintlist]...|. Hints enable EQC to handle and print functions
better. For example, the hint \verb|trig| will result in the function being
printed as $\sin^2 x$ instead of $(\sin(x))^2$.

Consider the function
\begin{verbatim}
\function{f}{x}
$$\deffunc{f}{ax^2 + bx + c}$$
\end{verbatim}
$${}f=ax^2 + bx + c$$

\begin{verbatim}
With $\eq{a = 4}$, $\eq{b = -2}$ and $\eq{c = 7}$ we can compute $f(x)$ for $x = 3$:
$$f(x) = \val{f(x)}$$
$$f(3) = \val{f(3)} = \numval{\val{f(3)}}$$
\end{verbatim}
With ${}a = 4$, ${}b = -2$ and ${}c = 7$ we can compute $f(x)$ for $x = 3$:
$$f(x) = 7+4\,x^{2} -2\,x  $$
$$f(3) = c+3\,b +9\,a   = 37$$
Note what effect the \kw{val} statement has on the different parameters. To both expand the function 
and substitute the values of known variables, a double \kw{val} statement is necessary.

\section{Asking for values of variables}
Most documents will be of the type that define a number of equations
and then try to calculate numeric values for the variables used in
these equations. There are several methods of doing this efficienctly:
\begin{itemize}
\item The most straight-forward way is to define an equation and
  then other equations that give the known values of variables. The
  \kw{val} statement can then be used to calculated the values of
  unkown variables.
\begin{verbatim} 
\begin{eqnarray*}  
    \eq{x = 3y + 4}\\
    \eq{y = 5}\\
    x &=& \numval{x}
  \end{eqnarray*}
\end{verbatim}
  \begin{eqnarray*}
    {}x &=& 3y + 4\\
    {}y &=& 5\\
    x &=& 19
  \end{eqnarray*}
  This method becomes awkward if you want to ask for the value of $x$
  again, using a different value for $y$. You would have to delete the
  equation defining $y$ and create a new one.
\item If you need the value of a variable for many different
  parameters, the best way is to define a function.
\begin{verbatim}
\clearequations
\begin{eqnarray*}
  \function{x}{y}%
  \deffunc{x}{3y+4}\\
  x &=& \val{x(5)}\\
  x &=& \val{x(7)}\\
\end{eqnarray*}
\end{verbatim}
  
  \begin{eqnarray*}
    %
    {}x&=&3y+4\\
    x &=& 19\\
    x &=& 25\\
  \end{eqnarray*}
  The only drawback is that you cannot easily substitute the
  definition $x = 3y+4$ into other equations. You would have to do
  something like \verb|\eqsubst{z = 3x}{x = \val{x}}|.
\item The last way is to use the \verb|with|-form of the \kw{val}
  statement.
  \begin{verbatim}
\clearequations%
\begin{eqnarray*}
  \eq{x = 3y + 4}\\
  x &=& \numvalwith{x}{y = 5}\\
  x &=& \numvalwith{x}{y = 7}\\
\end{eqnarray*}
\end{verbatim}
  %
  \begin{eqnarray*}
    {}x &=& 3y + 4\\
    x &=& 19\\
    x &=& 25\\
  \end{eqnarray*}
  All the assignments given as the second argument are defined as
  equations, the search for the value is  performed, and then the
  temporary equations are deleted  again. Therefore, you can find even
  values of variables that are indirectly defined: 
\begin{verbatim}
\clearequations
\begin{eqnarray*}
  \eq{x = 3y + 4}\\
  \eq{z = 4x}\\
  z &=& \numvalwith{z}{y = 5}\\
\end{eqnarray*}
\end{verbatim}
  
  \begin{eqnarray*}
    {}x &=& 3y + 4\\
    {}z &=& 4x\\
    z &=& 76\\
  \end{eqnarray*}
\end{itemize}
    
\section{Symbolic computations} 
EQC offers the possibility of symbolic manipulation of equations. You can use it to add,
subtract, multiply or divide an equation with an expression. Also, it is possible to substitute an
expression with another expression, and to differentiate an expression.

\subsection{Example: Solving a quadratic equation}
Consider the equation
\begin{verbatim}
\clearequations
\function{f}{x}
$$\deffunc{f}{ax^2 + bx + c} = 0$$
\end{verbatim}
$${}f=ax^2 + bx + c = 0$$
What values of x will solve this equation?

We need to bring the equation into the form $x^2 + 2 A x + A^2 = B$, which can then be written as
$(x + A)^2 = B$ and solved.

\begin{verbatim}
$$\eqdiv{\val{f(x)} = 0}{a}, a \ne 0$$
$$\eqadd{"prev"}{(1/2 b/a)^2 - c/a}$$
$$\eqsimpf{"prev"}{expand}$$
\end{verbatim}
$${}\frac{1}{a}\,\left(c+a\,x^{2} +x\,b  \right)  =0, a \ne 0$$
$${}\frac{1}{a}\,\left(c+a\,x^{2} +x\,b  \right)  +\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} =\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} $$
$${}x^{2}+\frac{x\,b }{a}+\frac{1}{4}\frac{b^{2} }{a^{2} } =\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} $$

The special equation label \verb|"prev"| is a shortcut to access the last
equation processed by EQC. With \kw{eqsimpf} it is possible to do a variety of
simplifications on the equation:
\begin{description}
\item[expand] Fully expands all expressions, including function arguments.
\item[expandf] Only expand function definition, not arguments.
\item[eval] Numerically evaluate the equation as far as possible.
\item[normal] Normalize the equation, that is, force all terms to have a common
  denominator (see description of GiNaC's \verb|normal()| method for details).
\item[collect-common] Collect common factors from all terms of the equation (see
  description of GiNaC's \verb|collect_common_factors()| method for details).
\item[unsafe] Do unsafe simplifications, for example, $\sqrt{x^2} = x$ and
  $\arctan\tan{x} = x$. Note that the opposite, $\tan\arctan{x}$, is not unsafe
  and thus is done automatically (by GiNaC).
\end{description}

As can be seen, $A = \frac{1}{2}\frac{b}{a}$ and $B = (\frac{1}{2}\frac{b}{a})^2 - \frac{c}{a}$. The
equation can now be written as:

\begin{verbatim}
$$\eq{\left(x + \frac{1}{2}\frac{b}{a}\right)^2 = \rhs{"prev"}}$$
\end{verbatim}
$${}\frac{1}{4}\,{\left(\frac{b}{a}+2\,x  \right)}^{2} =\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} $$

Applying the square root to both sides yields the two solutions:

\begin{verbatim}
$$\eqpow{"prev"}{1/2}$$
$$\eqsimpf[eq:poss1]{"prev"}{unsafe}$$
$$\mbox{or}\quad\eq[eq:poss2]{\lhs{"prev"} = -\rhs{"prev"}}$$
\end{verbatim}

$${}\frac{1}{2}\,\sqrt{{\left(\frac{b}{a}+2\,x  \right)}^{2}} =\sqrt{\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} }$$
$${}x+\frac{b }{2\,a } =\sqrt{\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} }\label{eq:poss1}$$
$$\mbox{or}\quad{}x+\frac{b }{2\,a } =-\sqrt{\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} } \label{eq:poss2}$$

The two possible values for $x$ are therefore:
\begin{verbatim}
\eqsubst*[eq:temp1]{"eq:poss1"}{x = x_1}
\eqsubst*[eq:temp2]{"eq:poss2"}{x = x_2}
\end{verbatim}

\begin{verbatim}
$$\eqsub[eq:sol1]{"eq:temp1"}{\frac{b}{2a}}$$
$$\eqsub[eq:sol2]{"eq:temp2"}{\frac{b}{2a}}$$
\end{verbatim}
$${}x_1=\sqrt{\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} }-\frac{b }{2\,a } \label{eq:sol1}$$
$${}x_2=-\frac{b }{2\,a }-\sqrt{\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} } \label{eq:sol2}$$

A faster way to achieve the same result is by using \kw{eqsolve}.
\begin{verbatim}
$$\eqsubst{\eqsolve{f(x) = 0}{x}{1}}{x = x_1}$$
$$\eqsubst{\eqsolve{f(x) = 0}{x}{2}}{x = x_2}$$
\end{verbatim}
$${}x_1=\sqrt{\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} }-\frac{b }{2\,a } $$
$${}x_2=-\frac{b }{2\,a }-\sqrt{\frac{1}{4}\frac{b^{2} }{a^{2} }-\frac{c}{a} } $$

With, for example, ${}a = 3\label{eq:a}$, ${}b = 4\label{eq:b}$ and 
${}c = -5\label{eq:c}$ the possible values for $x$ are:

\begin{verbatim}
$$x_1 = \numval[3]{x_1}$$
$$x_2 = \numval[3]{x_2}$$
\end{verbatim}
$$x_1 = 0.786$$
$$x_2 = -2.12$$
The \verb|3| option to \kw{numval} sets the precision to three digits, it is
equivalent to writing \verb|\numval[precision=3]{x_1}|.

When applying $f(x)$ on these values of $x$, the result is (almost) zero:
\begin{verbatim}
$$f(x_1) = \numval{f(x_1)}$$
$$f(x_2) = \numval{f(x_2)}$$
\end{verbatim}
$$f(x_1) = -1.776\cdot 10^{-15}$$
$$f(x_2) = 0$$

\subsection{Example: Finding the extrema of a function}
To find the extrema of $f(x)$, we set the first derivative to zero and solve for
$x$:
\begin{verbatim}
\deleq{"eq:a";"eq:b";"eq:c"}
$$\eq[eq:f]{f(x) = \val{f(x)}}$$
$$\eqdiff{"eq:f"}{x} = 0$$
\eqsub*{\rhs{"prev"} = 0}{b}%
\eqsubst*{"prev"}{x = x_{extr}}%
$$\eqdiv[eq:xextr]{"prev"}{2a}$$
\end{verbatim}
$${}f{\left(x\right)}=c+a\,x^{2} +x\,b  \label{eq:f}$$
$${}f'{\left(x\right)}=b+2\,a\,x  \label{eq:fdiff} = 0$$
$${}x_{extr}=-\frac{b }{2\,a }\label{eq:xextr}$$

Depending on the sign of the second derivate ${}f''{\left(x\right)}=2\,a $, this will
be a minimum or a maximum. The value of the extremum is
\begin{verbatim}
$$\eqsubstc[eq:yextr]{y_{extr} = \rhs{"eq:f"}}{x = x_{extr}; "eq:xextr"}$$
\end{verbatim}
$${}y_{extr}=c-\frac{1}{4}\frac{b^{2} }{a } \label{eq:yextr}$$
or with the values used in the previous section ${}a = 3$, ${}b = 4$ and
${}c = -5$: 
\begin{verbatim}
$$x_{extr} = \numval{x_{extr}}\quad y_{extr} = \numval{y_{extr}}$$
\end{verbatim}
$$x_{extr} = -0.6667\quad y_{extr} = -6.333$$

\subsection{Library of substititions}
To make working with equations easier, there is a library of mainly trigonometric
substitutions which can be included with \verb|\input substitutions.tex|. For
example, consider this equation:
\begin{verbatim}
\clearequations
\input ../examples/substitutions.tex
$$\eq[eq:r1]{\frac{r_1}{\sin(\pi - \frac{\theta}{2})} = \frac{r_2}{\sin(\frac{\pi}{2} - \frac{\theta}{2})}}$$
$$\eqsubst{"prev"}{"lib:trig:sina+pi/2"; "lib:trig:sina+pi"}$$
$$\eqsubst{"prev"}{"lib:trig:sin-a"; "lib:trig:cos-a"}$$
\end{verbatim}
%only for use with numerics
%only for use with numerics
% 
%Note: N is considered to be 1/s
%


$${}\frac{r_1}{\sin(\pi - \frac{\theta}{2})} = \frac{r_2}{\sin(\frac{\pi}{2} - \frac{\theta}{2})}\label{eq:r1}$$
$${}-\frac{r_1 }{\sin{\left(-\frac{\theta }{2 }\right)} }=\frac{r_2 }{\cos{\left(-\frac{\theta }{2 }\right)} }$$
$${}\frac{r_1 }{\sin{\left(\frac{\theta }{2 }\right)} }=\frac{r_2 }{\cos{\left(\frac{\theta }{2 }\right)} }$$

This equation can now be solved to give an expression for $\tfrac{\theta}{2}$:
\begin{verbatim}
$$\eqsubst{"prev" * \sin{\theta/2} / r_2}{\eqrev{"lib:trig:tansincos"}}$$
$$\eqrev{\eqsimpf{\eqfunc{"prev"}{\arctan}}{unsafe} * 2}$$
\end{verbatim}
$${}\frac{r_1}{r_2}=\tan{\left(\frac{\theta }{2 }\right)}$$
$${}\theta=2\,\arctan{\left(\frac{r_1}{r_2}\right)} $$
The keyword \kw{eqrev} swaps left and right hand side of the
equation. \kw{eqfunc} applies a function to both sides.


\section{Matrices}
Vectors and matrices can be created with the following input:
\begin{verbatim}
\begin{align*}
  \matrix{v_1}%
  \matrix{v_2}%
  \matrix{M_1}%
  \eq[eqraw=false]{v_1 = {x; y; z}}\\
  \eq[eqraw=false]{v_2 = \transpose{x; y; z}}\\
  \eq[eqraw=false]{M_1 = {{x_1; y_1; z_1};{x_2; y_2; z_2};{x_3; y_3; z_3}}}
\end{align*}
\end{verbatim}
\begin{align*}
  %
  %
  %
  {}v_1&=\left( \begin{array}{ccc}x& y& z\end{array} \right)\\
  {}v_2&=\left( \begin{array}{c}x\\y\\z\end{array} \right)\\
  {}M_1&=\left( \begin{array}{ccc}x_1& y_1& z_1\\x_2& y_2& z_2\\x_3& y_3& z_3\end{array} \right)
\end{align*}
It is very important to indicate to EQC that a variable contains a matrix 
(because of the non-commutativity of products). This is done with the \kw{matrix} keyword.
Note that currently it is not possible to create a ``standing'' vector
with \verb|\eq{v_2 = {{x};{y};{z}}|. Instead, use the \kw{transpose} function as shown in the example.

The value of matrix elements can be found with the function \verb|\mindex|:
\begin{verbatim}
\begin{align*}
  \eq{m = \mindex{M_1; b; 2}}\\
  \eq{b = 3}\\
  m_{32} &= \val{m}
\end{align*}
\end{verbatim}
\begin{align*}
  {}m_{32}&=M_1[b,2]\\
  {}b &= 3\\
  m_{32} &= y_3
\end{align*}
You can use the \verb|\wild| function as the index to access a whole row or column. 

EQC supports the following operations with matrices and vectors:
\begin{itemize}
\item Addition and subtraction
\item Multiplication 
\item Exponentiation
\item Transposition with the \kw{transpose}
\end{itemize}
EQC will terminate with an error if the matrices or vectors are not compatible with one another.


\section{Graphs}
EQC has some support for creating graphs with the package pstricks. As an
example, we will compare the graph of a function with its Taylor series expansion.

The definition of the Taylor series expansion is
\begin{equation*}
  T_n f(x,x_0) = \sum_{i=0}^n f^{(i)}(x_0) \cdot \frac{(x - x_0)^i}{i!}
\end{equation*}
Applying this to $\arctan(x)$ around the point ${}x_0 = 0.7\label{eq:x_0}$, we have
\begin{verbatim}
\function{f}{x}%
\begin{align}
  \eq[eq:f0]{f(x) = \arctan x}\tag*{}\\
  \eqdiff[eq:f1]{"prev"}{x}\tag*{}\\
  \eqdiff[eq:f2]{"prev"}{x}\tag*{}
\end{align}
\end{verbatim}
\begin{align}
  {}f(x) &= \arctan x\label{eq:f0}\tag*{}\\
  {}f'{\left(x\right)}&=\frac{1}{1+x^{2} }\label{eq:f1}\tag*{}\\
  {}f''{\left(x\right)}&=-2\frac{x }{{\left(1+x^{2} \right)}^{2} }\label{eq:f2}\tag*{}
\end{align}
The values of the function at $x_0$ are
\begin{verbatim}
\begin{align*}
  \eqsubstc{"eq:f0"}{x = x_0; "eq:x_0"}\\
  \eqsubstc{"eq:f1"}{x = x_0; "eq:x_0"}\\
  \eqsubstc{"eq:f2"}{x = x_0; "eq:x_0"}
\end{align*}
\end{verbatim}
\begin{align*}
  {}f{\left(0.7\right)}&=0.6107\\
  {}f'{\left(0.7\right)}&=0.6711\\
  {}f''{\left(0.7\right)}&=-0.6306
\end{align*}
The first parts of the expansion are
\begin{verbatim}
\begin{align}
  \eq{\arctan(x) = 
    \rhs{\eqsubst{"eq:f0"}{x = x_0}} + 
    \rhs{\eqsubst{"eq:f1"}{x = x_0}} \frac{x - x_0}{1!} +
    \rhs{\eqsubst{"eq:f2"}{x = x_0}} \frac{(x - x_0)^2}{2!}
    }\notag\\
  \eqsubst[eq:series]{"prev"}{"eq:x_0"}\tag*{}\\
  \eqsimpf{"prev"}{expand}
\end{align}
\end{verbatim}
\begin{align}
  {}\arctan{x}&=\frac{x-x_0  }{1+x_0^{2}  }-\frac{x_0\,{\left(x-x_0 \right)}^{2} }{{\left(1+x_0^{2} \right)}^{2} }+\arctan{x_0} \notag\\
  {}&=0.1409+0.6711\,x -0.3153\,{\left(x-0.7 \right)}^{2}  \label{eq:series}\tag*{}\\
  {}&=1.113\,x -0.3153\,x^{2} -0.01357 
\end{align}
The same result can be obtained more easily with the \kw{tseries} keyword:
\begin{verbatim}
  \arctan x = \val{\tseries{\arctan x}{x = 0.7}{3}}
\end{verbatim}
\begin{equation*}
  \arctan x = 1.113\,x -0.3153\,x^{2} -0.01357 
\end{equation*}

The two functions are compared in figure \ref{fig:func}. 
\begin{verbatim}
\begin{figure}[!htb]
  \begin{center}
    \psset{xunit=40mm, yunit=25mm}
    \mmakepspicture{-1}{-1.6}{2}{1.2}{0.5}{0.2}{$x$}{$\arctan(x)$}{%IMPORTANT COMMENT!
      \printvector{\val{\eqeval{y = \arctan x}{x = -1:2:0.1}}}%
    \psset{linecolor=red}%
    \pscurve{-}\printvector{\val{\eqeval{"eq:series"}{x = -1:2:0.1}}}}
  \end{center}
  \caption{Comparison of $\arctan x$ with its Taylor series expansion\label{fig:func}}
\end{figure}
\end{verbatim}
\begin{figure}[!htb]
  \begin{center}
    \psset{xunit=40mm, yunit=25mm}
    \mmakepspicture{-1}{-1.6}{2}{1.2}{0.5}{0.2}{$x$}{$\arctan(x)$}{%THIS COMMENT IS IMPORTANT
      (-1, -0.7853981634)(-0.9, -0.7328151018)(-0.8, -0.6747409422)(-0.6999999999999999, -0.6107259644)(-0.5999999999999999, -0.5404195002999999)(-0.5, -0.46364760899999995)(-0.4, -0.3805063771)(-0.29999999999999996, -0.2914567945)(-0.2, -0.1973955598)(-0.1, -0.0996686525)(0, 0)(0.1, 0.0996686525)(0.2, 0.1973955598)(0.29999999999999996, 0.2914567945)(0.4, 0.3805063771)(0.5, 0.46364760899999995)(0.5999999999999999, 0.5404195002999999)(0.6999999999999999, 0.6107259644)(0.8, 0.6747409422)(0.9, 0.7328151018)(1, 0.7853981634)(1.1, 0.8329812666999999)(1.2, 0.8760580505999998)(1.3, 0.9151007006)(1.4, 0.9505468407999999)(1.5, 0.9827937232)(1.6, 1.0121970115)(1.7, 1.0390722595)(1.8, 1.0636978224)(1.9, 1.0863183978)(2, 1.1071487178)%
    \psset{linecolor=red}%
    \pscurve{-}(-1, -1.4414338482)(-0.9, -1.2702703871)(-0.8, -1.1054129483)(-0.6999999999999999, -0.9468615317)(-0.5999999999999999, -0.7946161373)(-0.5, -0.6486767651999999)(-0.4, -0.50904341539999995)(-0.29999999999999996, -0.37571608779999996)(-0.2, -0.2486947824)(-0.1, -0.12797949929999999)(0, -0.0135702385)(0.1, 0.0945330001)(0.2, 0.1963302164)(0.29999999999999996, 0.29182141049999997)(0.4, 0.3810065824)(0.5, 0.463885732)(0.5999999999999999, 0.5404588593)(0.6999999999999999, 0.6107259644)(0.8, 0.67468704719999995)(0.9, 0.7323421077999999)(1, 0.7836911461)(1.1, 0.8287341622)(1.2, 0.867471156)(1.3, 0.8999021275999999)(1.4, 0.926027077)(1.5, 0.9458460039999999)(1.6, 0.9593589089)(1.7, 0.9665657913999999)(1.8, 0.9674666517)(1.9, 0.9620614898)(2, 0.9503503056)}
  \end{center}
  \caption{Comparison of $\arctan x$ with its Taylor series expansion\label{fig:func}}
\end{figure}
The arguments to \kw{mmakepspicture} are:
\begin{itemize}
  \item Negative $x$-axis value, then negative $y$-axis value
  \item Positive $x$-axis value, then positive $y$-axis value
  \item $x$-axis step value, then $y$-axis step value (for the axis labels)
  \item $x$ and $y$ axis names
  \item An array of $(x; y)$ values to plot
\end{itemize}
The last is generated by the keyword \kw{printvector}, which converts the output
of \kw{eqeval} into a format recognized by pstricks. \kw{eqeval} evaluates an
equation for all the values of the independent variable given as the second
parameter. In the example, $-1:2:0.1$ creates a vector of numbers from $-1$ to
$2$ in increments of $0.1$. The result is a matrix with the values of the
independent variable in the first column and the evaluation results in the
second column: 
\begin{verbatim}
\eq{r = \eqeval{"eq:series"}{x = -1:2:0.5}}
\end{verbatim}
$${}r=\left( \begin{array}{cc}-1& -1.441\\-0.5& -0.6487\\0& -0.01357\\0.5& 0.4639\\1& 0.7837\\1.5& 0.9458\\2& 0.9504\end{array} \right)$$

There is also a simplified version \kw{makepspicture} for drawing a graph in the
first quadrant only:
\begin{itemize}
  \item Location of origin in the format (x0, y0)
  \item Location of lower left-hand corner in the format (x1, y1)
  \item Positive $x$-axis value, then positive $y$-axis value
  \item $x$-axis step value, then $y$-axis step value (for the axis labels)
  \item $x$ and $y$ axis names
  \item An array of $(x; y)$ values to plot
\end{itemize}
Of course, if \kw{makepspicture} and \kw{mmakepspicture} do not
suit your purposes, you can use the standard pstricks macros
instead or create your own shortcuts.

\section{Utility functions}
If you want to make a fresh start in the middle of a document, use
\kw{clearequations}. This will delete all previously defined equations except
library equations, but keep the constants and any functions defined with the hint \verb|lib|.

\section{Pitfalls}
\subsection{Unexpected newlines}
If you use EQC commands like \verb|\eqmul*| that produce no Latex output inside an equationarray
environment, follow them by a comment to avoid insertion of a newline in the output file.
Equationarray environments may not contain newlines. For example:

\begin{verbatim}
\begin{eqnarray}
\eq{x & = & a + b}
\eqsub*{"prev"}{b}
\eqrev{"prev"}
\end{eqnarray}
\end{verbatim}

will yield the following output:

\begin{verbatim}
\begin{eqnarray}
x&=&a+b

a&=&x-b
\end{eqnarray}
\end{verbatim}


\subsection{Multiple possible values for equations}
Consider the following equation:

$${}u = x + y \sin\varphi\label{eq:u}$$

Now we want to find the value $x_1$ which will make $u$ become zero.

\begin{verbatim}
\begin{equation}
\eqsubst[eq:usubst]{"prev"}{x = x_1} = 0
\end{equation}
\end{verbatim}

\begin{equation}
{}u=x_1+y\,\sin{\varphi}  \label{eq:usubst} = 0
\end{equation}

and find $x_1$ to be:

\begin{verbatim}
\eqsubst*{"prev"}{u = 0}
\eqsub*{"prev"}{\sin\varphi y}
$$\eqrev{"prev"}$$
\end{verbatim}

$${}x_1=-y\,\sin{\varphi} $$

But what happens if we now ask for the value of $u$?

\verb|u = \val{u}|
$$u = x_1+y\,\sin{\varphi}  $$

EQC prints a warning that there are multiple possible values for $u$ (i.e., $x +
y \sin\varphi$ and $x_1 + y \sin\varphi$) and then chooses the
last value (which might or might not be what we wanted). There are two ways to avoid this:
\begin{enumerate}
\item Do both substitutions at the same time: \verb|\eqsubst{"prev"}{x = x_1; u = 0}|.
\item Introduce a temporary for $u$: \verb|\eqsubst{"prev"}{x = x_1; u = u_{temp}}|.
\end{enumerate}

\subsection{Multiple substitutions}
If you do multiple substitutions at the same time, the order in which the
substitutions are done is not defined. By using the keyword \kw{eqsubstc},
substitutions are done consecutively in the order they are listed. For example,
compare:
\begin{verbatim}
$$\eqsubst{x = 3y}{y = 4z; z = 3}$$
$$\eqsubstc{x = 3y}{y = 4z; z = 3}$$
\end{verbatim}
$${}x=12\,z $$
$${}x=36$$
Only use \kw{eqsubstc} when order is important because it is less efficient than
\kw{eqsubst}.

\subsection{Output of numbers}
Not all combinations of \verb|\precision|, \verb|\precision_type| and \verb|\scientific_limits|
make sense. For example, you might set the lower scientific limit to $0.001$ so that numbers like
$0.005$ will be printed without exponent. If you now set \verb|precision_type| to \verb|fixed_marker|
and precision to $2$, numbers smaller than $0.01$ will be printed as zero!

\subsection{Library equations}
Note that library equations are not automatically used for finding values of
variables. They are considered to be purely for reference purposes. An example: 
\begin{verbatim}
\eq[lib:myeq]{x = 7y}
\eq{y = 2}
x = \val{x}
\end{verbatim}
This will \emph{not} return $14$ as the value of $x$. If you want to use a
library equation for finding values, you need to ``activate'' it. There are two
different possibilities:
\begin{verbatim}
\eq{"lib:myeq"}
\eqsubst{"lib:myeq"}{x = x_1}
\end{verbatim}
The last case is really what the library equations are there for: They need to
be adapted to special purposes by substituting custom variables into them.

\subsection{Pstricks headaches}
pstricks can give you headaches when the function that is to be plotted has
$x$ or $y$ values of less than $1.0$, for example, $\sin x$:
\begin{verbatim}
\begin{figure}[!htb]
\begin{center}
\pspicture(\val{-180\degree},-1)(\val{180\degree},1)
  \psgrid(\val{-180\degree},-1)(\val{180\degree},1)
  \psaxes[linewidth=2pt, labels=none]{->}(0,0)(\val{-180\degree},-1)(\val{180\degree},1)
  \pscurve{-}\printvector{\val{
      \eqeval{y = \sin x}{x = -180\degree:180\degree:30\degree}}}
\endpspicture
\end{center}
\caption{Function $y = \sin x$, naïve version}
\end{figure}
\end{verbatim}
\begin{figure}[!htb]
\begin{center}
\pspicture(-3.142,-1)(3.142,1)
  \psgrid(-3.142,-1)(3.142,1)
  \psaxes[linewidth=2pt, labels=none]{->}(0,0)(-3.142,-1)(3.142,1)
  \pscurve{-}(-3.1415926536, 0)(-2.617993878, -0.5)(-2.0943951024, -0.8660254038)(-1.5707963268, -1)(-1.0471975512, -0.8660254038)(-0.5235987756, -0.5)(0, 0)(0.5235987756, 0.5)(1.0471975512, 0.8660254038)(1.5707963268, 1)(2.0943951024, 0.8660254038)(2.617993878, 0.5)(3.1415926536, 0)
\endpspicture
\end{center}
\caption{Function $y = \sin x$, naïve version}
\end{figure}
Note that some \kw{val} statements are required to evaluate the units to
floating point numbers. The method above has two major drawbacks: The $x$-axis
is scaled in radians, not in degrees, and the numbering of the $y$-axis is only in
integer numbers.

The non-naïve version of the diagram is:
\begin{verbatim}
\begin{figure}[!htb]
\begin{center}
\psset{xunit=0.35mm, yunit=40mm}
\pspicture(-190,-1.05)(200,1.1)  
  \psaxes[linewidth=2pt, ticks=none, labels=none]{->}(0,0)(-190,-1.05)(200,1.1)
  \psaxes[Dx=30, ticks=x, labels=x, ticksize=40mm]{-}(0,0)(-180,-1)(180,1)
  \psaxes[Dy=0.2, ticks=y, labels=y, ticksize=54mm]{-}(0,0)(-180,-1.05)(180,1.1)
  \pscurve{-}\printvector{\val{\eqeval{
        \eqsubst{y = \sin x}{x = x \degree}}{x = -180:180:30}}}
\endpspicture
\end{center}
\caption{Function $y = \sin x$}
\end{figure}
\end{verbatim}
\begin{figure}[!htb]
\begin{center}
\psset{xunit=0.35mm, yunit=40mm}
\pspicture(-190,-1.05)(200,1.1)  
  \psaxes[linewidth=2pt, ticks=none, labels=none]{->}(0,0)(-190,-1.05)(200,1.1)
  \psaxes[Dx=30, ticks=x, labels=x, ticksize=40mm]{-}(0,0)(-180,-1)(180,1)
  \psaxes[Dy=0.2, ticks=y, labels=y, ticksize=63mm]{-}(0,0)(-180,-1.05)(180,1.1)
  \pscurve{-}(-180, 0)(-150, -0.5)(-120, -0.8660254038)(-90, -1)(-60, -0.8660254038)(-30, -0.5)(0, 0)(30, 0.5)(60, 0.8660254038)(90, 1)(120, 0.8660254038)(150, 0.5)(180, 0)
\endpspicture
\end{center}
\caption{Function $y = \sin x$}
\end{figure}

\end{document}