Solving the problem posted by Jacob Silver: C31
Question C31 asks to solve the following set of linear equations:
3x + 2y = 1 x - y = 2 4x + 2y = 2
To solve this, we can use the matrix form of the equations:
Matrix A:
\[ A = \begin{pmatrix} 3 & 2 \\ 1 & -1 \\ 4 & 2 \end{pmatrix} \]
Matrix B:
\[ B = \begin{pmatrix} 1 \\ 2 \\ 2 \end{pmatrix} \]
To solve this in R, since this is an over-determined system (more equations than unknowns), I’ll use the MASS package:
library(MASS)
# matrix of coefficients A and the constant vector B
A <- matrix(c(3, 2, 1, -1, 4, 2), nrow = 3, byrow = TRUE)
B <- c(1, 2, 2)
# pseudoinverse of A
A_pinv <- ginv(A)
# solving for x
x <- A_pinv %*% B
print(x)
## [,1]
## [1,] 1
## [2,] -1