Chapter 4
Math and Equations

4.1 Displaying Math Expressions

Two basic types of formula (or math) environments are available in Image: (1) a text mode in which math expressions are placed in a line of text, and (2) a display environment in which the math expression is place on a separate line.

text mode: To place a math expression in a line of text, simply enclose the math expression with $. . .$ or, equivalently, (…). In this mode, some symbols such as Image and Image are written more compactly compared to their treatment in the “displaymath” mode.

displaymath (without equation numbering): To center a math expression or formula on a separate line, embed the math expression between the environment delimiters egin{displaymath} … end{displaymath}. Shorthand equivalents are [… ] or $$…$$.

displaymath (with equation numbering): To place automatically an equation number to the right of a math expression that is centered on a separate line, use the egin{equation} . . . end{equation} environment. There is no built-in shorthand equivalent (although a shorthand version can be defined in the preamble; see Section 7.2).

4.2 Composing Math Expressions

In Image, a large variety of mathematical expressions can be created; however, you often have to resort to fairly complex programming for “difficult” expressions. These difficult expressions are handled much more easily with the macros of Image However, in these notes we stick to pure Image (mixed occasionally with Image). Here are some examples.

Fractions

Image

Binomials

Image

Math Accents

Image

Subscripts and Superscripts

Image

Growing Symbols

Image

Matrices

Image

Operators

Image

Text in Formulas

Image

Miscellaneous

Image

4.3 Math Spacing Commands

For many math expressions, it is important to perform some small horizontal spacing adjustments to move parts together or apart. Here are the math-mode spacing commands (Image indicates a space).

Image

4.4 Types of Equations

Three basic types of equations are frequently encountered when using Image: (1) simple equation, (2) multi-line or multi-conditional equations, and (3) an array of equations.

4.4.1 Simple Equations

A simple equation, such as y (x) = 3 + x2 or Eq. (4.1),

(4.1)

Image

is produced by

          A simple equation, such as $y(x) = 3+x^2$
          or Eq.~( ef{simpleeq}),
          egin{equation}
                    f(x) + g(x) = sqrt{l + x^2}
                    label{simpleeq}
          end{equation}

Note the use of the optional label in the single-line equation definition so that this label can be referenced later in the text with ef{simpleeq}.

4.4.2 Multiconditional Equations

Often an equation will have multiple lines on one side of the = sign that depend on various conditions. For example,

(4.2)

Image

