I need to find a matrix A
whose dimensions will be 1 x n
and I have input matrix X
whose dimensions are n x m
and another matrix Y
whose dimensions are 1 x m
.
I have the following equation:
$A * X = Y$
To find A
we can write the above equation as
$A = Inverse(X) * Y$
right?
But, as X
is not a square matrix we cannot have its inverse. So, what will be the best possible way to solve A
?
After a fair bit of research I have found that $X = L * B$ where L
is the left inverse of A
. Is this the right approach? If so how to find the left inverse in R Programming
? I have tried the below code, but A
and the PredA
should have same values which they are not.
m = 5
n = 10
A = t(matrix(runif(n)))
X = matrix(round(runif(m * n)), nrow = n)
# Y = t(matrix(runif(n)))
# # Usually A * X = Y
Y = A %*% X
library(MASS)
# # Now to find A (Predicted A)
PredA = Y %*% ginv(X)
# # PredA should be equal to A right?
PredA == A # Returns False
What could be the basic thing that I'm missing?
I have tried two approaches:
$PredA1 = (X'*Y) * Inv(X*X')$
$PredA2 = Y * Inv(X)$
both resulting in same values (PredA1 = PredA2
) but none of them are equal to the actual value (PredA1 not = A
) and (PredA2 not = A
)
NOTE: I am new to Matrix Algebra. So, I've surely missed something very basic