Question SSLE.C30

A First Course in Linear Algebra, Section SSLE: Solving Systems of Linear Equations

Find all solutions to this linear system:

\(x + y = 5\)
\(2x - y = 3\)


1. Use the solve function

# Create a matrix with the coefficients of the system
a <- matrix(c(1, 2, 1, -1), nrow=2, ncol=2)
a
##      [,1] [,2]
## [1,]    1    1
## [2,]    2   -1
# Create a matrix with the right-hand side of the system
b <- matrix(c(5, 3), nrow=2, ncol=1)
b
##      [,1]
## [1,]    5
## [2,]    3
# Solve for the unknown variables
s <- solve(a,b)
s
##          [,1]
## [1,] 2.666667
## [2,] 2.333333

Using the solve function, we find that \(x \approx 2.67\), or \(\frac{8}{3}\), and \(y \approx 2.33\), or \(\frac{7}{3}\).


2. Check Results

To check our accuracy, we can plug \(x\) and \(y\) into the original equation and evaluate whether we get the right-hand side in return.

# Assign x and y to the output of the solve function
x <- s[1]
y <- s[2]

x
## [1] 2.666667
y
## [1] 2.333333
# Equation 1
x + y
## [1] 5
# Equation 2
(2*x) - y
## [1] 3

We get an output of \(5\) for Equation 1 and \(3\) for Equation 2. This matches the right-hand side of the original system.


3. Solution

Thus, the solution to the system is \(x = \frac{8}{3}\), \(y = \frac{7}{3}\).