From 3d53ab464839be6672e21546e67eb174e4718302 Mon Sep 17 00:00:00 2001 From: Michael Friendly Date: Sun, 4 Aug 2024 12:46:40 -0400 Subject: [PATCH] fix import in matrix2latex --- R/matrix2latex.R | 1 + man/symbolicMatrix.Rd | 7 ++++++- vignettes/linear-equations.Rmd | 10 +++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/matrix2latex.R b/R/matrix2latex.R index c551cb9e..8ab5f004 100644 --- a/R/matrix2latex.R +++ b/R/matrix2latex.R @@ -28,6 +28,7 @@ #' @param ... additional arguments passed to \code{xtable::xtableMatharray()} #' @importFrom xtable xtableMatharray #' @importFrom dplyr case_when +#' @importFrom utils capture.output #' @author Phil Chalmers #' @export #' @examples diff --git a/man/symbolicMatrix.Rd b/man/symbolicMatrix.Rd index 211bfa88..4611673d 100644 --- a/man/symbolicMatrix.Rd +++ b/man/symbolicMatrix.Rd @@ -23,7 +23,8 @@ symbolicMatrix( \item{symbol}{name for matrix elements, character string. For LaTeX symbols, the backslash must be doubled because it is an escape character in R. That is, you must use \code{symbol = "\\\\beta"} to get \eqn{\beta}. Alternatively, this can be an -R matrix object, containing LaTeX code for the elements.} +R matrix object, containing LaTeX code for the elements. For a row or column vector, use +\code{matrix(..., nrow=1)} or \code{matrix(..., ncol=1)}} \item{nrow}{Number of rows, a single character representing rows symbolically, or an integer, generating that many rows.} @@ -170,6 +171,10 @@ symbolicMatrix("\\\\beta", comma=TRUE, exponent="-1") symbolicMatrix("\\\\beta", comma=TRUE, transpose=TRUE) symbolicMatrix("\\\\beta", comma=TRUE, exponent="-1", transpose=TRUE) +# for a row/column vector, wrap in matrix() +symbolicMatrix(matrix(LETTERS[1:4], nrow=1)) +symbolicMatrix(matrix(LETTERS[1:4], ncol=1)) + # represent the SVD, X = U D V' symbolically X <- symbolicMatrix("x", "n", "p") U <- symbolicMatrix("u", "n", "k") diff --git a/vignettes/linear-equations.Rmd b/vignettes/linear-equations.Rmd index 5f1c8b14..032cdbd4 100644 --- a/vignettes/linear-equations.Rmd +++ b/vignettes/linear-equations.Rmd @@ -106,7 +106,7 @@ all.equal( R(A), R(cbind(A,b)) ) # consistent? ``` You can see this in the result of reducing $\mathbf{A} | \mathbf{b}$ to echelon form, where the last row indicates the inconsistency. -```{r} +```{r echelon} echelon(A, b) ``` `Solve()` shows this more explicitly: @@ -116,7 +116,7 @@ Solve(A, b, fractions=TRUE) An approximate solution is sometimes available using a generalized inverse. -```{r} +```{r ginv} x <- MASS::ginv(A) %*% b x ``` @@ -124,7 +124,7 @@ x Plot the equations. You can see that each pair of equations has a solution, but all three do not have a common, consistent solution. -```{r} +```{r plotEqn4} par(mar=c(4,4,0,0)+.1) plotEqn(A,b, xlim=c(-2, 4)) points(x[1], x[2], pch=15) @@ -139,7 +139,7 @@ have a unique solution if all planes intersect in a point. ### Three consistent equations -```{r} +```{r three-eqn} A <- matrix(c(2, 1, -1, -3, -1, 2, -2, 1, 2), 3, 3, byrow=TRUE) @@ -171,7 +171,7 @@ echelon(A, b, verbose=TRUE, fractions=TRUE) Plot them. `plotEqn3d` uses `rgl` for 3D graphics. If you rotate the figure, you'll see an orientation where all three planes intersect at the solution point, $\mathbf{x} = (2, 3, -1)$ -```{r plotEqn1, webgl=TRUE} +```{r plotEqn3, webgl=TRUE} plotEqn3d(A,b, xlim=c(0,4), ylim=c(0,4)) ```