2021-CS107 / AC207

  • Syllabus
  • Schedule
  • Course Flow
  • Resources
  • Project
  • C/C++ Primer
  • Topic index

Key Word(s): Automatic differentiation, Forward mode

Download Notebook


Lecture 10 Exercise Solutions¶

Exercise 1¶

You will work with the following function for this exercise, \begin{align} f\left(x,y\right) = \exp\left(-\left(\sin\left(x\right) - \cos\left(y\right)\right)^{2}\right). \end{align}

  1. Draw the computational graph for the function.
    • Note: This graph will have $2$ inputs.
  2. Create the evaluation trace for this function.
  3. Use the graph / trace to evaluate $f\left(\dfrac{\pi}{2}, \dfrac{\pi}{3}\right)$.
  4. Compute $\dfrac{\partial f}{\partial x}\left(\dfrac{\pi}{2}, \dfrac{\pi}{3}\right)$ and $\dfrac{\partial f}{\partial y}\left(\dfrac{\pi}{2}, \dfrac{\pi}{3}\right)$ using the forward mode of AD.

Solution¶

Trace Elementary Function Current Value Elementary Function Derivative $\nabla_{x}$ Value $\nabla_{y}$ Value
$x_{1}$ $x_{1}$ $\dfrac{\pi}{2}$ $\dot{x}_{1}$ $1$ $0$
$x_{2}$ $x_{2}$ $\dfrac{\pi}{3}$ $\dot{x}_{2}$ $0$ $1$
$v_{1}$ $\sin\left(x_{1}\right)$ $1$ $\cos\left(x_{1}\right)\dot{x}_{1}$ $0$ $0$
$v_{2}$ $\cos\left(x_{2}\right)$ $\dfrac{1}{2}$ $-\sin\left(x_{2}\right)\dot{x}_{2}$ $0$ $-\dfrac{\sqrt{3}}{2}$
$v_{3}$ $-v_{2}$ $-\dfrac{1}{2}$ $-\dot{v}_{2}$ $0$ $\dfrac{\sqrt{3}}{2}$
$v_{4}$ $v_{1} + v_{3}$ $\dfrac{1}{2}$ $\dot{v}_{1} + \dot{v}_{3}$ $0$ $\dfrac{\sqrt{3}}{2}$
$v_{5}$ $v_{4}^{2}$ $\dfrac{1}{4}$ $2v_{4}\dot{v}_{4}$ $0$ $\dfrac{\sqrt{3}}{2}$
$v_{6}$ $-v_{5}$ $-\dfrac{1}{4}$ $-\dot{v}_{5}$ $0$ $-\dfrac{\sqrt{3}}{2}$
$v_{7}$ $\exp\left(v_{6}\right)$ $\exp\left(-1/4\right)$ $\exp\left(v_{6}\right)\dot{v}_{6}$ $0$ $-\dfrac{\sqrt{3}}{2}\exp\left(-1/4\right)$

Exercise 2¶

\begin{align} f\left(x,y\right) = \begin{bmatrix} xy + \sin\left(x\right) \\ x + y + \sin\left(xy\right) \end{bmatrix}. \end{align}

Trace Elem.      Val.                       Elem. Der.       $\nabla_{x}$ $\nabla_{y}$
$x_{1}$ $x_{1}$ $a$ $\dot{x}_{1}$ $1$ $0$
$x_{2}$ $x_{2}$ $b$ $\dot{x}_{2}$ $0$ $1$
$v_{1}$ $x_{1}x_{2}$ $ab$ $x_{1}\dot{x}_{2} + x_{2}\dot{x}_{1}$ $b$ $a$
$v_{2}$ $x_{1} + x_{2}$ $a+b$ $\dot{x}_{1} + \dot{x}_{2}$ $1$ $1$
$v_{3}$ $\sin\left(x_{1}\right)$ $\sin\left(a\right)$ $\cos\left(x_{1}\right)\dot{x}_{1}$ $\cos\left(a\right)$ $0$
$v_{4}$ $\sin\left(v_{1}\right)$ $\sin\left(ab\right)$ $\cos\left(v_{1}\right)\dot{v}_{1}$ $b\cos\left(ab\right)$ $a\cos\left(ab\right)$
$v_{5}$ $v_{1} + v_{3}$ $ab + \sin\left(a\right)$ $\dot{v_{1}} + \dot{v_{3}}$ $b + \cos\left(a\right)$ $a$
$v_{6}$ $v_{2} + v_{4}$ $a+b + \sin\left(ab\right)$ $\dot{v}_{2} + \dot{v}_{4}$ $1 + b\cos\left(ab\right)$ $1 + a\cos\left(ab\right)$
Copyright 2018 © Institute for Applied Computational Science