Week 2 - Linear Algebra
Week 2 - Linear Algebra
Linear Algebra-FAQ’s
Errors
1. Getting an error while finding values of variables
the code is
A=matrix(c(1,2,3,4,5,6,7,8,9),ncol=3,byrow=F)
b=c(2,3,4)
x=solve(A)%*%b
The error is " Lapack routine dgesv: system is exactly singular: U[3,3] = 0"
Answer:
Please check the determinant of the matrix. The determinant of the matrix is
0. Hence it cannot be solved. That is why it throws up the error.
3. Already installed the package ‘reshape2’’but still, getting the following error.
> library(reshape2)
Error: package or namespace load failed for ‘reshape2’ in
loadNamespace
(i,c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
there is no package called ‘stringi’
Answer:
While installing the packages we have to install the dependencies as well.
Inverse
1. How to perform A inverse in R?.
Answer:
To calculate the inverse of A, use the command solve(A).
2. The R Code doesn't show the multiplication of inverse of A with B. How to
represent the inverse of A in R also?
Answer:
To calculate the inverse of a matrix , please use the command inv(A) or
solve (A) Please find attached snapshots to calculate the inverse of a matrix
Null space
1. Explain the concept of the size of the null space. It is being said that the
Beta has to be a 3 x 1, so does it not mean that the size of Beta in this
example is 3
Answer:
Size of the null space is the dimension of the null space matrix. In this case,
It is a matrix of size 3*1.
2. Is there a way or method available in R through which one can find Null
Space vector in R?
Answer:
nullspace() is the function in R
3. How is the size of the null space calculated in R?
Answer:
To calculate the nullspace, please use the command
nullspace(matrix_name).
To calculate the size of the nullspace , use the command dim(matrix_name).
Please find attached snapshot for your reference.
Pracma library
1. What does library pracma contain?
Answer:
By loading library called pracma, it allows you to perform some matrix
operations such as finding the rank of the matrix.
Please make sure you installed the package pracma before loading it as
library
Rank
1. Explain the difference between the functions Rank() and rank() in R?
Answer:
Rank() returns the sample ranks of the values in a vector. Ties (i.e., equal
values)
where as Rank() gives the no.of linearly independent columns of the matrix.
2. The Rank provides us the number of independent columns in the matrix &
Nullity provides the number of columns that are linearly dependent. So for a
given matrix, how to identify what are the columns that are linearly
dependent?
Answer:
Nullity provides the number of linear relationships among columns. Using
the concept of Rank of the matrix we can only identify the no. of linearly
related columns.
Solving linear equations
1. Matrix A where m = n and A if full rank and |A| = 0. does A have any solution?
Answer:
If you have a matrix A where m= n , both cannot happen at the same time.
The conditions for solving linear equations have been attached below.
Vectors
1. Why are basis vectors not unique?
Answer:
There are many ways to define a basis vector. However, all share the same
properties. Basis is a collection of vectors that are linearly independent and
span the whole space.
2. Can we insert row or column in between matrix?
Answer:
Yes! Rbind () and cbind () is used to insert row and column matrix
respectively.
Principal component analysis
1. Can you please give a practical application in data science where projection
and principal component analysis is used?
Answer:
Projection is a very widely used in concept in data science. While there are
many applications, whenever we have dimensionality reduction, we project
data onto the basis vectors that we choose. In PCA, the data is projected
along the chosen set of directions of maximum variance, in classification
data is projected onto directions that enhance separability and so on.