Applications of Linear Algebra and Multivariable Calculus

These pages present the example applications of the content covered in 8BA060: Linear algebra and multivariable calculus.

Week 1A: Fitting a curve to data points.

Consider three data points : {x,y}={1,0},{0,0}\{x, y\} = \{-1, 0\}, \{0,0\} and {0,1}\{0,1\}. We fit a (non-linear!) polynomial relation of the form,

y(x)=ax2+bx+c.y(x) = ax^2 + bx + c.

Noting that the terms scale linearly with their respective unknowns (a,b,ca, b, c). We can setup a system of linear equations,

(111001111)(abc)=(001).\begin{pmatrix} 1 & -1 & 1\\0 & 0 & 1 \\ 1 & 1 & 1\end{pmatrix} \begin{pmatrix}a\\b\\c\end{pmatrix} = \begin{pmatrix}0\\0\\1\end{pmatrix}.

An echelon form of the augmented matrix is,

(111002010010),\begin{pmatrix}1&-1&1&0\\0&2&0&1\\0&0&1&0\end{pmatrix},

The solution (a,ba, b and cc) for the parabola is thus; c=0c = 0, b=12b = \frac{1}{2} and a=12a = \frac{1}{2},

y=12x2+12x.y = \frac{1}{2}x^2 + \frac{1}{2}x.

We may visually verify in Octave/Matlab.

% Plot function for -2 < x < 2.
fplot (@(x) 0.5*x.^2 + 0.5*x, [-2, 2], "linewidth", 2, 'red');
hold on
% data points
scatter ([-1, 0, 1], [0, 0, 1], 'filled');
The resulting figure with some additional formatting

Polynomial fit with a free variable

Reconsider the three data points : {x,y}={1,0},{0,0}\{x, y\} = \{-1, 0\}, \{0,0\} and {0,1}\{0,1\}. Lets try to fit a polynomial relation of the form,

y(x)=ax3+bx2+cx+d.y(x) = ax^3 + bx^2 + cx + d.

The linear system now reads,

(111100011111)(abcd)=(001),\begin{pmatrix} -1 & 1 & -1 & 1\\0 &0 & 0 & 1 \\ 1&1 & 1 & 1\end{pmatrix} \begin{pmatrix}a\\b\\c\\d\end{pmatrix} = \begin{pmatrix}0\\0\\1\end{pmatrix},

with an echelon form of the augmented below having three (underlined) pivots for four unknowns, indicating one free variable.

(1_111102_0210001_0).\begin{pmatrix} \underline{1} & 1 & 1 & 1 & 1\\0 & \underline{2} & 0& 2 & 1 \\ 0&0 & 0 & \underline{1} & 0\end{pmatrix}.

The solution is: d=0d = 0, the free variable: c=tc = t, b=12b = \frac{1}{2} and a=12ta = \frac{1}{2} - t. For t=12t = \frac{1}{2}, we obtain the previous parabolic solution. Using Octave, we may plot the solution for some some selected values of tt.

fplot (@(x) 0.5*x.^3+0.5*x.^2, [-1.1, 1.1], 'linewidth', 2,'red')
hold on
fplot (@(x) x.^3+0.5*x.^2-0.5*x, [-1.1, 1.1], 'linewidth', 2,'green')
fplot (@(x) -0.5*x.^3+0.5*x.^2+1*x, [-1.1, 1.1], 'linewidth', 2,'magenta')
scatter([-1,0,1],[0,0,1], 'filled')
Fit for serveral values of the free variable (t)

Thank you Gaussian elimination! for helping me to find these solutions.

Week 1B: Projection for computer graphics

Parallel projection

Technical drawings are often presented using various “side views” of an object via a so-called orthographic projection. Here a point in three-dimensional (3D) space (𝐱=(xyz)\mathbf{x} = \begin{pmatrix}x\\y\\z\end{pmatrix}) is transferred to 2D screen-space coordinates, 𝐩=(ij)\mathbf{p} = \begin{pmatrix}i\\j\end{pmatrix}. A simple projection onto the xyx-y plane is obtained by the linear map.

𝐩=(100010)𝐱\mathbf{p}=\begin{pmatrix}1 & 0 & 0\\ 0 & 1 & 0\end{pmatrix}\mathbf{x}

Since the matrix is already in echelon form we can directly conclude that this is onto but not one-to-one. Its kernel is 1D and given by t(001)t\begin{pmatrix}0\\0\\1\end{pmatrix}, with tt \in \mathcal{R}.

Orthographic projections of a house, Image by Kenny (Chris) on designbuildings.co.uk/

Perspective projection

A projection that better mimics our perception of the world is the so-called perspective projection. This is a linear map that is popular in graphics applications, and it is also given by a matrix transformation,

(xyd)=(A1,1A1,2A1,3txA2,1A2,2A2,3tyA3,1A3,2A3,3tz)(xyz1).\begin{pmatrix}x'\\y'\\d\end{pmatrix} = \begin{pmatrix} A_{1,1}&A_{1,2}&A_{1,3}&t_x\\ A_{2,1}&A_{2,2}&A_{2,3}&t_y\\ A_{3,1}&A_{3,2}&A_{3,3}&t_z \end{pmatrix} \begin{pmatrix} x\\y\\z\\1\end{pmatrix}.

Here the Am,nA_{m,n} coefficients encode the camera tilt angles and the tx,y,zt_{x,y,z} is the translation of the camera. The final screen-space coordinates are then computed in a separate step, the so-called perspective division which causes far-away objects, with large distance dd, to appear smaller,

i=xdand j=yd,i = \frac{x'}{d} \text{and } j = \frac{y'}{d},

or

(ij)=(1d001d)(xy).\begin{pmatrix}i\\j\end{pmatrix} = \begin{pmatrix}\frac{1}{d}& 0 \\ 0 & \frac{1}{d}\end{pmatrix}\begin{pmatrix}x' \\y' \end{pmatrix}.

Perspective mapping. Image via IT hare

Thank you linear transformations! for all the nice computer graphics.

Continue to the examples of week 2…

The marvelous design of this website is taken from Suckless.org