Learning linear algebra with Scala
I recently came across 3Blue1Brown's Essence of linear algebra YouTube playlist. As the title implies, it covers the basics of linear algebra. Instead of focusing on the math though, it lays down a foundation that gives you a visual intuition that helps you reason about it. I would highly recommend this if you've never really grasped linear algebra that you've been taught in university, or if you've never gotten around learning about linear algebra at all.
While watching the first video, I decided to code it all out in Scala to let it materialize. That's when it really clicked for me. While typing out the float multiplications I noticed just how simple the underlying operations are. It now really makes sense to me that GPU's are optimized for floating point operations as all vector and matrix manipulations are encoded by multiplying or dividing floats. Loving it, thanks Grant!
Now it's your turn to get your hands dirty. I've open sourced the unit tests here. There's also a branch with my solutions if you feel the need to cheat ;) These are the functions you'll be implementing while you watch the videos:
import MatrixImplicits._
import model.{Matrix2, Vector2}
object VectorImplicits {
implicit class ArithmeticVectorImplicits(v: Vector2) {
def +(v2: Vector2): Vector2 = ???
def *(scalar: Float): Vector2 = ???
def *(m: Matrix2): Vector2 = ???
def isLinearlyDependent(v2: Vector2): Boolean = ???
}
}
import VectorImplicits._
import model.{Matrix2, Vector2}
object MatrixImplicits {
implicit class ArithmeticMatrixImplicits(m: Matrix2) {
def *(m2: Matrix2): Matrix2 = ???
def *(scalar: Float): Matrix2 = ???
def determinant(): Float = ???
def changesOrientation(): Boolean = ???
def inverse(): Option[Matrix2] = ???
}
}
There might be a lot of terms you're not familiar with yet, but don't worry, it will all make sense when you go through the videos.
If you have any additions or corrections, I'd really appreciate a fork and merge request.
Happy hacking!