The R Project SVN R

Rev

Rev 7087 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7087 Rev 7745
Line 7... Line 7...
7
  is an expression, the argument is interpreted as a mathematical
7
  is an expression, the argument is interpreted as a mathematical
8
  expression and the output will be formatted according to TeX-like
8
  expression and the output will be formatted according to TeX-like
9
  rules.
9
  rules.
10
}
10
}
11
\details{
11
\details{
12
  %% FIXME: use \describe instead when this works in nroff!
-
 
13
  A mathematical expression must obey the normal rules of syntax
12
  A mathematical expression must obey the normal rules of syntax for any
14
  for any \R expression, but it is interpreted according to very
13
  \R expression, but it is interpreted according to very different rules
15
  different rules than for normal \R expressions.
14
  than for normal \R expressions.
16
  
15
  
-
 
16
  \describe{
-
 
17
    \item{\emph{Binary operators:}}{
17
  \emph{Binary operators:} addition, subtraction, multiplication, and
18
      addition, subtraction, multiplication, and division use the
18
  division use the standard \R syntax, although multiplication only
19
      standard \R syntax, although multiplication only juxtaposes the
-
 
20
      arguments.
-
 
21
      
19
  juxtaposes the arguments.  For example, \code{a+b}, \code{a-b}, and
22
      For example, \code{a+b}, \code{a-b}, and \code{a/b}, produce
20
  \code{a/b}, produce \eqn{a+b}, \eqn{a-b}, and \eqn{a/b}, but
23
      \eqn{a+b}, \eqn{a-b}, and \eqn{a/b}, but \code{a*b} produces
21
  \code{a*b} produces \eqn{ab}.
24
      \eqn{ab}.}
22
 
25
    
-
 
26
    \item{\emph{Unary operators:}}{
23
  \emph{Unary operators:} positive and negative numbers are specified
27
      positive and negative numbers are specified with standard syntax.
-
 
28
      
24
  with standard syntax.  For example, \code{+x} produces \eqn{+x} and
29
      For example, \code{+x} produces \eqn{+x} and \code{-y} produces
25
  \code{-y} produces \eqn{-y}.
30
      \eqn{-y}.}
26
 
31
    
-
 
32
    \item{\emph{Subscripts and superscripts:}}{
27
  \emph{Subscripts and superscripts:} a subscript is specified using the
33
      a subscript is specified using the subsetting syntax and a
28
  subsetting syntax and a superscript is specified using the power
34
      superscript is specified using the power syntax.
-
 
35
      
29
  syntax.  For example, \code{x[i]} produces \eqn{x_i} and \code{x^2}
36
      For example, \code{x[i]} produces \eqn{x_i} and \code{x^2}
30
  produces \eqn{x^2}.
37
      produces \eqn{x^2}.}
31
 
38
    
-
 
39
    \item{\emph{Accents:}}{
32
  \emph{Accents:} accented expressions are specified using the special
40
      accented expressions are specified using the special mathematical
33
  mathematical functions \code{hat} and \code{bar}.
41
      functions \code{hat} and \code{bar}.}
-
 
42
    
34
  % For example, \code{hat(x)} produces \eqn{\hat{x}} and \code{bar(x)}
43
    % For example, \code{hat(x)} produces \eqn{\hat{x}} and \code{bar(x)}
35
  % produces \eqn{\bar{x}}.
44
    % produces \eqn{\bar{x}}.
36
 
45
    
-
 
46
    \item{\emph{Fractions:}}{
37
  \emph{Fractions:} fractions are specified using the special
47
      fractions are specified using the special mathematical function
38
  mathematical function \code{frac} (or its alias, \code{over}).
48
      \code{frac} (or its alias, \code{over}).}
-
 
49
    
39
  % For example, \code{frac(1,2)} produces \eqn{1\over2}.
50
    % For example, \code{frac(1,2)} produces \eqn{1\over2}.
40
 
51
    
-
 
52
    \item{\emph{Relations:}}{
41
  \emph{Relations:} equality or assignment of terms is specified using
53
      equality or assignment of terms is specified using the \code{==}
42
  the \code{==} relation.  For example, \code{x == y} produces
54
      relation.
43
  \eqn{x=y}.
55
      
-
 
56
      For example, \code{x == y} produces \eqn{x=y}.}
44
 
57
    
-
 
58
    \item{\emph{Visible grouping:}}{
45
  \emph{Visible grouping:} terms are visibly grouped by placing them
59
      terms are visibly grouped by placing them within parentheses.
-
 
60
      
46
  within parentheses.  For example, \code{(x+y)} produces \eqn{(x+y)}.
61
      For example, \code{(x+y)} produces \eqn{(x+y)}.}
-
 
62
    
-
 
63
    \item{\emph{Invisible grouping:}}{
-
 
64
      terms are invisibly grouped by placing them within curly braces.
47
 
65
 
48
  \emph{Invisible grouping:} terms are invisibly grouped by placing them
-
 
49
  within curly braces.  For example, \code{x^{2*y}} produces
66
      For example, \code{x^{2*y}} produces \eqn{x^{2y}}, whereas
50
  \eqn{x^{2y}}, whereas \code{x^2*y} produces \eqn{x^2y}.
67
      \code{x^2*y} produces \eqn{x^2y}.}
51
 
68
 
-
 
69
    \item{\emph{Big operators:}}{
52
  \emph{Big operators:} a sum, product, or integral is specified using
70
      a sum, product, or integral is specified using the special
53
  the special mathematical function of the corresponding name.  Each of
71
      mathematical function of the corresponding name.  Each of these
54
  these functions takes three arguments;  the first indicates what is
72
      functions takes three arguments;  the first indicates what is
55
  being summed/multiplied/integrated and the second and third specify
73
      being summed/multiplied/integrated and the second and third
56
  the limits of the summation/product/integral.
74
      specify the limits of the summation/product/integral.
-
 
75
      
57
  For example, \code{sum(x[i], i==0, n)} produces
76
      For example, \code{sum(x[i], i==0, n)} produces
58
  \deqn{\sum\limits_{i=0}^n x_i}{sum_{i=0}^n x_i}.
77
      \deqn{\sum\limits_{i=0}^n x_i}{sum_{i=0}^n x_i}}
59
 
78
 
-
 
79
    \item{\emph{Radicals:}}{
60
  \emph{Radicals:} a square root expression is specified using the
80
      a square root expression is specified using the special
61
  special mathematical functions \code{root} and \code{sqrt}.
81
      mathematical functions \code{root} and \code{sqrt}.}
-
 
82
      
62
  % For example, \code{sqrt(x)} produces \eqn{\sqrt x}.
83
    % For example, \code{sqrt(x)} produces \eqn{\sqrt x}.
63
 
84
 
-
 
85
    \item{\emph{Absolute values:}}{
64
  \emph{Absolute values:} an absolute term is specified using the
86
      an absolute term is specified using the special mathematical
65
  special mathematical function \code{abs}.  For example, \code{abs(x)}
87
      function \code{abs}.
-
 
88
 
66
  produces \eqn{|x|}.
89
      For example, \code{abs(x)} produces \eqn{|x|}.}
67
 
90
 
-
 
91
    \item{\emph{Juxtaposition:}}{
68
  \emph{Juxtaposition:} multiple terms are juxtaposed using the special
92
      multiple terms are juxtaposed using the special mathematical
69
  mathematical function \code{paste}.  For example,
93
      function \code{paste}.
-
 
94
      
70
  \code{paste(over(b, 2), y, sum(x))} produces
95
      For example, \code{paste(over(b, 2), y, sum(x))} produces
71
  \eqn{\frac{b}{2} y \sum x}{b/2 y sum(x)}.
96
      \eqn{\frac{b}{2} y \sum x}{b/2 y sum(x)}.}
72
 
97
   
-
 
98
    \item{\emph{Typeface changes:}}{
73
  \emph{Typeface changes:} the default font in mathematical expressions
99
      the default font in mathematical expressions is italic (except for
74
  is italic (except for terms which are symbols).  A new typeface is
100
      terms which are symbols).  A new typeface is specified using the
75
  specified using the special mathematical functions \code{bold},
101
      special mathematical functions \code{bold}, \code{italic},
76
  \code{italic}, \code{plain}, and \code{bolditalic}.  Note that these
102
      \code{plain}, and \code{bolditalic}.  Note that these font
77
  font specifications do not accumulate (i.e., \code{bold(italic(x)))}
103
      specifications do not accumulate (i.e., \code{bold(italic(x)))}
78
  gives an italic `x', whereas \code{bolditalic(x)} produces a bold,
104
      gives an italic `x', whereas \code{bolditalic(x)} produces a bold,
79
  italic `x').
105
      italic `x').}
80
  % For example, \code{plain(X)[i]} produces \eqn{\textrm{X}_i}.
-
 
81
 
106
 
-
 
107
    \item{\emph{General expressions:}}{
82
  \emph{General expressions:} any functional expression which is not a
108
      any functional expression which is not a special mathematical
83
  special mathematical function is simply reproduced as a function
109
      function is simply reproduced as a function expression.
-
 
110
 
84
  expression.  For example, \code{foo(x)} produces \eqn{foo(x)}.
111
      For example, \code{foo(x)} produces \eqn{foo(x)}.}
-
 
112
  }
85
}
113
}
86
\seealso{
114
\seealso{
87
  \code{\link{axis}},
115
  \code{\link{axis}},
88
  \code{\link{mtext}},
116
  \code{\link{mtext}},
89
  \code{\link{text}},
117
  \code{\link{text}},
Line 93... Line 121...
93
x <- seq(-4, 4, len = 101)
121
x <- seq(-4, 4, len = 101)
94
y <- cbind(sin(x), cos(x))
122
y <- cbind(sin(x), cos(x))
95
matplot(x, y, type = "l", xaxt = "n",
123
matplot(x, y, type = "l", xaxt = "n",
96
        main = expression(paste(plain(sin) * phi, "  and  ",
124
        main = expression(paste(plain(sin) * phi, "  and  ",
97
                                plain(cos) * phi)),
125
                                plain(cos) * phi)),
98
        ylab = expression("sin" * phi, "cos" * phi),    # only 1st is taken
126
        ylab = expression("sin" * phi, "cos" * phi), # only 1st is taken
99
        xlab = expression(paste("Phase Angle ", phi)),
127
        xlab = expression(paste("Phase Angle ", phi)),
100
        col.main = "blue")
128
        col.main = "blue")
101
axis(1, at = c(-pi, -pi/2, 0, pi/2, pi),
129
axis(1, at = c(-pi, -pi/2, 0, pi/2, pi),
102
     lab = expression(-pi, -pi/2, 0, pi/2, pi))
130
     lab = expression(-pi, -pi/2, 0, pi/2, pi))
103
 
131
 
104
plot(1:10, 1:10)
132
plot(1:10, 1:10)
105
text(4, 9, expression(hat(beta) == (X^t * X)^{-1} * X^t * y))
133
text(4, 9, expression(hat(beta) == (X^t * X)^{-1} * X^t * y))
106
text(4, 8.4, "expression(hat(beta) == (X^t * X)^{-1} * X^t * y)", cex = .8)
134
text(4, 8.4, "expression(hat(beta) == (X^t * X)^{-1} * X^t * y)",
-
 
135
     cex = .8)
107
text(4, 7, expression(bar(x) == sum(frac(x[i], n), i==1, n)))
136
text(4, 7, expression(bar(x) == sum(frac(x[i], n), i==1, n)))
108
text(4, 6.4, "expression(bar(x) == sum(frac(x[i], n), i==1, n))", cex = .8)
137
text(4, 6.4, "expression(bar(x) == sum(frac(x[i], n), i==1, n))",
-
 
138
     cex = .8)
109
text(8, 5, expression(paste(frac(1, sigma*sqrt(2*pi)), " ",
139
text(8, 5, expression(paste(frac(1, sigma*sqrt(2*pi)), " ",
110
                            plain(e)^{frac(-(x-mu)^2, 2*sigma^2)})), cex= 1.2)
140
                            plain(e)^{frac(-(x-mu)^2, 2*sigma^2)})),
-
 
141
     cex= 1.2)
111
}
142
}
112
\keyword{aplot}
143
\keyword{aplot}