From 9423d7c1fae0c46792437e11fc4ae8635b01c523 Mon Sep 17 00:00:00 2001 From: Michael Friendly Date: Tue, 30 Jul 2024 14:23:54 -0400 Subject: [PATCH] add symb_matrix() --- DESCRIPTION | 4 +-- NAMESPACE | 1 + NEWS.md | 4 +++ {dev => R}/symb-matrix.R | 4 +-- README.md | 2 +- man/symb_matrix.Rd | 60 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 5 deletions(-) rename {dev => R}/symb-matrix.R (96%) create mode 100644 man/symb_matrix.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 924d4216..a84cf698 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,8 +2,8 @@ Package: matlib Type: Package Title: Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics -Version: 0.9.8 -Date: 2024-07-22 +Version: 0.9.9 +Date: 2024-07-30 Authors@R: c(person(given = "Michael", family = "Friendly", role=c("aut", "cre"), email="friendly@yorku.ca", comment=c(ORCID="0000-0002-3237-0941")), diff --git a/NAMESPACE b/NAMESPACE index b25962a9..3509c343 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,6 +61,7 @@ export(showEqn) export(svdDemo) export(swp) export(symMat) +export(symb_matrix) export(tr) export(vandermode) export(vec) diff --git a/NEWS.md b/NEWS.md index f966cbdf..2260ab5a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# matlib 0.9.9 + +- added `symb_matrix()` to create a symbolic matrix + # matlib 0.9.8 - added `circle()` for drawing circles in diagrams diff --git a/dev/symb-matrix.R b/R/symb-matrix.R similarity index 96% rename from dev/symb-matrix.R rename to R/symb-matrix.R index e1d0e721..5b748611 100644 --- a/dev/symb-matrix.R +++ b/R/symb-matrix.R @@ -30,12 +30,12 @@ #' \code{"v"} uses vertical bars \code{"|", "|"}; #' \code{"V"} uses double vertical bars \code{"||", "||"}; #' \code{""} generates a plain matrix without delimeters -#' @param indent characters to indent each line +#' @param indent characters to indent each line [not yet implemented] #' #' @author Michael Friendly #' @export #' @examples -#' symb_matrix("x", rows = "n", cols = "m", brackets = "p) # default +#' symb_matrix("x", rows = "n", cols = "m", brackets = "p") # default #' symb_matrix("\\beta", "p", "q") #' #' # numeric rows/cols diff --git a/README.md b/README.md index 2accd9f8..acf9756c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ **Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics**, http://friendly.github.io/matlib/ -Version 0.9.8 +Version 0.9.9 These functions were originally designed for tutorial purposes in teaching & learning matrix algebra ideas using R. In some cases, functions are provided for concepts or computations available diff --git a/man/symb_matrix.Rd b/man/symb_matrix.Rd new file mode 100644 index 00000000..8e4fcc30 --- /dev/null +++ b/man/symb_matrix.Rd @@ -0,0 +1,60 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/symb-matrix.R +\name{symb_matrix} +\alias{symb_matrix} +\title{Create a Symbolic Matrix for LaTeX} +\usage{ +symb_matrix( + symbol = "x", + rows = "n", + cols = "m", + brackets = c("p", "b", "B", "v", "V", ""), + indent = "\\t" +) +} +\arguments{ +\item{symbol}{A single character, the name of the matrix elements} + +\item{rows}{Number of rows, a single character representing rows symbolically, or an integer, generating +that many rows.} + +\item{cols}{Number of columns, a single character representing rows symbolically, or an integer, generating +that many columns.} + +\item{brackets}{Type of brackets: \code{"p"} uses parentheses \code{"(", ")"}; +\code{"b"} uses square brackets \code{"[", "]"}; +\code{"B"} uses braces \code{"{", "}"}; +\code{"v"} uses vertical bars \code{"|", "|"}; +\code{"V"} uses double vertical bars \code{"||", "||"}; +\code{""} generates a plain matrix without delimeters} + +\item{indent}{characters to indent each line [not yet implemented]} +} +\description{ +Constructs the latex code for a symbolic matrix, like: +\begin{pmatrix} + x_{11} & x_{12} & \\dots & x_{1m} \\ + x_{21} & x_{22} & \\dots & x_{2m} \\ + \\vdots & \\vdots & \\ddots & \\vdots \\ + x_{n1} & x_{n2} & \\dots & x_{nm} + \end{pmatrix} + +Alternatively, the number of rows and/or columns can be integers, generating a matrix of given size. + +As presently designed, the function outputs the LaTeX code to the console, which can then be copied/pasted into a document. +} +\details{ +This implementation assumes that the \code{amsmath} package will be available. +} +\examples{ +symb_matrix("x", rows = "n", cols = "m", brackets = "p") # default +symb_matrix("\\\\beta", "p", "q") + +# numeric rows/cols +symb_matrix("y", "p", 5) +symb_matrix("y", 4, "q") +symb_matrix("y", 4, 4) +} +\author{ +Michael Friendly +}