Practical 2
Practical 2
Practical 2
a1 a2 a3
[1,] -0.29629630 -0.07407407 0.4074074
[2,] -0.07407407 0.48148148 -0.1481481
[3,] 0.40740741 -0.14814815 -0.1851852
Example:
A group took a trip on a bus, at $3 per child and $3.20
per adult for a total of $118.40. They took
the train back at $3.50 per child and $3.60 per adult for
a total of $135.20.
How many children, and how many adults?
First, let us set up the matrices (be careful to get the
rows and columns correct!):
Now we have the inverse we can solve using:
X = BA-1
There were 16 children and 22 adults!
The answer almost appears like magic. But it is based
on good mathematics.
Calculations like that (but using much larger
matrices) help Engineers design buildings,
are used in video games and computer
animations to make things look 3-
dimensional, and many other places.
Matrix Transpose in R
Transpose of a matrix is an operation in which we
convert the rows of the matrix in column and column of
the matrix in rows. The general equation for performing
the transpose of a matrix is as follows.
Aij = Aji where i is not equal to j
Example:
Matrix M ---> [1, 8, 9
12, 6, 2
19, 42, 3]
Transpose of M
Output ---> [1, 12, 19
8, 6, 42,
9, 2, 3]
Transpose of a Matrix can be performed in two ways:
Finding the transpose by using the t()
function
filter_none
brightness_4
# R program for Transpose of a Matrix
# create a matrix with 2 rows
# using matrix() method
M <- matrix(1:6, nrow = 2)
# print the original matrix
print(M)
# transpose of matrix
# using t() function.
t <- t(M)
# print the transpose matrix
print(t)
Output:
[, 1] [, 2] [, 3]
[1, ] 1 3 5
[2, ] 2 4 6
[, 1] [, 2]
[1, ] 1 2
[2, ] 3 4
[3, ] 5 6