[R] Printing a list of simultaneous equations
Michael Friendly
|r|end|y @end|ng |rom yorku@c@
Sat Jan 19 19:14:59 CET 2019
John-
Don't try to forge a new wheel, when you can get one ready made
and it might fit your wagon.
Check out the `matlib` package on CRAN and devel on github:
https://github.com/friendly/matlib
install.packages("matlib")
library(matlib)
A <- matrix(c(1,2,3, -1, 2, 1), 3, 2)
b <- c(2,1,3)
showEqn(A, b)
> showEqn(A, b)
1*x1 - 1*x2 = 2
2*x1 + 2*x2 = 1
3*x1 + 1*x2 = 3
>
sound like what you want. Various vignettes illustrate this, also
showing how to plot linear equations in 2D, 3D.
browseVignettes("matlib")
On 1/18/2019 7:02 AM, Sorkin, John wrote:
> I am trying to print a list of equations in an easily readable form. At this time all I can get is a series of characters enclosed in quotation marks rather than equations with numbers and equal signs. What I get is
>
>
> y equalsigns x z
> eq1 "0.5" "=" "1" "2"
> eq2 "4" "=" "2" "3"
>
>
> When what I want is
>
> y x z
>
> eq1 0.5 = 1 2
> eq2 4.0 = 2 3
>
>
> I am enclosing my R code below:
>
> # Create matrix of coefficients of independent variables.
> a <- matrix(c(1,2,2,3),nrow=c(2,2),byrow=TRUE)
> dimnames(a)<-list(c("eq1","eq2"),c("x","z"))
> cat("Matrix of independent variables\n")
> a
>
> # Create vector of dependent variables.
> b <- matrix(c(0.5,4.0),nrow=c(2,1))
>
> dimnames(b)<-list(c("eq1","eq2"),c("y"))
> cat("Vector of dependent variables","\n")
> b
>
> cat("System of equations to be solved")
> equalsigns <- c("=","=")
> cbind(b,equalsigns,a)
>
>
>
>
> Thank you,
>
> John
>
>
>
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
> [[alternative HTML version deleted]]
>
--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, ASA Statistical Graphics Section
York University Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele Street Web: http://www.datavis.ca | @datavisFriendly
Toronto, ONT M3J 1P3 CANADA
More information about the R-help
mailing list