# showEqn: Show Matrices (A, b) as Linear Equations In matlib: Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics

## Description

Shows what matrices A, b look like as the system of linear equations, A x = b, but written out as a set of equations.

## Usage

 ```1 2``` ```showEqn(A, b, vars, simplify = FALSE, reduce = FALSE, fractions = FALSE, latex = FALSE) ```

## Arguments

 `A` either the matrix of coefficients of a system of linear equations, or the matrix `cbind(A,b)`. Alternatively, can be of class `'lm'` to print the equations for the design matrix in a linear regression model `b` if supplied, the vector of constants on the right hand side of the equations. When omitted the values `b1, b2, ..., bn` will be used as placeholders `vars` a numeric or character vector of names of the variables. If supplied, the length must be equal to the number of unknowns in the equations. The default is `paste0("x", 1:ncol(A)`. `simplify` logical; try to simplify the equations? `reduce` logical; only show the unique linear equations `fractions` logical; express numbers as rational fractions? `latex` logical; print equations in a form suitable for LaTeX output?

## Value

a one-column character matrix, one row for each equation

## Author(s)

Michael Friendly, John Fox, and Phil Chalmers

## References

Fox, J. and Friendly, M. (2016). "Visualizing Simultaneous Linear Equations, Geometric Vectors, and Least-Squares Regression with the matlib Package for R". useR Conference, Stanford, CA, June 27 - June 30, 2016.

## See Also

`plotEqn`, `plotEqn3d`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51``` ``` A <- matrix(c(2, 1, -1, -3, -1, 2, -2, 1, 2), 3, 3, byrow=TRUE) b <- c(8, -11, -3) showEqn(A, b) # show numerically x <- solve(A, b) showEqn(A, b, vars=x) showEqn(A, b, simplify=TRUE) showEqn(A, b, latex=TRUE) # lower triangle of equation with zeros omitted (for back solving) A <- matrix(c(2, 1, 2, -3, -1, 2, -2, 1, 2), 3, 3, byrow=TRUE) U <- LU(A)\$U showEqn(U, simplify=TRUE, fractions=TRUE) showEqn(U, b, simplify=TRUE, fractions=TRUE) #################### # Linear models Design Matricies data(mtcars) ancova <- lm(mpg ~ wt + vs, mtcars) summary(ancova) showEqn(ancova) showEqn(ancova, simplify=TRUE) showEqn(ancova, vars=round(coef(ancova),2)) showEqn(ancova, vars=round(coef(ancova),2), simplify=TRUE) twoway_int <- lm(mpg ~ vs * am, mtcars) summary(twoway_int) car::Anova(twoway_int) showEqn(twoway_int) showEqn(twoway_int, reduce=TRUE) showEqn(twoway_int, reduce=TRUE, simplify=TRUE) # Piece-wise linear regression x <- c(1:10, 13:22) y <- numeric(20) y[1:10] <- 20:11 + rnorm(10, 0, 1.5) y[11:20] <- seq(11, 15, len=10) + rnorm(10, 0, 1.5) plot(x, y, pch = 16) x2 <- as.numeric(x > 10) mod <- lm(y ~ x + I((x - 10) * x2)) summary(mod) lines(x, fitted(mod)) showEqn(mod) showEqn(mod, vars=round(coef(mod),2)) showEqn(mod, simplify=TRUE) ```

matlib documentation built on April 4, 2018, 5:03 p.m.