Demonstrate LaTeX Math Formatting in Roxygen

Description

The quadratic formula is given by:

\(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\)

For inline math, the variance is denoted \(\sigma^2\), and the standard deviation is \(\sigma\).

Usage

math_demo(a, b, c)

Arguments

a Numeric coefficient of \(x^2\)
b Numeric coefficient of \(x\)
c Numeric constant term

Details

This function demonstrates how to include formatted mathematical expressions in roxygen2 documentation using LaTeX syntax.

This function computes the roots of a quadratic equation of the form:

\(ax^2 + bx + c = 0\)

The discriminant is \(\Delta = b^2 - 4ac\). When \(\Delta > 0\), there are two real roots. When \(\Delta = 0\), there is one repeated real root. When \(\Delta < 0\), there are two complex conjugate roots.

Additional mathematical notation examples:

  • Sum notation: \(\sum_{i=1}^{n} x_i\)

  • Integral: \(\int_{0}^{\infty} e^{-x} dx = 1\)

  • Matrix multiplication: = +

  • Greek letters: \(\alpha, \beta, \gamma, \delta\)

Value

A numeric vector of length 1 or 2 containing the root(s) of the equation. Complex roots are returned as complex numbers.

Examples

Code
library("rpt")

# Two real roots: x^2 - 5x + 6 = 0
# Solution: x = 2 or x = 3
math_demo(1, -5, 6)
[1] 3 2
Code
# One repeated root: x^2 - 4x + 4 = 0
# Solution: x = 2
math_demo(1, -4, 4)
[1] 2
Code
# Complex roots: x^2 + 2x + 5 = 0
# Solution: x = -1 ± 2i
math_demo(1, 2, 5)
[1] -1+2i -1-2i