is produced by

          egin{equation}
              f(x) = left{  egin{array}{ll}
                                z-y & mbox{if $y>0$} \
                                z+y & mbox{otherwise}
                                end{array}
                    ight.
              label{eqtype2}
          end{equation}

Note the use of mbox{. . .} to place roman fonts in the equation.

4.4.3 Multiline and Multiple Equations

Sometimes you will want to break a long equation into several lines or to have several equations in one block. For this, Image provides the eqnarray environment.

(4.3)

Image

(4.4)

Image

is produced by

        egin{eqnarray}
          f(x) & = & sqrt{l - x~2} label{eqmultil} \
          g(x) & =&a + b + c + d + e + f  onumber \
               & &+ g + h + i + j label{eqmulti2} 
        end{eqnarray}

Notice that when an equation is broken between lines with \ the onumber command is used to prevent an equation number being automatically printed to the right of the broken line.

There is also an eqnarray* environment that is exactly like the eqnarray environment except that equation numbers are not automatically placed at the end of each equation line. To force an equation number in this environment, insert yesnumber after the line and before the line break \.

4.5 Equal Spacing in Equations and Eqnarrays

The spacing around the equal sign in an eqnarray environment is larger than that in an equation environment, as can be seen by comparing Eqs. (4.1) and (4.3). The spacing can be made the same for both environments by defining in the preamble the following new environment:

        ewenvironment {Eqnarray}%
              {arraycolsep 0.14emegin{eqnarray}}{end{eqnarray}}

Then with the use of egin{Eqnarray}. . .end{Eqnarray}, Eqs. (4.3) and (4.4) are typeset as

(4.5)

Image

(4.6)

Image

4.6 Text in Eqnarray

In the eqnarray environment, we often want to insert text between equations without leaving the environment and the alignment on the = sign. For example,

(4.7)

a = b + c

(4.8)

d = f + g

and finally

(4.9)

h = d + e + f

uses oalign to insert the words”and finally” between the second and third equation.

In the { t eqnarray} environment,
we often want to insert text between
equations without leaving the
environment and the alignment on
the = sign. For example,
    egin{eqnarray}
    a & = & b + c \
    d & = & f + g \
     oalign{hbox{andand}}
    h & = & d + e + f
    end{eqnarray}
uses verb| oalign| to insert the
words ’‘and finally” between the
second and third equation.

4.7 Vertical Spacing With Struts

A strut, such as ule{0in}{.25in}, is a box of some specified height but of zero width so that nothing is printed. However, the height of a strut forces extra space above the line containing the strut. A strut can thus be used to increase spacing between lines of a multiline equation as shown in the second example below. Note the use of s, which has been defined as a shorthand notation for a strut by the defs{ ule{0in}{.30in}} statement. This is a useful definition to place in the document preamble if you use a lot of struts.

Image

The strut is also useful for tricking Image into thinking that the line is taller than it really is. In this way, variable delimiters (for example, left[ or ight}) on different lines of a multiline equation can be made the same size. Consider the following examples. In the second example, a strut has been placed in the second line to force the closing square bracket to have the same size as the square bracket on the first line.

Image

4.8 Math-mode Font Sizes

Four font sizes and styles are available in math mode: extstyle, displaystyle, scriptstyle, and scriptscriptstyle.

displaystyle is used for displayed equations (equations on their own lines), whereas extstyle is used for mathematical expressions in a line of text. These fonts are almost the same except that the large operators are different: for example,

in extstyle we get Image and Image and in displaystyle we get Image and Image.

The math style scriptstyle is used for first-level superscripts and subscripts; scriptscriptstyle is normally used for higher-level superscripts and subscripts.

4.8.1 Nested Fraction Constructions

The frac command produces small fonts when they are nested, as in the first example below. Fonts can be returned to normal size with the displaystyle command, as in the second example. However, the third construction is the preferred way to typeset this type of expression.

Image

4.8.2 Displaystyle in Eqnarrays and Arrays

Image has a nasty habit of using small fonts in an array or eqnarray environment (see the first example that follows). The second example shows a way to avoid this problem. Notice also in the second example that the strut ( ule{0in}{5ex}) is used to increase the spacing between the two lines of the array.

Image

4.9 Manual Equation Numbering

The easiest way to gain control of equation numbers in Image is not to use them! In some situations the normal Image convention of chapter, eqno is not flexible enough and neither are most of the “subeqn” styles (see Section 8.4). But the Image command eqno() also works in Image, so that you can write

        $$ pV = nRT . eqno(mbox{em ideal gas law: } 12345a)$$

to produce

pV = n RT. (ideal gas law: 12345a)

4.10 Equations With Left and Right Tags

As a special effect, you may occasionally want a displayed equation to have a tag both on the left and on the right of the equation line, as in the two following examples.

Image

The first example, with the equation centered on the line, is produced by

    [ Longrightarrow setboxO=hbox{$Longrightarrow$}kern-wdO
       hspace{.5columnwidth minus .5columnwidth}
          g(x)=int_aˆb dx, frac{f(x)Hsqrt{l-xˆ2}}
       hspace{.5columnwidth minus .5columnwidth}
       llap{em a difficult integral}
    ]

The second example, with the equation centered between the tags, is produced by

    [ Longrightarrow
    hspace{.5columnwidth minus .5columnwidth}
         g(x)=int_aˆb dx, frac{f (x)Hsqrt{l-xˆ2}}
    hspace{.5columnwidth minus .5columnwidth}
    mbox{em a difficult integral}
    ]

4.11 Multiletter Variables in Math Mode

Image uses the math italics font for variables in a math environment; for example, $f (x)$ is typeset as f(x). More importantly, Image treats adjacent letters as different variables multiplied together. This can produce ugly results when a multiletter variable is used. For example, suppose you want to define a symbol for a variable called “Working-Level-Month—effective.” The natural $WLM_{eff}$ produces the strangely spaced result WLMeff. What needs to be done is to use regular italics font. Thus, to produce the more pleasing result WLMeff, you would use ${em WLM}_{ ! ! em eff}$. Notice the use of negative spaces ! to move the superscript closer to the variable name. If this variable is to be used many times in your document, it is a good idea to define a command to produce this variable by placing in the preamble

       ewcommand{WLMeff}{{em WLM}_{!!em eff}}.

Then $WLMeff$ will produce WLMeff.

4.12 Roman Font in Math Mode

Often roman font and not italic font is needed in the math environment such as when typing chemical equations. For example, $$C + H_2 ightarrow CH_4$$

produces the unattractive

C + 2H2 → CH4

The chemical symbols should be in roman font, and CH is not two separate variables multiplied together. To produce a better result, use

     $$ mbox{C} + mbox{2H_2}  ightarrow mbox{CH_4}$$

to produce

C + 2H2 → CH4

As an alternative to using mbox{ m roman text }, you can define a chem command to cause all characters to be roman. The chem command is defined in the preamble as

       defchem{everymath={fam0 }fam0 }

Note the space after each fam0 command. Then, in math mode, the command chem will cause all lettering to be in roman font. For example,

      $$chem C + 2H_2  ightarrow CH_4$$

produces

C + 2H2 → CH4

Alternatively, if the command everymath={fam0 } is placed in the preamble of a document, all math will be typeset in roman face.

4.13 Boldface in Math Mode

Math italic is the default font in math mode. In this mode, the f command causes all uppercase Greek letters and numbers to be printed in boldface. Also, the alphabetic characters are changed from math italics to bold Roman font. However, in math mode, lower case Greek letters and all operators are treated as symbols, and are thus unaffected by the command f. Consider the following example.

Image

To create bold lowercase Greek letters, operators, and bold math italics, you must use the oldmath command before entering the math mode. The command oldmath causes uppercase Greek letters to be set in bold italics and numbers to become large bold subscripts. Here is how oldmath affects the preceding example.

Image

Because oldmath is a text mode command, its use becomes rather cumbersome in the displayed math environment where you have to do things like

       [ mbox{oldmath $sigma$} = mbox{oldmath $alpha$}
                                      - mbox{f b} ]

to produce

σ = α—b

Here is a preamble macro for use in math mode that will produce the appropriate boldface (either oldmath or f) for any symbol:

       ewcommand{mathbold} [1] {mbox{oldmath $f#1$}}

With this macro, the example equation can be composed more easily as

      [ mathbold{ sigma = alpha - b} ]

4.13.1 Accents in Boldmath

As explained above, to obtain a bold lowercase Greek letter it is necessary to use oldmath; for example, to produce µ you enter $mbox{oldmath $mu$}$. However, to put an accent on such a lowercase Greek letter is not so easy. There is a warning on page 201 of Lamport’s book that oldmath may have problems, but it does not mention accents. Apparently, some accents cause oldmath great problems. For example, $mbox{oldmath $hat{mu}$}$ produces Image which gives an accent that looks like a smile going through the µ.

However, widehat does not cause such problems. To produce Image, you enter

        $mbox{oldmath $widehatmu$}$.

To produce a regular size, but not bold, hat symbol on a bold µ, that is, Image requires an equally awkward sequence:

        $hat{mbox{oldmath $mu$}}$

4.14 A Better Dot Product Operator

The cdot in math mode for the dot product operator is too small, as in U . V ($f U cdot V$) and the ullet symbol produces too large a dot, as in U • V ($f U ullet V$). Moreover, the spacing around the dot is a bit large. Here are two alternatives that differ only in their spacing around the dot:

    U.Vfrom$f U !stackrel{scriptscriptstyleullet}{{}}! V$
    U-V from $f U scriptstyle strackre{ullet}{{}}} V$.

To use one of these alternatives, it is best to define a dotprod command in the preamble with, for example,

      ewcommad{dotprodM{scriptscriptstyle stackrel{ullet}{{}}}}

Then, to produce U • V, simply type $f U dotprod V$.

4.15 Two Compound Math Operators

In many math documents the “greater than or approximately equal to” (Image) or the “less than or approximately equal to” (Image) operators are needed. However,Image does not include these compound operators in its fonts (although they are included in the Image fonts under the NFSS). These two operators can be constructed by placing the following in your preamble.


     makeatletter
     %------- Compound Math Operators by D. Arseneau
     defgsim{compoundrel>oversim}
     deflsim{compoundrel<oversim}
     defcompoundrel#lover#2{mathpalettecompoundreL{{#l}over{#2}}}
     defcompoundreL#l#2{compoundREL#l#2}
     defcompoundREL#l#2over#3{mathrel
          {vcenter{hbox{$m Image thuildrel{#l#2}over{#l#3}$}}}}
     makeatother

Then use $gsim$ to produce Image and $lsim$ to produceImage.

4.16 Matrix Expressions

Image’s array environment can be used to create matrix equations, as shown in the following example:

Image

If you use parentheses to delimit the arrays (as in this example), it is easier to use Image’s pmatrix command as in

Image

Image’s vphantom command can also be used to give vertical alignment of a row vector times a matrix. Consider these two cases:

Image

4.17 Continued Fractions

A continued fraction such as

Image

is created by

              [
                t_0+frac{l}{t_l+frac{ extstyle 1}
                { extstyle t_2+frac{ extstyle 1}
                { extstyle t_3+frac{ extstyle 1}
                { extstyle t_4+cdots}}}}
              ]

A continued fraction can also be written in “short” form as

Image

by the following input

       $$l+cfrac{l}{t_l}+cfrac{l}{t_2}+cfrac{l}{t_3}+
                                  cfrac{l}{t_4}+cdots ,$$

To use this short form, you must first define the following definition of cf rac in the preamble.

       defcfrac#l#2{array{c}multicolumn{l}{|c}{#1}\
                              hlinemulticolumn{l}{|c}{#2}endarray}

4.18 Chemical Reaction Arrows

To produce a chemical reaction equation such as

Image

a double-arrow reaction rate symbol is needed. One method is to define in the preamble the macro

  def eactionrates#l#2{mathrel{mathop{ ightleftharpoons}limits^{#l}_{#2}}}

and then use

       mbox{A} + mbox{B}  eactionrates{k_l}{k_2} mbox{C}

4.19 Placing Frames around Equations

Sometimes you will want to emphasize an equation by placing a box or frame around it, such as Image or even

Image

To produce this, use

      … equations such as framebox{$x^2 = z + sin(z)$} or even
      {fboxsep=.2in
      $$ framebox{$ f(x, y) = x^2 + y^2 $} $$ }

To add equation numbers to a boxed equation is a bit more complex. To produce

(4.10)

Image

use the following:

         egin{equation}
              mbox{fboxsep=.lin framebox{$ f(x, y) = x^2 + y^2 $}}
        end{equation}

Putting a box around multiline equations is more difficult. The easiest way is to use the Image macros (see Section 5.4). To produce

(4.11)

Image

use the following (it is assumed that the Image macros have been loaded):

     egin{equation}
     BeginTable
       penUp99
       BeginFormat
        | r M o0 | M    |
       EndFormat
        -
        | frac{dP(t)}{dt} " = frac{ ho-ar{eta}}{ell} P(t)
                      + sum_{i=l}^G lambda_i C_i(t) + S(t) | \+44
        | frac{d C_i(t){dt} " = -lambda_i C_i(t)
        + frac{ar{eta}_i}{ell} P(t), qquad i=l, 1dots, G I \+44
        -
       EndTable
       end{equation}

To avoid automatic generation of equation numbers, replace the egin{equation} . . . end{equation} by $$ … $$.

4.20 Word Equations in Boxes

Sometimes you may want to use word equations, that is, blocks of text in boxes. For example,

(4.12)

Image

This was produced with

   egin{equatequat}
     mbox{f ramebox{parbox{l. 5inMcentering
     The Total Document or Great Big Book Made from Many Parts}}  =  %
     framebox{parbox{1.0in}{centering Part 1}}  + $cdots$ +  %
     framebox{parbox{1.0in}{centering Part n}}}
     end{equation}

4.21 Math in Section Titles

You must be careful when placing math, references, and citations in the title of a chapter, section, subsection, or the like. If special care is not taken you will encounter the dreaded error message “Image capacity exceeded, sorry…”. For example, the statement

     subsubsection*{Solution of Equation oldmath $y,,(x) = f(x)$}

will cause just such a problem no matter what the capacity of your Image compiler. Remember, the commands section, subsection, and so on, have moving arguments (the argument appears as a heading as well as in the .toe file), and fragile commands in such an argument must be “protected.” Commands like oldmath, cite, and ef must be protected with the protect command. For example, to produce the title

Solution of Equation y”(x) = f(x)

you must use

     subsubsection*{Solution of Equation protectoldmath $y,,(x) = f(x)$}.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.97.248