🎓 A1Learner
🔍
0 of 47 lessons completed

Julia Linear Algebra

Linear algebra is the study of vectors and matrices and the operations that combine them. It gives a short way to solve systems of equations and to measure vector size.

A matrix times a vector gives a new vector

The code multiplies a diagonal matrix by a vector. The printout shows the new vector.

using LinearAlgebra
A = [2.0 0.0; 0.0 3.0]
x = [1.0, 2.0]
println(round.(A * x, digits=6))

The backslash operator solves a system

The code solves for the vector that gives a known result. The printout shows the solved vector.

using LinearAlgebra
B = [2.0 0.0; 0.0 4.0]
b = [4.0, 8.0]
println(round.(B \ b, digits=6))

A norm measures vector length

The code measures a vector with sides three and four. The printout shows its length.

using LinearAlgebra
println(round(norm([3.0, 4.0]), digits=6))

Example

using LinearAlgebra
C = [1.0 2.0; 3.0 4.0]
y = [1.0, 1.0]
println(round.(C * y, digits=6))
println(round.(C \ [3.0, 7.0], digits=6))
println(round(norm(y), digits=6))

Key points

  • Vector: a list of numbers that stands for a point or a direction.
  • Matrix: a table of numbers arranged in rows and columns.
  • Multiplication: multiplying a matrix by a vector gives a new vector.
  • Solve: solving with the backslash operator finds the vector that makes a matrix times a vector equal a given vector.
  • Norm: the norm of a vector is its length.

In this example, the code multiplies a matrix by a vector. It solves a system with the backslash operator. It measures the length of the vector.

Note

results are rounded to six digits so printed floats stay short.

Try it Yourself

Edit the code, then press Run.

Running is simulated · JuliaHub

Exercise

What does A \ b find?