<!-- MATH 4242 Python Lab 5: sections 3.1 to 3.5 -->
<setup>
  <selectFromSequence name="k" from="2" to="5" step="1" />
  <math name="dotExpected">2*$k-1</math>
  <math name="normSquared">$k^2+2</math>
  <math name="cosExpected">(2*$k-1)/($k^2+2)</math>
  <math name="quadExpected">$k+2</math>
  <math name="detQ">2*$k+3</math>
</setup>

<p>Python Lab 5: Inner products, norms, and quadratic forms</p>

<p>
  Open <em>05_Inner_Products_Quadratic_Forms.ipynb</em> and enter
  <m>k=$k</m>. Let
  <m>
    u=\begin{bmatrix}1\\$k\\-1\end{bmatrix},\qquad
    v=\begin{bmatrix}$k\\1\\1\end{bmatrix}.
  </m>
</p>

<ol marker="a.">
  <li>
    <p>
      Compute
      <m>u^Tv=</m>
      <mathInput name="dotUV" forAnswer="$innerProductAnswer">
        <shortDescription>inner product of u and v</shortDescription>
      </mathInput>
      and
      <m>\lVert u\rVert^2=</m>
      <mathInput name="normUSquared" forAnswer="$innerProductAnswer">
        <shortDescription>squared norm of u</shortDescription>
      </mathInput>.
    </p>
    <answer name="innerProductAnswer">
      <award><when>$dotUV=$dotExpected and $normUSquared=$normSquared</when></award>
    </answer>
  </li>

  <li>
    <p>
      Compute the exact cosine of the angle between the vectors:
      <m>\cos(\theta)=</m>
      <mathInput name="cosTheta" forAnswer="$cosineAnswer" minWidth="110">
        <shortDescription>cosine of the angle between u and v</shortDescription>
      </mathInput>.
    </p>
    <answer name="cosineAnswer"><award><when>$cosTheta=$cosExpected</when></award></answer>
  </li>

  <li>
    <p>
      Is equality attained in the Cauchy--Schwarz inequality for these
      vectors?
    </p>
    <choiceInput name="csChoice" forAnswer="$csAnswer">
      <shortDescription>whether equality holds in Cauchy Schwarz</shortDescription>
      <choice>Yes, because their dot product is positive.</choice>
      <choice>Yes, because their norms are equal.</choice>
      <choice>No, because the vectors are not scalar multiples.</choice>
      <choice>No, because Cauchy--Schwarz applies only to matrices.</choice>
    </choiceInput>
    <answer name="csAnswer"><award><when>$csChoice.selectedIndex=3</when></award></answer>
  </li>

  <li>
    <p>
      Now let
      <m>
        Q=\begin{bmatrix}2 &amp; 1\\1 &amp; $k+2\end{bmatrix},\qquad
        z=\begin{bmatrix}1\\-1\end{bmatrix}.
      </m>
      Compute
      <m>z^TQz=</m>
      <mathInput name="quadValue" forAnswer="$quadraticAnswer">
        <shortDescription>value of the quadratic form at z</shortDescription>
      </mathInput>
      and
      <m>\det(Q)=</m>
      <mathInput name="detQInput" forAnswer="$quadraticAnswer">
        <shortDescription>determinant of Q</shortDescription>
      </mathInput>.
    </p>
    <answer name="quadraticAnswer">
      <award><when>$quadValue=$quadExpected and $detQInput=$detQ</when></award>
    </answer>
  </li>

  <li>
    <p>What does the computation with <em>np.linalg.eigvalsh</em> show?</p>
    <choiceInput name="pdChoice" forAnswer="$pdAnswer">
      <shortDescription>classification of the quadratic form matrix</shortDescription>
      <choice><m>Q</m> is positive definite.</choice>
      <choice><m>Q</m> is negative definite.</choice>
      <choice><m>Q</m> is singular.</choice>
      <choice><m>Q</m> is not symmetric.</choice>
    </choiceInput>
    <answer name="pdAnswer"><award><when>$pdChoice.selectedIndex=1</when></award></answer>
  </li>
</ol>
