Applications of Linear Algebra in Computer Science
Applications of Linear Algebra in Computer Science
BSCS 2-A
Definition
Introduction
When you take a digital photo with your phone or transform the image in Photoshop, when
you play a video game or watch a movie with digital effects, when you do a web search
or make a phone call, you are using technologies that are built upon linear algebra. Linear
algebra is built upon two elements, the matrix and the vector.
Why linear algebra is important?
It is vital in multiple areas of CS because linear equations are easy to solve.
It coverts large number of problems to matrix and thus we solve the matrix.
Linear algebra in CS
Linear algebra in CS can be divided into two categories:
i. Linear algebra for spatial quantities
This part deals with 2,3 or 4
dimensional vectors and
rotations, projections and other
related matrix operations that
have some spatial interpretation.
This type of linear algebra
mostly comes up in computer
graphics and physics simulations.
2
Answer:
1. The total resistance is 7 ohms. With a 9volt potential, the flow will be 9/7 amperes.
Incidentally, the voltage drops will then be 27/7 volts across the 3ohm resistor,
and 18/7 volts across each of the two 2 ohm resistors.
2. One way to do this network is to note that the 2ohm resistor on the left has a
voltage drop across it of 9 volts (and hence the flow through it is 9/2 amperes, and
the remaining portion on the right also has a voltage drop of 9 volts, and so is
analyzed as in the prior item. We can also use linear systems.
which yields the unique solution i1 = 81/14, i1 = 9/2, i2 = 9/7, and i3 = 81/14.
Of course, the first and second paragraphs yield the same answer. Essentially, in
the first paragraph we solved the linear system by a method less systematic than
Gauss' method, solving for some of the variables and then substituting.
3. Using these variables
4
2. Cryptography
There are some essential concepts concerning Cryptography.
Although there are different methods to encrypt and decrypt messages, we'll focus on
a linear algebra based cipher, the
Hill cipher, which uses a matrix as
a cipher to encode a message, and
it's extremely difficult to break
when a large matrix is used. The
receiver of the message decodes it
using the inverse of the matrix.
This first matrix is called the
encoding matrix and its inverse is
called the decoding matrix.
84 104 101 32 112 97 115 115 119 111 114 100 32 105 115 58 32 78 67 83 45 50
48 49 52
5
Coding matrix
We choose the following 4x4 invertible matrix A:
1 −1 −1 1
2 −3 −5 4
[ ]
−2 −1 −2 2
3 −3 −1 2
We convert the sequence of numbers related to plaintext into a matrix, splitting it into
column vectors of 4 elements (the order of the encoding matrix). We fill out the last
column with zeros as necessary to complete the 4 elements.
84 112 119 32 32 45 52
[ 104 97 111 105 78 50 0 ]
101 115 114 115 67 48 0
32 115 100 58 83 49 0
We now encode the message by multiplying the encoding matrix A by the above matrix
B. The result is the cipher matrix C:
The columns of this matrix give the encoded message. The message could be
transmitted in the following linear form:
-89 -521 -410 -97 15 -182 -321 160 -6 -265 -377 110 -130 -594 -283 -218 -30 -173 -
110 -39 -4 -104 -138 35 52 104 -104 156
To decode the message, write the sequence of numbers you received as a matrix, by
splitting the numbers into column vectors of 4 elements. The resulting matrix from this
process will be equal to the cipher matrix C. You must know the inverse of the
encoding matrix:
6
6 −1 0 −1
22 −4 1 −4
Inv(A) = [ ]
14 −3 1 −2
31 −6 2 −5
Multiply that matrix (decoding matrix) by the cipher matrix C. Form back the resulting
matrix (it'll be equal to matrix B) into a continuous sequence of numbers and map the
numbers to their corresponding characters, to get the original message.
3. Computer Graphics
In computer graphics every element is represented by a matrix and so all images
can be represented in matrix form.
In video games
As we know linear algebra is study of the vectors.
If your game involves the position of an on-screen
button, the direction of a camera or the velocity of
the race car, you will have to use vectors in that
case. The better understanding of linear algebra
will help in better handling of vectors.
4. Machine Learning
Linear algebra is essential in machine learning in many ways and some are:
1. Building Block: Let me state it, Linear algebra is absolutely key to
understanding the calculus and statistics you need in machine learning. Better
linear algebra will lift your game across the board. Seriously.
2. Deeper Intuition: If you can understand machine learning methods at the
level of vectors and matrices you will improve your intuition for how and when
they work.
7
3. Get More from Algorithms: A deeper understanding of the algorithm and its
constraints will allow you to customize
its application and better understand
the impact of tuning parameters on the
results.
4. Implement Algorithms from Scratch:
You require an understanding of linear
algebra to implement machine learning
algorithms from scratch. At the very
least to read the algorithm descriptions
and at best to effectively use the
libraries that provide the vector and matrix operations.
5. Devise New Algorithms: The notation and tools of linear algebra can be used
directly in environments like Octave and MATLAB allowing you to prototype
modifications to existing algorithms and entirely new approaches very quickly.