Posts

You could have invented the determinant

Image
I'm going to talk about how a geometric intuition becomes the definition of the determinant. As many of you already know, the determinant of a matrix is the (hyper)volume of the (hyper)parallelepiped whose edges are the (row or column) vectors of the matrix. This page on Wolfram gives you an interactive visualization of a parallelogram or a parallelepiped while showing the corresponding determinant. There are abundant sources on the internet (many on math.stackexchange.com ) that give more-or-less the same explanation as I just said above, but most of them don't explain why. That's what I want to discuss in this post. First goal: Define area in 2D I'll motivate this discussion with a simple question: how to define volume in a Euclidean space? I'm kidding. That question is actually not that simple, and people have gone to great lengths to answer that. Let me simplify it a bit more, quite gratuitously, so that we ...

C++: Hidden array copy operation

A fixed-size array type in C++ does not have a copy constructor or a copy assignment. The following code won't compile: int a[2] = {1, 2}; int b[2] = a; A recommended way to fix this is to use std::array from the header <array> instead because it supports copying (and more): std::array<int, 2> a = {1, 2}; std::array<int, 2> b = a; Alternatively, one can resort to std::copy in <algorithm> , or the old school std::memcpy in <cstring> . Interestingly, the C++ language does have a way to copy fixed-size arrays, but it can only be accessed via a lambda capture. Here's an example that demonstrates that an array copy is actually done when it's captured by value into a lambda expression: (click this repl.it link if you want to play with the code) #include <functional> #include <iostream> using namespace std; struct LoudInt { int v; LoudInt(int v): v{v} { cout << "LoudIn...

Adding code snippets to Blogger posts (or any HTML pages)

As a preparation for writing a blog post about coding, I had to look for a way to show code snippets nicely on my post. I found highlight.js to be the best solution but the way to use it is not super straightforward. I'll explain how I use it on this blog post. Using highlight.js To "install" highlight.js, simply add the following code inside the <head> section: <link href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/styles/default.min.css' rel='stylesheet'/> <script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/highlight.min.js'/> <script>hljs.initHighlightingOnLoad();</script> If you're using Blogger, this should be done in the theme html file, which you can get to by going to the "Theme" tab, clicking the "Customize" button, and choosing "Edit HTML". This is just like how I added MathJax to Blogger . After we have installed highlight.j...

Matrix Multiplication

In highschool, I was introduced to these operations on matrices: Add matrices. Multiply matrices. Compute the determinant of a matrix. Invert a matrix. Solve a system of linear equations with Cramer's rule . There were a lot of mysteries around why and how that did not get explained. Years passed and I entered college, yet those mysteries never were explained despite the frequent use of those operations. Here's a list of some mysteries that occupied my mind for quite some time: Why is matrix multiplication defined that way? Why is matrix multiplication associative ? (This means $A(BC) = (AB)C$.) Why is the determinant defined that way? Why does Cramer's rule work? Why is the matrix of cofactors defined that way? I eventually knew the answers, but I wish that I had had someone tell me sooner because such a simple explanation would suffice to answer all those questions. (Some of you might disagree on the use of ...