From a3609edbdbe9102778df2181a4da8489033f69fa Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Sun, 27 Aug 2023 21:33:20 +0200 Subject: [PATCH] Update week35.do.txt --- doc/src/week35/week35.do.txt | 53 +++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/doc/src/week35/week35.do.txt b/doc/src/week35/week35.do.txt index 7539ac178..3341ba78a 100644 --- a/doc/src/week35/week35.do.txt +++ b/doc/src/week35/week35.do.txt @@ -570,7 +570,9 @@ From this we have, using the definition of the Jacobian !split ===== Example 2 ===== -We define a scalar (our cast functions are in general also scalars, think of the mean squared error) as the result of some matrix vector multiplications +We define a scalar (our cost/loss functions are in general also scalars, +just think of the mean squared error) as the result of some matrix vector +multiplications !bt \[ @@ -601,6 +603,55 @@ Since $\alpha$ is a scalar we have $\alpha =\alpha^T=\bm{x}^T\bm{A}^T\bm{y}$. De +!split +===== Example 3 ===== + +We start with a new scalar but where now the vector $\bm{y}$ is +replaced by a vector $\bm{x}$ and the matrix $\bm{A}$ is a square +matrix with dimension $n\times n$. + +!bt +\[ +\alpha = \bm{x}^T\bm{A}\bm{x}$, +\] +!et +with $\bm{x}$ a vector of length $n$. + +We write out the specific sums involved in the calculation of $\alpha$ +!bt +\[ +\alpha = \sum_{i=0}^{n-1}\sum_{j=0}^({n-1}x_i a_{ij}x_j, +\] +!et +taking the derivative of $\alpha$ with respect to a given component $x_k$ we get the two sums +!bt +\[ +\frac{\partial \alpha}{\partial x_k} = \sum_{i=0}^{n-1}a_{ik}x_i+\sum_{j=0}^{n-1}a_{kj}x_j, +\] +!et +for $\all k =0,1,2,\dots,n-1$. We identify these sums as +!bt +\[ +\frac{\partial \alpha}{\partial \bm{x}} = \bm{x}^T\left(\bm{A}^T+\bm{A}\right). +\] +!et +If the matrix $\bm{A}$ is symmetric, that is $\bm{A}=\bm{A}^T$, we have +!bt +\[ +\frac{\partial \alpha}{\partial \bm{x}} = 2\bm{x}^T\bm{A}. +\] +!et + +!split +===== Example 4 ===== + +We let the scalar $\alpha$ be defined by +!bt +\[ +\alpha = \bm{y}^T\bm{x}, +\] +!et +where both $\bm{y}$ and $\bm{x}$ have the same length $n$, or if we wish to think of them as column vectors, they have dimensions $n\times 1$ !bt \[