Chichi
Chichi

Reputation: 11

Having problem with having a fraction result

I was trying to solve a basic matrix problem. .

I used :

A<- matrix(c(2,7,5,7), 2,2)
b<- c(8,12)
solve(A,b, fractions = TRUE)

However, my result only gives me results in decimal places. How can get fractions results?

I also want to plot this equation above. I used:

plotEqn(A,b)

However, it tells me this equation can't be found. Can I have some advice please?

Thank you very much!!!

Upvotes: 1

Views: 35

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226332

For your first question,

MASS::fractions(solve(A,b))

gives {4/21, 32/21} (note that you won't always be guaranteed the correct answer, as R does floating-point calculation unlike e.g. Mathematica)

For your second question, it looks like the plotEqn() function is in the matlib package: if you have that package installed, then either first loading the package (with library("matlib")) or matlib::plotEqn(A,b) should work.

On closer inspection it looks like you want matlib::Solve() for the first question (note that R is case-sensitive, so solve and Solve are different):

library(matlib)
Solve(A,b, fraction=TRUE)
## x1    =   4/21 
## x2  =  32/21 

Upvotes: 2

Related Questions