friendly / matlib

Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics
http://friendly.github.io/matlib/
65 stars 16 forks source link

Problem with plotEqn #41

Closed aoandrade closed 1 year ago

aoandrade commented 3 years ago

I am trying to use the package matlib, however see the type of error I am getting.

If necessary, you can improve the package.

library(matlib) # use the package

A <- matrix(c(0.1, 0.3, 0.5, 0.9, 0.7,0.5), 3, 2)

b <- c(-0.3,-0.1, 0.1)

showEqn(A, b)

plotEqn(A,b)

Solve(A, b) # unique solution

plotEqn(A,b)

0.x[1] + 0.9*x[2] = -0.3

0.3x[1] + 0.7x[2] = -0.1

0.5x[1] + 0.5x[2] = 0.1

Error in parse(text = sub("=", "==", labels[i])) :

:1:5: unexpected symbol 1: 0.x ^
philchalmers commented 1 year ago

I ran your code with the latest version of the package, however I do not see the issue.

library(matlib)
A <- matrix(c(0.1, 0.3, 0.5, 0.9, 0.7,0.5), 3, 2)
b <- c(-0.3,-0.1, 0.1)
showEqn(A, b)
#> 0.1*x1 + 0.9*x2  =  -0.3 
#> 0.3*x1 + 0.7*x2  =  -0.1 
#> 0.5*x1 + 0.5*x2  =   0.1
plotEqn(A,b)
#> 0.1*x[1] + 0.9*x[2]  =  -0.3 
#> 0.3*x[1] + 0.7*x[2]  =  -0.1 
#> 0.5*x[1] + 0.5*x[2]  =   0.1

Solve(A, b) # unique solution
#> x1    =   0.6 
#>   x2  =  -0.4 
#>    0  =     0
plotEqn(A,b)
#> 0.1*x[1] + 0.9*x[2]  =  -0.3 
#> 0.3*x[1] + 0.7*x[2]  =  -0.1 
#> 0.5*x[1] + 0.5*x[2]  =   0.1

It's possible this has to do with an earlier version of the package, so feel free to update from Github directly or wait until the next CRAN release.

Created on 2022-12-06 with reprex v2.0.2