\input{Lecture-header}
\begin{document}
\providecommand{\currentLecture}{8}

\lect{\semester}{Angles}{1}{% begin lecture
%DesiredLectureName: Angles
\section{Angles}
\subsection{The Unit circle}
\input{../../modules/trigonometry/unit-circle-def}
\subsection{Three Meanings of Angle}
\input{../../modules/trigonometry/angle-three-meanings}
\input{../../modules/trigonometry/angle-geometric-definition}
\input{../../modules/trigonometry/angle-measure-of-geometric-angle-definition}
\input{../../modules/trigonometry/circle-arclength-from-general-definition-note}
\input{../../modules/trigonometry/circle-arclength}
\input{../../modules/trigonometry/circle-arclength-ex1}
\subsection{Two Meanings of Rotation}
\input{../../modules/trigonometry/rotation-two-meanings}
\input{../../modules/trigonometry/continuous-rotation-definition}
\input{../../modules/trigonometry/angle-measure-of-continuous-rotation}
\input{../../modules/trigonometry/angle-equivalence}
\subsection{Angles and the Coordinate System}
\input{../../modules/trigonometry/angle-coordinate-system}
\subsection{Radians and Degrees}
\input{../../modules/trigonometry/angles-measurement-units}
\input{../../modules/trigonometry/convert-radians-degrees-ex1}
\input{../../modules/trigonometry/circle-arclength-ex2}
\input{../../modules/trigonometry/frequently-encountered-angles}
\input{../../freecalc/modules/trigonometry/coterminal-angles}
\input{../../modules/trigonometry/coterminal-angles-example-1}
\input{../../modules/trigonometry/complementary-angles}
\input{../../modules/trigonometry/supplementary-angles}
\subsection{Area cut off by an angle}
\input{../../modules/trigonometry/area-sector}
}

\lect{\semester}{Lecture 2}{2}{% begin lecture
%DesiredLectureName: Trigonometry_Definitions
\section{Trigonometry}
\subsection{Definition of the Trigonometric Functions}
\input{../../freecalc/modules/trigonometry/trig-functions-definition}
\input{../../freecalc/modules/trigonometry/similar-triangles-def}
\input{../../freecalc/modules/trigonometry/similar-triangles-same-side-ratios}
\input{../../freecalc/modules/trigonometry/trig-functions-and-right-angle-triangles}
\subsection{Basic Computations with Trigonometric Functions}
\input{../../freecalc/modules/trigonometry/trig-functions-example3}
\input{../../freecalc/modules/trigonometry/trig-functions-example2}
\input{../../freecalc/modules/trigonometry/triangle-angles-sum-to-180-degrees}
\input{../../freecalc/modules/trigonometry/trig-functions-of-45-degrees}
\input{../../freecalc/modules/trigonometry/trig-functions-of-30-60-degrees}
\subsection{Reference Angles}
\input{../../freecalc/modules/trigonometry/reference-angles}
\input{../../freecalc/modules/trigonometry/trig-example}
\input{../../freecalc/modules/trigonometry/frequently-encountered-sines-cosines}
\subsection{Geometric Interpretation of the Trigonometric Functions}
\input{../../freecalc/modules/trigonometry/trig-functions-unit-circle}
\subsection{Periodicity and Symmetries of the Trig Functions}
\input{../../freecalc/modules/trigonometry/trig-functions-even-odd}
\input{../../freecalc/modules/trigonometry/trig-functions-periodicity}
\input{../../freecalc/modules/trigonometry/trig-identity-definition}
\input{../../freecalc/modules/trigonometry/trig-identities-pythagorean}
%\input{../../modules/trigonometry/trig-identities-angle-sum-summary}
}

\lect{\semester}{Lecture 3}{3}{% begin lecture
%DesiredLectureName: Trigonometry_Cofunction_Identities_Angle_Sum_Formulas
\section{Cofunction identities}
\input{../../modules/trigonometry/cofunction-identities-part1}
\input{../../modules/trigonometry/cofunction-identities-part2}
\input{../../modules/trigonometry/cofunction-identities-memorization-aid}
\section{Trigonometric Functions of Sums of Angles}
\input{../../modules/trigonometry/similar-triangles-def}
\input{../../modules/trigonometry/similar-triangles-same-side-ratios}
\input{../../modules/trigonometry/trig-angle-sum-formulas-geometric-proof}
\input{../../modules/trigonometry/trig-angle-sum-formulas-geometric-proof-part2}
\input{../../modules/trigonometry/trig-angle-sum-formulas-geometric-proof-part3}
\input{../../modules/trigonometry/trig-angle-sum-formulas-to-find-sin-cos-ex1}
\input{../../modules/trigonometry/trig-angle-sum-formulas-sums-pi-over-2-ex1}
\input{../../modules/trigonometry/trig-angle-sum-formulas-sums-pi-over-2-ex2}
\input{../../modules/trigonometry/trig-angle-sum-formulas-tan-is-pi-periodic}
\input{../../modules/trigonometry/trig-angle-sum-formulas-to-prove-pythagorean-identity}
\input{../../modules/trigonometry/tan-angle-sum-formula}
\section{Double Angle Formulas}
\input{../../modules/trigonometry/double-angle-formulas}
\input{../../modules/trigonometry/double-angle-formulas-proof}
\input{../../modules/trigonometry/half-angle-formula-ex1}
\input{../../modules/trigonometry/power-reducing-formulas}
\input{../../modules/trigonometry/power-reducing-formulas-ex1}
}

\lect{\semester}{Lecture 4}{4}{% begin lecture
%DesiredLectureName: Complex-numbers-basics
\section{Complex Numbers}
\input{../../modules/complex-numbers/complex-numbers-definition}
\input{../../modules/complex-numbers/complex-numbers-addition-multiplication-example-1}
\input{../../modules/complex-numbers/complex-numbers-multiplication-example-2}
\input{../../modules/complex-numbers/overview-of-numbers}
}

\lect{\semester}{Lecture 5}{5}{% begin lecture
%DesiredLectureName: Trigonometric_Identities
\section{Trigonometric Identities}
\subsection{Trigonometric Identities and Complex Numbers}
\input{../../modules/trigonometry/trig-Euler-formula}
\input{../../modules/trigonometry/trig-using-euler-formula}
\subsection{Trigonometric Identities without Complex Numbers}
\input{../../modules/trigonometry/trig-identity-definition}
\input{../../modules/trigonometry/trig-identity-proving}
\input{../../modules/trigonometry/trig-identity-types}
\subsection{Trig Identities Using $\sin^2\theta+\cos^2\theta=1$}
\input{../../modules/trigonometry/trig-identities-pythagorean-ex1}
\input{../../modules/trigonometry/trig-identities-pythagorean-ex2}
\input{../../modules/trigonometry/trig-identities-pythagorean-ex3}
\input{../../modules/trigonometry/trig-identities-pythagorean-ex4}
\subsection{Trig Identities Using the Angle Sum Formulas}
\input{../../modules/trigonometry/trig-identities-example-1}
\input{../../modules/trigonometry/trig-identities-example-3}
\input{../../modules/trigonometry/trig-identities-example-3-with-Eulers-Formula}
\input{../../modules/trigonometry/trig-identities-example-2}
\input{../../modules/trigonometry/trig-identities-strategy-note}
\subsection{Trig Identities Exercises}
\input{../../modules/trigonometry/trig-identities-exercises-1}
}

\lect{\semester}{Lecture 6}{6}{% begin lecture
%DesiredLectureName: Inverse_Functions
\section{Inverse Functions}
\subsection{One-to-one Functions}
\input{../../modules/inverse-functions/one-to-one-def}
\input{../../modules/inverse-functions/horizontal-line-test}
\subsection{The Definition of the Inverse of $f$}
\input{../../modules/inverse-functions/inverse-function-def}
\input{../../modules/inverse-functions/inverse-notation-warning}
\input{../../modules/inverse-functions/inverse-function-equations}
\input{../../modules/inverse-functions/inverse-function-solve-for-version2}
\input{../../modules/inverse-functions/guess-and-check}
\input{../../modules/inverse-functions/inverse-function-graph}
\input{../../modules/inverse-functions/inverse-function-ex5}
\input{../../modules/inverse-functions/inverse-function-solve-for-ex1-freeCalc}
\input{../../modules/inverse-functions/inverse-function-solve-for-ex3-freeCalc}
}

\lect{\semester}{Lecture 7}{7}{% begin lecture
%DesiredLectureName: Trigonometric_Function_Graphs_Inverse_Trig
\section{Graphs of the Trigonometric Functions}
\subsection{Graphs of $\sin $ and $\cos$}
\input{../../freecalc/modules/trigonometry/graph-sin-extended}
\input{../../freecalc/modules/trigonometry/graph-cos-extended}
\input{../../freecalc/modules/trigonometry/graphs-sin-and-cos}
\subsection{Graph of $a\sin(bx-c)$}
\input{../../freecalc/modules/trigonometry/graphs-asinbx-plus-c}
\subsection{Graphs of $\tan, \cot, \sec, \csc $}
\input{../../freecalc/modules/trigonometry/graph-tan-extended}
\input{../../freecalc/modules/trigonometry/graphs-tan-and-cot}
\input{../../freecalc/modules/trigonometry/graphs-sec-and-csc}
\section{Inverse Trigonometric Functions}
\input{../../freecalc/modules/inverse-trig/arcsin-def}
\input{../../freecalc/modules/inverse-trig/arcsin-frequently-encountered-example-1}
\input{../../freecalc/modules/inverse-trig/tan-arcsin-example-1}
\input{../../freecalc/modules/inverse-trig/arcsin-sin-ex1}
\input{../../freecalc/modules/inverse-trig/arcsin-sin-ex2}
\input{../../freecalc/modules/inverse-trig/arcsin-properties}
\input{../../freecalc/modules/inverse-trig/arccos-def}
\input{../../freecalc/modules/inverse-trig/arccos-properties}
\input{../../freecalc/modules/inverse-trig/arccos-cos-example-1}
%\section{Some applied trigonometric problems}
\input{../../freecalc/modules/trigonometry/text-problem-visibility-horizon-earth-1}
%\input{../../freecalc/modules/trigonometry/text-problem-visibility-mountain-earth-1}
\subsection{Trigonometric Functions with Inverse Trig Arguments}
\input{../../freecalc/modules/inverse-trig/trig-applied-to-inverse-trig-ex1}
\input{../../freecalc/modules/inverse-trig/trig-applied-to-inverse-trig-ex2}
\input{../../freecalc/modules/inverse-trig/arctan-def}
\input{../../freecalc/modules/inverse-trig/arctan-ex3}
\input{../../freecalc/modules/inverse-trig/arcsec-intro}
\input{../../freecalc/modules/inverse-trig/arcsec-def}
}

\lect{\semester}{Lecture 8}{8}{% begin lecture
%DesiredLectureName: Trig_Equations_Inequalities
\section{Trigonometric equations and inequalities}
\input{../../freecalc/modules/trigonometry/trig-equations-intro}
\subsection{The Equations $\sin x = A$, $\cos x = B$}
\input{../../freecalc/modules/trigonometry/trig-equations-sin-x-equals-const-algebraic-1}
\input{../../freecalc/modules/trigonometry/trig-equations-cos-x-equals-const-algebraic-1}
\input{../../freecalc/modules/trigonometry/trig-equations-sin-x-equals-const-general-1}
\subsection{Equations that reduce to $\sin x = A$, $\cos x = B$}
\input{../../freecalc/modules/trigonometry/trig-equations-example}
\input{../../freecalc/modules/trigonometry/trig-equations-example-2}
\input{../../freecalc/modules/trigonometry/trig-equations-strategy}
\section{Product-to-Sum Formulas}
\input{../../freecalc/modules/trigonometry/product-to-sum-formulas}
\input{../../freecalc/modules/trigonometry/sum-to-product-formulas}
\input{../../freecalc/modules/trigonometry/sum-to-product-formulas-ex1}
\section{Trigonometric inequalities}
\input{../../freecalc/modules/trigonometry/sin-geq-leq-constants-example-1}
\input{../../freecalc/modules/inequalities-polynomial/trig-inequality-reduced-to-quadratic-1}
}

\lect{\semester}{Lecture 9}{9}{% begin lecture
%DesiredLectureName: Law_of_Sines_Law_of_Cosines_Trig_Applications
\section{Law of sines}
\input{../../modules/trigonometry/area-of-triangle-from-base-and-height}
\input{../../modules/trigonometry/area-of-triangle-from-two-sides-and-angle}
\input{../../modules/trigonometry/law-of-sines}
\input{../../modules/trigonometry/law-of-sines-example-1}
\section{Law of cosines}
\input{../../modules/trigonometry/law-of-cosines}
\input{../../modules/trigonometry/law-of-cosines-solve-triangle-example-1}
}

\lect{\semester}{Lecture 10}{10}{
%DesiredLectureName: Exponents
\section{Exponents}
\input{../../modules/exponential-functions/exponential-properties}
\subsection{Two ways to define exponents}
\input{../../modules/exponential-functions/exponential-function-def-various-approaches}
\input{../../modules/exponential-functions/exponential-function-def}
\subsection{Basic properties}
\input{../../modules/exponential-functions/exponential-function-graphs}
\input{../../modules/exponential-functions/exponential-versus-polynomial}
\input{../../modules/exponential-functions/exponential-function-ex-sketch}
\input{../../modules/exponential-functions/exponential-one-to-one-over-reals}
\subsection{The Natural Exponential Function}
\input{../../modules/exponential-functions/natural-exponential-intro}
\input{../../modules/logarithms/e-limit-no-lim-notation}
\input{../../modules/exponential-functions/compound-interest}
\input{../../modules/logarithms/e-limit-compound-interest-example-1}
\input{../../modules/logarithms/e-limit-compound-interest-example-2}
\input{../../modules/logarithms/e-limit-compound-interest-rule-of-72}
}

\lect{\semester}{Lecture 11}{11}{% begin lecture
%DesiredLectureName: Logarithm_Basics
\section{Logarithmic Functions}
\subsection{Logarithm basics}
\input{../../modules/logarithms/logarithm-def}
\input{../../modules/logarithms/logarithm-def-ex1}
\input{../../modules/logarithms/log-and-exp}
\input{../../modules/logarithms/logarithm-graphs}
\subsection{Natural Logarithms}
\input{../../modules/logarithms/natural-logarithm-def}
\input{../../modules/logarithms/log-notation-note}
\input{../../modules/logarithms/log-notation-summary}
\subsection{Shifting graphs of logarithmic functions}
\input{../../modules/logarithms/natural-logarithm-def-ex8}
\section{Basic Operations with Logarithms}
\input{../../modules/logarithms/logarithm-properties}
\input{../../modules/logarithms/logarithm-properties-compute-arbitrary-base-via-ln-example-1}
\input{../../modules/logarithms/logarithm-properties-ex2}
\input{../../modules/logarithms/logarithm-properties-ex4}
\input{../../modules/logarithms/logarithm-properties-ex6}
\input{../../modules/logarithms/logarithm-properties-ex7}
\input{../../modules/logarithms/logarithm-properties-extra}
\input{../../modules/logarithms/logarithm-properties-ex5}
\input{../../modules/logarithms/logarithm-evaluate-log-linear-combination-multiple-techniques-1}
\input{../../modules/logarithms/logarithm-properties-proofs}
}

\lect{\semester}{Lecture 12}{12}{% begin lecture
%DesiredLectureName: Equations_involving_logarithms_and_exponents
\section{Equations involving logarithms}
\input{../../modules/logarithms/logarithms-equations-ex1}
\input{../../modules/logarithms/logarithms-equations-ex2}
\section{Equations involving exponents}
\input{../../modules/exponential-functions/exponential-equation1}
\input{../../modules/logarithms/exponential-equation-basic-arbitrary-base-1.tex}
\input{../../modules/logarithms/exponential-equation-basic-two-exponents-1}
\input{../../modules/logarithms/exponential-equation-basic-two-different-exponents-1}
\input{../../modules/logarithms/natural-logarithm-def-ex5}
\input{../../modules/exponential-functions/exponential-word-problem1}
\input{../../modules/exponential-functions/exponential-equation2}
\input{../../modules/logarithms/exponential-equation-quadratic-natural-base-1}
\input{../../modules/logarithms/exponential-equation-quadratic-arbitrary-base-1}
\input{../../modules/logarithms/exponential-equation-quadratic-arbitrary-base-2}
\section{Inverse function problems and exponents}
\input{../../modules/inverse-functions/inverse-function-solve-for-ex2-freeCalc}
\section{Basic exponential inequalities}
\input{../../modules/logarithms/exponential-inequality-basic-1}
}

\lect{\semester}{Lecture 13}{13}{% begin lecture
%DesiredLectureName: Exponential_and_Logarithmic_models
\section{Models Involving Logarithms and Exponents}
\input{../../modules/logarithms/models-involving-logarithms-and-exponents}
\input{../../modules/exponential-growth-and-decay/exponential-growth-decay-model}
\input{../../modules/exponential-growth-and-decay/exponential-growth-model-ex1}
\input{../../modules/exponential-growth-and-decay/exponential-decay-model-ex1}
\input{../../modules/exponential-growth-and-decay/logistic-growth-model}
\input{../../modules/exponential-growth-and-decay/logistic-growth-model-ex1}
\input{../../modules/logarithms/logarithmic-models}
\input{../../modules/logarithms/logarithmic-models-ex1}
}

\lect{\semester}{Lecture 14}{14}{
%DesiredLectureName: Factoring_polynomials_and_polynomial_inequalities
\section{Factoring quadratics}
\input{../../modules/polynomial-factorization/factorization-meaning-1}
\input{../../modules/quadratic-functions/factoring-quadratics-theory-1}
\input{../../modules/quadratic-functions/factoring-quadratics-example-Vieta-guessing-or-formula-1}
\input{../../modules/quadratic-functions/vietas-formulas}
\input{../../modules/quadratic-functions/factoring-quadratics-example-example-Vieta-guessing-1}
\input{../../modules/quadratic-functions/factoring-quadratics-example-by-formula-1}
\input{../../modules/quadratic-functions/factoring-quadratics-example-by-formula-no-real-roots-1}
\section{Factorization overview}
\input{../../modules/polynomial-factorization/factorization-examples-no-theory-1}
\input{../../modules/polynomial-factorization/fundamental-theorem-of-algebra-statement}
\input{../../modules/polynomial-factorization/factorization-examples-1}
\input{../../modules/polynomial-factorization/factorization-algebraic-overview-1}
\input{../../modules/polynomial-factorization/factorization-over-basic-three-fields-explanation}
\input{../../modules/polynomial-factorization/factorization-over-rationals}
%DesiredLectureName: Factoring_cubics_with_rational_root
\section{Polynomial division}
\input{../../modules/polynomial-factorization/polynomial-division-example-1}
\input{../../modules/polynomial-factorization/polynomial-division-use-to-factor-1}
\section{Factoring cubics with rational root}
\input{../../modules/polynomial-factorization/solve-cubic-rational-roots-using-graph-1}
\input{../../modules/polynomial-factorization/solve-cubic-one-rational-two-real-roots-from-graph-1}
\input{../../modules/polynomial-factorization/solve-cubic-one-rational-two-complex-roots-from-graph-1}
\section{Polynomial inequalities}
%DesiredLectureName: Polynomial_inequalities
\input{../../freecalc/modules/inequalities-polynomial/inequality-quadratic-1}
\input{../../freecalc/inequalities-polynomial/inequality-cubic-three-rational-roots-1}
}

\lect{\semester}{Lecture 98}{98}{
%DesiredLectureName: Graphing-Equations-Circle-Equation
\section{Graph of an equation}
\input{../../modules/equation-graph/equation-graph-def}
\input{../../modules/equation-graph/equation-check-solution-1}
\input{../../modules/equation-graph/equation-check-solution-2}
\input{../../modules/equation-graph/graph-equation-when-one-variable-is-function-of-the-other}
\youWillNotBeTested
\input{../../modules/equation-graph/graph-equation-implicit-computer-algorithm}
\input{../../modules/equation-graph/graph-intercepts}
\input{../../modules/equation-graph/find-graph-intercepts-example-1}
\input{../../modules/equation-graph/find-graph-intercepts-example-2}
\input{../../modules/equation-graph/graph-symmetries}
\input{../../modules/equation-graph/circle-equation}
\input{../../modules/quadratic-functions/completing-the-square}
\input{../../modules/quadratic-functions/completing-the-square-example-1}
\input{../../modules/equation-graph/find-center-radius-from-circle-equation-1}
\input{../../modules/equation-graph/find-circle-equation-from-radius-and-point-1}
}% end lecture

\lect{\semester}{Lecture 99}{99}{
%DesiredLectureName: Quadratic_Functions
\section{Quadratic Functions}
\subsection{Standard Form}
\input{../../freecalc/modules/quadratic-functions/definition-quadratic-function}
\input{../../freecalc/modules/quadratic-functions/completing-the-square-example-1}
\input{../../freecalc/modules/quadratic-functions/completing-the-square}
\input{../../freecalc/modules/quadratic-functions/discriminant-and-standard-form-quadratic}
\subsection{Geometric Features}
\input{../../freecalc/modules/quadratic-functions/quadratic-function-geometric-features}
\input{../../freecalc/modules/quadratic-functions/write-equation-parabola-given-vertex-and-point-example-1}
\subsection{Quadratic Equations}
\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution}
\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution-example-1}
\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution-example-2}
\input{../../freecalc/modules/quadratic-functions/quadratic-equation-solution-example-3}
\subsection{Vieta's Formulas}
\input{../../freecalc/modules/quadratic-functions/dicriminant-from-roots-formula}
\input{../../freecalc/modules/quadratic-functions/vietas-formulas}
\subsection{Factoring quadratics}
\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-theory-1}
\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-Vieta-guessing-or-formula-1}
\input{../../freecalc/modules/quadratic-functions/vietas-formulas}
\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-example-Vieta-guessing-1}
\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-by-formula-1}
\input{../../freecalc/modules/quadratic-functions/factoring-quadratics-example-by-formula-no-real-roots-1}
\subsection{Plotting Quadratics}
\input{../../freecalc/modules/quadratic-functions/plot-roughly-by-hand-parabola-recipe}
\input{../../freecalc/modules/quadratic-functions/plot-roughly-by-hand-parabola-example-1}
\input{../../freecalc/modules/quadratic-functions/quadratic-find-parameters-to-ensure-quadratic-positive-1}
\subsection{Maxima and Minima}
\input{../../freecalc/modules/quadratic-functions/quadratic-function-minimum-example-1}
\input{../../freecalc/modules/quadratic-functions/quadratic-function-maximum-or-minimum}
\input{../../freecalc/modules/quadratic-functions/quadratic-max-min-word-problem-1}
}

\lect{\semester}{Lecture 100}{100}{
%DesiredLectureName: Cartesian_Coordinates_Vector_Addition_Scalar_Product
\section{Cartesian coordinate system}
\input{../../modules/coordinate-systems/cartesian-coordinates-2d-part1}
\input{../../modules/coordinate-systems/cartesian-coordinates-2d-part2}
\input{../../modules/coordinate-systems/cartesian-coordinates-2d-part3}
\input{../../modules/coordinate-systems/cartesian-coordinates-2d-plot-points-example}

\subsection{The Pythagorean Theorem, Euclidean Distance}
\input{../../modules/coordinate-systems/pythagorean-theorem}
\input{../../modules/coordinate-systems/distance-in-cartesian-coordinates-2d}
\input{../../modules/coordinate-systems/distance-2d-example-1}
\input{../../modules/coordinate-systems/distance-2d-check-if-triangle-right-angled-1}
\subsection{Vectors}
\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part1}
\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part2}
\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part3}
\input{../../modules/vectors/vector-addition-and-scalar-mult-from-cartesian-system-2d-part4-translation-definition}
\input{../../modules/vectors/vectors-translation-of-point-2d-example-1}
\subsection{Segments, Midpoints}
\input{../../modules/coordinate-systems/segment-between-two-points}
\input{../../modules/coordinate-systems/midpoint-definition-verification-2d}
\input{../../modules/coordinate-systems/find-midpoint-1}
}% end lecture

\lect{\semester}{Lecture 101}{101}{
%DesiredLectureName: Lines
\section{Lines}
\input{../../modules/coordinate-systems/r-two-r-n}
\input{../../modules/lines-2d/line-definition}
\input{../../modules/lines-2d/line-from-two-points}
\input{../../modules/lines-2d/line-from-two-points-formulas-and-slope-form}
\subsection{Slope-intercept Form}
\input{../../modules/lines-2d/line-slope-intercept-form}
\input{../../modules/lines-2d/line-slope-intercept-form-explanation}
\input{../../modules/lines-2d/compare-linear-functions-via-slope}

\input{../../modules/lines-2d/vertical-line-and-slope}
\input{../../modules/lines-2d/line-plot-from-equation-example-1}

\input{../../modules/lines-2d/line-from-two-points-example-1}
\input{../../modules/lines-2d/line-from-point-and-slope-example-1}

\subsection{Line intersection}
\input{../../modules/lines-2d/line-intersection}
\input{../../modules/lines-2d/line-intersection-example-1}
\input{../../modules/lines-2d/parallel-lines-equal-slopes}
}% end lecture

\lect{\semester}{Lecture 102}{102}{
%DesiredLectureName: Functions
\section{The Definition of a Function}
\input{../../modules/functions-basics/function-def-uses-arrows}
\input{../../modules/functions-basics/function-def}
\input{../../modules/functions-basics/function-def-note-on-f-of-x-notation}
\input{../../modules/functions-basics/function-formulas-and-bound-variables}
\input{../../modules/functions-basics/function-formula-understanding-example-1}
\subsection{Function Domains}
\input{../../modules/functions-basics/domains}
\input{../../modules/functions-basics/domains-example-1}

\subsection{The Vertical Line Test}
\input{../../modules/precalculus/vertical-line-test}
\subsection{Piecewise Defined Functions}
\input{../../modules/precalculus/function-piecewise}
\input{../../modules/precalculus/absolute-value}
\input{../../modules/precalculus/piecewise-formula}
\input{../../modules/precalculus/piecewise-ex1}
\input{../../modules/precalculus/piecewise-ex2}
\subsection{Zeros of a function}
\input{../../modules/functions-basics/zeroes-of-a-function}
\input{../../modules/functions-basics/zeroes-of-function-from-formula-1}
\input{../../modules/functions-basics/f-of-x-equals-g-of-x-algebra-example-1}
\input{../../modules/functions-basics/finding-when-f-of-x-equals-g-of-x}
\subsection{Symmetry}
\input{../../modules/precalculus/even-and-odd}
\subsection{Increasing and Decreasing Functions}
\input{../../modules/precalculus/increasing-decreasing}

}% end lecture

\lect{\semester}{Lecture 103}{103}{
%DesiredLectureName: Functions
\section{A Catalog of Essential Functions}
\subsection{Linear Functions}
\input{../../modules/lines-2d/linear-functions}
\input{../../modules/lines-2d/linear-functions-examples-1}
\subsection{Polynomials}
\input{../../modules/precalculus/polynomials}
\subsection{Power Functions}
\input{../../modules/precalculus/power-functions-def}
\input{../../modules/precalculus/root-functions}
\input{../../modules/precalculus/reciprocal-function}
\subsection{Rational Functions}
\input{../../modules/precalculus/rational-functions}
\subsection{Algebraic Functions}
\input{../../modules/precalculus/algebraic-functions}
\subsection{Transcendental Functions}
\input{../../modules/precalculus/transcendental-functions-version2}
\subsection{Miscellaneous}
\input{../../modules/continuity/greatest-integer-function}
\section{New Functions from Old Functions}
\input{../../modules/precalculus/combinations-functions}
\input{../../modules/precalculus/composition-functions}
\input{../../modules/precalculus/composition-example}
\input{../../modules/precalculus/composition-example-2}
}

\lect{\semester}{Lecture 104}{104}{
\section{Composing Functions with Linear Transformations}
\input{../../modules/function-graph-linear-transformations/transformations-shifts}
\input{../../modules/function-graph-linear-transformations/transformations-shifts-example}
\input{../../modules/function-graph-linear-transformations/transformations-magnifications}
\input{../../modules/function-graph-linear-transformations/transformations-horizontal-stretches}
\section{Graphing Absolute Value of a Function}
\input{../../modules/function-graph-linear-transformations/transformations-absolute-value}
}
\end{document}


% jam 2004-09-10

\section{Vector spaces}
\label{sec:vector-spaces}

My approach to vector spaces is largely based on
the texts I used as a college freshman for linear algebra and
multivariate calculus: Halmos \cite{halmos1958finite}
and Spivak \cite{spivak-1965}.

Some useful definitions/identities:

Let $\Vspace$ be an $n$-dimensional real inner product space.
Let $\v, \w \in \Vspace$.

\begin{itemize}
\item The inner (dot) product on $\Reals^n$:
\begin{equation}
\v \bullet \w \; \equiv \; \sum_{i=0}^{n-1} v_i w_i
\end{equation}

\item The euclidean ($l_2$) norm:
\begin{equation}
\| \v \|^2 \; \equiv \; \v \bullet \v
\end{equation}

\item $\theta(\v,\w)$ is the angle between $\v$ and $\w$
and is defined by:
\begin{eqnarray}
\v \bullet \w \; = \; \| \v \| \| \w \| \cos(\theta(\v,\w))
\\
\theta(\v,\w)
\; \equiv \;
\cos^{-1} \left(\frac{ \v \bullet \w }{\| \v \| \| \w \| } \right)
\nonumber
\end{eqnarray}

\item The tensor (outer) product:

Let $\v, \u \in \Vspace, \w \in \Wspace.$
$\w \otimes \v$ is a rank 1 linear map
from $\Vspace$ to $\Wspace$, defined by:
\begin{equation}
(\w \otimes \v)(\u) \; \equiv \; \w (\v \bullet \u)
\end{equation}

Note: this is an abuse of the usual definition of tensor product $\otimes$.
This operation, which takes a pair of vectors and returns a linear map,
is more conventionally referred to as the 'outer product',
and written $\w \v^{\dagger}$.
However, because I am working in spaces other than $\Reals^n$
(eg. $\Lspace(\Vspace,\Wspace)$, the space of linear maps
between 2 vector spaces),
I want to avoid notations that suggest thinking in terms
of 'row' and 'column' vectors.

The following is a useful identity.
If $\t \in \Tspace$, $\u, \v \in \Vspace$, and $\w \in \Wspace.$
then
\begin{equation}
\label{eq:tensor-dot}
(\t \otimes \u) (\v \otimes \w)(\u) = (\u \bullet \v) (\t \otimes \w)
\end{equation}

\item Elementary orthogonal projection:
\begin{equation}
\Projection_{\w} \v
\; \equiv \;
\left( \frac{ \w }{ \| \w \| } \otimes \frac{ \w }{ \| \w \| } \right) \v
\; = \;
\left( \frac{\w }{\|\w\|} \bullet \v \right) \frac{\w}{\|\w\|}
\end{equation}

\item Orthogonal complement:
\begin{equation}
\perp_{\w} \v
\; \equiv \;
\v \perp \w
\; \equiv \;
\v \; - \; \Projection_{\w} \v
\; = \;
\v \; - \; \left( \frac{\w}{\|\w\|} \bullet \v \right) \frac{\w}{\|\w\|}
\end{equation}

\end{itemize}


\subsection{Trigonometric Functions}
There are six basic trigonometric functions:
\begin{multicols}{2}
\begin{itemize}
	\item Sine (abbreviated by $\sin$)
	\item Cosine (abbreviated by $\cos$)
	\item Tangent (abbreviated by $\tan$)
	\item Cosecant (abbreviated by $\csc$)
	\item Secant (abbreviated by $\sec$)
	\item Cotangent (abbreviated by $\cot$)
\end{itemize}
\end{multicols}

We first describe trigonometric functions in terms of ratios of two sides of a \ifont{right angle triangle} containing the angle $\theta$.

$$\includegraphics[width=2.5in]{images/trig2}$$

With reference to the above triangle, for an acute angle $\theta$ (that is, $0\leq\theta<\pi/2$), the six trigonometric functions can be described as follows:
$$\begin{array}{ccc}
\ds\sin\theta=\frac{\rm opp}{\rm hyp}&\qquad&\ds\csc\theta=\frac{\rm hyp}{\rm opp}\\
\\
\ds\cos\theta=\frac{\rm adj}{\rm hyp}&\qquad&\ds\sec\theta=\frac{\rm hyp}{\rm adj}\\
\\
\ds\tan\theta=\frac{\rm opp}{\rm adj}&\qquad&\ds\cot\theta=\frac{\rm adj}{\rm opp}\\
\end{array}$$

\begin{formulabox}[Mnemonic]
The mnemonic \ifont{SOH CAH TOA} is useful in remembering how trigonometric functions of acute angles relate to the sides of a right triangle.
\end{formulabox}

This description does not apply to \ifont{obtuse} or \ifont{negative angles}.
To define the six basic trigonometric functions we first define sine and cosine as the lengths of various line segments from a unit circle, and then we define the remaining four basic trigonometric functions in terms of sine and cosine.

Take a line originating at the origin (making an angle of $\theta$ with the positive half of the $x$-axis) and suppose this line intersects the unit circle at the point $(x,y)$.
The $x$- and $y$-coordinates of this point of intersection are equal to $\cos\theta$ and $\sin\theta$, respectively.
$$\includegraphics[width=2.3in]{images/trig3}$$
For angles greater than $2\pi$ or less than $-2\pi$, simply continue to rotate around the circle.
In this way, sine and cosine become periodic functions with period $2\pi$:
$$\sin\theta = \sin\left(\theta + 2\pi k \right)\qquad\qquad \cos\theta = \cos\left(\theta + 2\pi k \right)$$
for any angle $\theta$ and any integer $k$.

Above, only sine and cosine were defined directly by the circle.
We now define the remaining four basic trigonometric functions in terms of the functions $\sin\theta$ and $\cos\theta$:
$$\tan\theta = \frac{\sin\theta}{\cos\theta} \qquad \sec\theta = \frac{1}{\cos\theta} \qquad \csc\theta = \frac{1}{\sin\theta} \qquad \cot\theta = \frac{\cos\theta}{\sin\theta}$$


\documentclass{article}

\usepackage{amsmath, amsthm, amssymb}
\usepackage{fullpage}

\newcommand{\N}{\mathcal{N}}
\renewcommand{\v}[1]{\mathbf{#1}}
\begin{document}

We have an observed signal $O(t)$. We have an arrival at time $t_0$, with a latent shape $S(t)$, repeatable wiggle $R(t)$, and nonrepeatable wiggle $W(t)$. These combine to form a latent signal $L(t) = S(t) \cdot (R(t) + W(t))$.

We assume the observed signal is modeled as $O(t) = L(t) + N(t)$ where $N(t)$ is an $AR(p_N)$ noise process with mean $0$, parameters $\phi^N$, and step variance $\sigma^2_N$. Here we are ignoring, for simplicity of exposition, the contribution to $O(t)$ of any other simultaneous arrivals, along with any nonzero noise mean, since WLOG these can be subtracted out beforehand. We also assume that $W(t)$ is an $AR(p_W)$ noise process with mean $1$, parameters $\phi_W$ and step variance $\sigma^2_W$.

We consider here the problem of Gibbs sampling a new entry at time $k$ of the latent nonrepeatable wiggle $W(k)$. That is, we want to find the distribution
\[p(W(k) | W(\not k), O, S, R).\]

It's most enlightening to consider the problem in terms of the autoregressive processes $W$ and $N$. We can solve for $N$ as $N = O - L = O - S \cdot (R + W)$. Note that, with $O$, $S$, $R$ observed, $N$ has a deterministic dependence on $W$: given any latent wiggle hypothesis, we can compute the station noise that would be required to explain the remainder of the observed signal. We deal with this deterministic dependence by 'integrating out' $N$, i.e. just modeling $O$ as a noisy function of $L$ with no explicit representation of $N$ in the model. This means that, when resampling $W(k)$, we do not have access to $N(k)$, since $N(k)$ can only be computed from the current value of $W(k)$.

The Markov blanket of $W(k)$ includes the $p_W$ entries of $W$ preceding $W(k)$ as well as the $p_W$ entries following it. Since $N(k)$ is a deterministic function of $W(K)$, it also includes the $p_N$ entries of $N$ preceding $N(k)$ and the $p_N$ entries following. We can write the joint distribution on all of these quantities as
\[p(W,O) = p_{AR}(W(k-p_W), \cdots, W(k+p_W) \cdot p_{AR}(N(k-p_N), \cdots, N(k+p_N))\]
where $p_{AR}$ denotes probability under the relevant AR model and we take $N = O - SR - SW$.

Since $N$ depends linearly on $W$, this is a linear Gaussian system. We can determine the posterior on $W(k)$ by the messages that are passed from the variables in its Markov blanket. We can divide these messages into $W$-messages and $N$-messages. The $W$ messages together will yield exactly the AR smoothing distribution on $W(k)$ given the other entries of $W$. Similarly, the $N$ messages together will yield the AR smoothing distribution on $N(k)$, which is just a linear function of $W(k)$, so we can transform that distribution into a message to $W(k)$ which we will combine with the smoothing distribution already received.

\section{Fully Observed Smoothing Distributions}

Here we consider the smoothing distribution of an AR process $W$ with mean 0, parameters $\phi$ and step variance $\sigma^2$. We assume that all entries other than $W(k)$ are observed.

Notation: we define an AR process by $W(k) = \phi^T W(k-p : k-1) + \N(0,\sigma^2) = \sum_{i=1}^{p} \phi_i W(k-i)$. So increasing indices to $\phi$ denote coefficients that are 'further back' in time.

The joint distribution on the Markov blanket is given by
\begin{align*}
p(W(k-p_W : k+p_W)) &= \N(W(k); \phi^T W(k-p : k-1); \sigma^2 ) \prod_{j=1}^p \N(W(k+j); \phi^T W(k-p+j : k+j-1); \sigma^2 )
\end{align*}
If we adopt the shorthand $\Pi(k') = W(k'-p : k'-1)$, i.e. we let $\Pi(k')$ denote the vector of values that directly influence $W(k')$, we can rewrite this as
\begin{align*}
p(W(k-p_W : k+p_W)) &= \N(W(k); \phi^T \Pi(k); \sigma^2 ) \prod_{j=1}^p \N(W(k+j); \phi^T \Pi(k+j); \sigma^2 )\\
&\propto \exp\left(\left( \left( W(k) - \phi^T \Pi(k) \right)^2  + \sum_{j=1}^p \left( W(k+j) - \phi^T \Pi(k+j)\right)^2 \right) / \sigma^2 \right)\\
\end{align*}
Note that each term inside the exponential includes $W(k)$ somewhere: the first term explicitly, and all subsequent terms as a component of the $\Pi(k')$ vector. We can thus imagine rewriting each of these terms as $(\phi^*_j W(k) - z_j)$ for some $z_j$, where $\phi^*_j$ is the coefficient on the $W(k)$ term that we've pulled out, and $z_j$ is just ``whatever's left'' after pulling out that term. Formally, this gives
\begin{align*}
z_0 &= \phi^T \Pi(k)\\
z_j &= W(k+j) - \sum_{i=1, i \ne j}^p \phi_i W(k+j-i)
\end{align*}

\begin{align*}
\phi^*_0 &= 1\\
\phi^*_j &= -\phi_j
\end{align*}

Under this notation we can write

\begin{align*}
p(W(k-p_W : k+p_W)) & \propto \exp\left( \sum_{j=0}^p \left(\phi^*_j W(k) - z_j \right)^2  / \sigma^2 \right)\\
&= \exp\left( \| W(k) \v{\phi^*} - \v{z} \|^2 / \sigma^2 \right)\\
\end{align*}
We can view this as a Gaussian distribution on $W(k) \v{\phi^*}$ with mean $\v{z}$ and covariance $\sigma^2 \mathcal{I}$. By the standard formula for linear transformations of a Gaussian, we can transform by $\v{\phi^*}^T / \|\v{\phi^*}\|^2$ to yield a Gaussian $\N\left(W(k); \mu, \sigma^2 / \|\v{\phi^*}\|^2\right)$  where $\mu = \v{\phi^*}^T\v{z} /  \|\v{\phi^*}\|^2$. This gives the smoothing distribution on $W(k)$.

We can calculate this efficiently by first computing the filtered means $f_t = \sum_{i=1}^p \phi_i W(t-i)$, then computing each $z$ value as $z_j = W(k+j) - (f_{k+j} - \phi_{j} f_k)$, i.e. we remove the $k$ term from the filtered prediction at each timestep.

\section{Partly Observed Smoothing Distributions}

We now consider the case where some of the $W(t)$'s are unknown.

\subsection{Filtering}

We begin by considering just the filtering distribution. In particular, suppose some $W(\ell)$ is unobserved, where $k-p < \ell < k$ and we let $L = k-\ell$ denote the coefficient $\phi_L$ by which $W(\ell)$ predicts $W(k)$. Now we have unknowns $W(k)$ and $W(\ell)$. We solve for the marginal on $W(k)$:
\begin{align*}
p(W(k) | W(\ell-p), &\ldots, W(\ell-1), W(\ell+1), \ldots, W(k-1)) \\
&= \int p\left(W(k), W(\ell) | W(\ell-p), \ldots, W(\ell-1), W(\ell+1), \ldots, W(k-1)\right) d W(\ell)\\
&= \int \N\left(W(k); \phi_{\neg L}^T \Pi_{\neg \ell}(k)  + \phi_L W(\ell), \sigma^2 \right) \N\left(W(\ell); \phi^T \Pi(\ell), \sigma^2\right) dW(\ell)
\end{align*}
where $\phi_{\neg L}$ and $\Pi_{\neg \ell}$ have the obvious interpretations as vectors excluding the element corresponding to $W(\ell)$. By the ``marginalization'' section of my notes on multivariate Gaussians, we find
\[p(W(k)) \sim \N\left(\phi_{\neg L}^T \Pi_{\neg \ell}(k)  + \phi_L \phi^T \Pi(\ell), \sigma^2 + \sigma^2\phi_L^2  \right).\]
This is essentially the usual filtering distribution on $W(k)$, but with $W(\ell)$ replaced by its filtered prediction $\phi^T \Pi(\ell)$, and the variance increased slightly to compensate.

It is easy to see that if we had {\em multiple} missing values in the dependence set for $W(k)$, we could apply this formula recursively: first calculate the filtering distribution for the second missing value given the first, then for the third given the second and first, and so on: in each case we substitute the filtered mean for each missing variable in the mean calculation, and add the filtered variance of each missing variable, weighted by its squared coefficient, to the variance.

{\bf But wait!} This is wrong because if we depend on multiple missing values, they will in general also depend on each other. A good way to think of this is that each filtered timestep $W(k)$ is a Gaussian random variable formed by the linear combination $\phi^T \Pi(k) + \N(0, \sigma^2)$, where each of its dependencies in $\Pi(k)$ is {\em also} such a Gaussian variable. As a sum of correlated variables, $\phi^T \Pi(k)$ has variance
\begin{align*}
Var\left(\sum_i^p \phi_i W(k-i) \right) &= \sum_{i,j} \phi_i \phi_j Cov(W(k-i), W(k-j))  \\
&= \sum_i \phi_i^2 Var(W(k-i)) + \sum_{i \ne j} \phi_i \phi_j Cov(W(k-i), W(k-j)) \\
&= \sum_i \phi_i^2 Var(W(k-i)) + 2\sum_{i > j} \phi_i \phi_j Cov(W(k-i), W(k-j))
\end{align*}

Now how do we find these covariances? In general if we have $Z = X+Y$ where $X$ and $Y$ are uncorrelated Gaussian rvs, then $var(Z) = var(X) + var(Y)$ and $cov(Z, X) = E[X(X+Y)] = E[X^2 + XY] = E[X^2] = Var(X)$.
What if $X$ and $Y$ are correlated with some covariance $\xi$? Then $cov(Z, X) = Var(X) + \xi$.

In the autoregressive case, say we know the variance and covariances up to $W(k)$. Now we want $W(k+1)$.

Assume WLOG that $i > j$, then we have
\begin{align*}
Cov(W(k-i), W(k-j)) &= E\left[ W(k-i) W(k-j) \right]\\
&= E\left[\left(\sum_{i'}\phi_{i'} W(k-i-i')\right) \left(\sum_{j'} \phi_{j'}W(k-j-j')\right)  \right]\\
&= E\left[\sum_{i',j'}\phi_{i'} \phi_{j'} W(k-i-i') W(k-j-j')  \right]
\end{align*}

\subsection{Smoothing}

We now return to the smoothing calculation as described above. Recall that we factored the joint distribution on $W(k), \ldots, W(k+p)$, conditioned on $W(k-p), \ldots, W(k-1)$, into the product of filtering distributions for each of $W(k), \ldots, W(k+p)$. Thus a missing observation will have two effects: first, we will not have a factor for the filtering distribution of that variable, and second, that variable will be missing from the filtering condition for all other relevant variables.

I don't want to figure out the notation to write this all out, but the implementation is: we compute the filtering distribution as described above, then also just ignore any component of $z$ corresponding to a missing observation. A slight change is that we now have different filtering variances for different variables. Let $\sigma^2_j$ denote the filtering variance for $W(k+j)$, so that $\v{\sigma^2}$ is a $p+1$-dimensional vector. Then
\begin{align*}
p(W(k-p_W : k+p_W)) & \propto \exp\left( \sum_{j=0}^p \left(\phi^*_j W(k) - z_j \right)^2  / \sigma_j^2 \right)\\
&= \exp\left( ( W(k) \v{\phi^*} - \v{z})^T \text{diag}(\sigma^2)^{-1}  ( W(k) \v{\phi^*} - \v{z}) \right)
\end{align*}
and applying the linear transformation $\v{\phi^*}^T / \|\v{\phi^*}\|^2$ now yields the Gaussian $\N\left(W(k); \mu,   \xi   \right)$  where $\mu = \v{\phi^*}^T\v{z} /  \|\v{\phi^*}\|^2$ and $\xi = \v{\phi^*}^T  \text{diag}(\sigma^2) \v{\phi^*} / \| \v{\phi^*}\|^4$.

\end{document}


\subsection{Quadratic forms}

One of the applications of orthogonal diagonalization is that of quadratic forms and graphs of level curves of a quadratic form. This section has to do with rotation of axes
so that with respect to the new axes, the graph of the level curve of a
quadratic form is oriented parallel to the coordinate axes. This makes it
much easier to understand. For example, we all know that $x_1^2 + x_2^2=1$ represents the equation in two variables whose graph in $\R^2$ is a circle of radius $1$. But how do we know what the graph of the equation $5x_1^2 + 4x_1x_2 + 3x_2^2=1$ represents?
\index{principal axis!quadratic forms}

We first formally define what is meant by a quadratic form. In this section we will work with only \textit{real} quadratic forms, which means that the coefficients will all be real numbers.

\begin{definition}{Quadratic form}{quadratic-form}
A \textbf{quadratic form}\index{quadratic form} is a polynomial of degree two in $n$ variables $x_1, x_2,\ldots, x_n$, written as a linear combination of $x_i^{2}$ terms and $x_ix_j$ terms.
\end{definition}

Consider the quadratic form $q = a_{11}x_1^2 + a_{22}x_2^2 + \ldots + a_{nn}x_n^2 + a_{12}x_1x_2 + \ldots$. We can write $\vect{x} = \begin{mymatrix}{r}
x_1 \\
x_2 \\
\vdots \\
x_n
\end{mymatrix}$ as the vector whose entries are the variables contained in the quadratic form.

Similarly, let $A = \begin{mymatrix}{rrrr}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{mymatrix}$ be the matrix whose entries are the coefficients of $x_i^2$ and $x_ix_j$ from $q$. Note that the matrix $A$ is not unique, and we will consider this further in the example below. Using this matrix $A$,  the quadratic form can be written as $q = \vect{x}^T A \vect{x}$.

\begin{eqnarray*}
q &=& \vect{x}^T A \vect{x} \\
&=& \begin{mymatrix}{rrrr}
x_1 & x_2 & \cdots & x_n
\end{mymatrix}
 \begin{mymatrix}{rrrr}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{mymatrix}
\begin{mymatrix}{r}
x_1 \\
x_2 \\
\vdots \\
x_n
\end{mymatrix} \\
&=&
\begin{mymatrix}{rrrr}
x_1 & x_2 & \cdots & x_n
\end{mymatrix}
\begin{mymatrix}{c}
a_{11}x_1 + a_{21}x_2 + \ldots + a_{n1}x_n \\
a_{12}x_1 + a_{22}x_2 + \ldots + a_{n2}x_n \\
\vdots \\
a_{1n}x_1 + a_{2n}x_2 + \ldots + a_{nn}x_n
\end{mymatrix} \\
&=& a_{11}x_1^2 + a_{22}x_2^2 + \ldots + a_{nn}x_n^2 + a_{12}x_1x_2 + \ldots
\end{eqnarray*}

Let's explore how to find this matrix $A$. Consider the following example.

\begin{example}{Matrix of a quadratic form}{matrix-quadratic-form}
Let a quadratic form $q$ be given by
\[
q = 6x_1^2 + 4x_1x_2 + 3x_2^2
\]
Write $q$ in the form $\vect{x}^TA\vect{x}$.
\end{example}

\begin{solution}
First, let $\vect{x} = \begin{mymatrix}{r}
x_1 \\
x_2
\end{mymatrix}$ and $A = \begin{mymatrix}{rr}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{mymatrix}$.

Then, writing $q = \vect{x}^TA\vect{x}$ gives
\begin{eqnarray*}
q &=& \begin{mymatrix}{rr}
x_1 & x_2
\end{mymatrix}
\begin{mymatrix}{rr}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{mymatrix}
\begin{mymatrix}{r}
x_1 \\
x_2
\end{mymatrix} \\
&=& a_{11}x_1^2 + a_{21}x_1x_2 + a_{12}x_1x_2 + a_{22}x_2^2
\end{eqnarray*}

Notice that we have an $x_1x_2$ term as well as an $x_2x_1$ term. Since multiplication is commutative, these terms can be combined. This means that $q$ can be written
\[
q =  a_{11}x_1^2 + (a_{21}+ a_{12}) x_1x_2 + a_{22}x_2^2
\]

Equating this to $q$ as given in the example, we have
\[
 a_{11}x_1^2 + (a_{21}+ a_{12}) x_1x_2 + a_{22}x_2^2 =  6x_1^2 + 4x_1x_2 + 3x_2^2
\]

Therefore,
\begin{eqnarray*}
a_{11} &=& 6 \\
a_{22} &=& 3 \\
a_{21}+a_{12} &=& 4
\end{eqnarray*}

This demonstrates that the matrix $A$ is not unique, as there are several correct solutions to $a_{21}+a_{12} = 4$. However, we will \textit{always} choose the coefficients such that $a_{21} = a_{12} = \frac{1}{2} (a_{21}+a_{12})$. This results in $a_{21} = a_{12} = 2$. This choice is key, as it will ensure that $A$ turns out to be a symmetric matrix.

Hence,
\[
A =
\begin{mymatrix}{rr}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{mymatrix}
=
\begin{mymatrix}{rr}
6 & 2 \\
2 & 3
\end{mymatrix}
\]

You can verify that $q = \vect{x}^T A \vect{x}$ holds for this choice of $A$.
\end{solution}

The above procedure for choosing $A$ to be symmetric applies for any quadratic form $q$. We will \textit{always} choose coefficients such that $a_{ij}=a_{ji}$.

We now turn our attention to the focus of this section. Our goal is to start with a quadratic form $q$ as given above and find a way to rewrite it to eliminate the $x_ix_j$ terms. This is done through a change of variables. In other words, we wish to find $y_i$ such that
\[
q = d_{11}y_1^2 + d_{22}y_2^2 + \ldots + d_{nn}y_n^2
\]
 Letting $\vect{y} = \begin{mymatrix}{r}
y_1 \\
y_2 \\
\vdots \\
y_n
\end{mymatrix}$ and $D = \mat{d_{ij} }$, we can write $q = \vect{y}^T D \vect{y}$ where $D$ is the matrix of coefficients from $q$. There is something special about this matrix $D$ that is crucial. Since no $y_iy_j$ terms exist in $q$, it follows that $d_{ij} = 0$ for all $i \neq j$. Therefore, $D$ is a diagonal matrix. Through this change of variables, we find the \textbf{principal axes}\index{principal axes} $y_1, y_2,\ldots, y_n$ of the quadratic form.

This discussion sets the stage for the following essential theorem.

\begin{theorem}{Diagonalizing a quadratic form}{diagonalize-quadratic-form}
Let $q$ be a quadratic form in the variables $x_1,\ldots, x_n$. It follows that $q$ can be written in the form $q = \vect{x}^T A \vect{x}$ where
\[
\vect{x} = \begin{mymatrix}{r}
x_1 \\
x_2 \\
\vdots \\
x_n
\end{mymatrix}
\]
and $A = \mat{a_{ij} }$ is the symmetric matrix of coefficients of $q$.

New variables $y_1, y_2,\ldots, y_n$ can be found such that $q = \vect{y}^T D \vect{y}$ where
\[
\vect{y} = \begin{mymatrix}{r}
y_1 \\
y_2 \\
\vdots \\
y_n
\end{mymatrix} \] and $D=\mat{d_{ij} }$ is a diagonal matrix. The matrix $D$ contains the eigenvalues of $A$ and is found by orthogonally diagonalizing $A$.
\end{theorem}

While not a formal proof, the following discussion should convince you that the above theorem holds. Let $q$ be a quadratic form in the variables $x_1,\ldots, x_n$. Then, $q$ can be written in the form $q = \vect{x}^T A \vect{x}$ for a symmetric matrix $A$.
By Theorem~\ref{thm:orthogonal-diagonalization} we can orthogonally diagonalize the matrix $A$ such that $U^TAU = D$ for an orthogonal matrix $U$ and diagonal matrix $D$.

Then, the vector $\vect{y} = \begin{mymatrix}{r}
y_1 \\
y_2 \\
\vdots \\
y_n
\end{mymatrix}
$ is found by $\vect{y} = U^T \vect{x}$. To see that this works, rewrite $\vect{y} = U^T \vect{x}$ as $\vect{x} = U\vect{y}$. Letting $q = \vect{x}^TA\vect{x}$, proceed as follows:
\begin{eqnarray*}
q &=& \vect{x}^T A \vect{x}\\
&=& (U\vect{y})^T A (U\vect{y})\\
&=& \vect{y}^T (U^TAU) \vect{y} \\
&=& \vect{y}^T D \vect{y}
\end{eqnarray*}

The following procedure details the steps for the change of variables given in the above theorem.

\begin{procedure}{Diagonalizing a quadratic form}{diagonalize-quadratic-form}
Let $q$ be a quadratic form in the variables $x_1,\ldots, x_n$ given by
\[
q = a_{11}x_1^2 + a_{22}x_2^2 + \ldots + a_{nn}x_n^2 + a_{12}x_1x_2+\ldots
\]
Then, $q$ can be written as $q = d_{11}y_1^2 + \ldots + d_{nn}y_n^2$ as follows:

\begin{enumerate}
\item
Write $q = \vect{x}^T A \vect{x}$ for a symmetric matrix $A$.

\item
Orthogonally diagonalize $A$ to be written as $U^TAU=D$ for an orthogonal matrix $U$ and diagonal matrix $D$.

\item
Write $\vect{y} = \begin{mymatrix}{c}
y_1 \\
y_2 \\
\vdots \\
y_n
\end{mymatrix}$. Then, $\vect{x} = U \vect{y}$.

\item
The quadratic form $q$ will now be given by
\[
q = d_{11}y_1^2 + \ldots + d_{nn}y_n^2 = \vect{y}^T D \vect{y}
\]
where $D = \mat{d_{ij} }$ is the diagonal matrix found by orthogonally diagonalizing $A$.
\end{enumerate}
\end{procedure}

Consider the following example.

\begin{example}{Choosing new axes to simplify a quadratic form}{new-axes1}
Consider the following level curve
\[
6x_1^2 + 4x_1x_2 + 3x_2^2 = 7
\]
shown in the following graph.
\begin{center}
\begin{tikzpicture}[scale=0.5]
\draw[-, thick](-2,0)--(2,0);
\node[above right] at (2,0){$x_1$};
\draw[-, thick](0,-2)--(0,2);
\node[above right] at (0,2){$x_2$};
\draw[blue, ultra thick, domain=-1.78376:1.78376] plot(\x, {0.2*(-2*\x-sqrt(35-11*\x*\x))});
\draw[blue, ultra thick, domain=-1.78376:1.78376] plot(\x, {0.2*(sqrt(35-11*\x*\x)-2*\x)});
\end{tikzpicture}
\end{center}

Use a change of variables to choose new axes such that the ellipse is oriented parallel to the new coordinate axes. In other words, use a change of variables to rewrite $q$ to eliminate the $x_1x_2$ term.
\end{example}

\begin{solution}
Notice that the level curve is given by $q = 7$ for $q = 6x_1^2 + 4x_1x_2 + 3x_2^2$. This is the same quadratic form that we examined earlier in Example~\ref{exa:matrix-quadratic-form}. Therefore we know that we can write $q = \vect{x}^T A \vect{x}$ for the matrix
\[
A = \begin{mymatrix}{rr}
6 & 2 \\
2 & 3
\end{mymatrix}
\]

Now we want to orthogonally diagonalize $A$ to write $U^TAU=D$ for an orthogonal matrix $U$ and diagonal matrix $D$. The details are left to the reader, and you can verify that the resulting matrices are
\begin{eqnarray*}
U &=&
\begin{mymatrix}{rr}
\vspace{0.05in}\frac{2}{\sqrt{5}} & -\vspace{0.05in}\frac{1}{\sqrt{5}} \\
\vspace{0.05in}\frac{1}{\sqrt{5}} & \vspace{0.05in}\frac{2}{\sqrt{5}}
\end{mymatrix} \\
D &=&
\begin{mymatrix}{rr}
 7 & 0 \\
0 & 2
\end{mymatrix}
\end{eqnarray*}

Next we write $ \vect{y} = \begin{mymatrix}{c}
y_1 \\
y_2
\end{mymatrix}$. It follows that $\vect{x} = U \vect{y}$.

We can now express the quadratic form $q$ in terms of $y$, using the entries from $D$ as coefficients as follows:
\begin{eqnarray*}
q &=& d_{11}y_1^2 + d_{22}y_2^2 \\
&=& 7y_1^2 + 2y_2^2
\end{eqnarray*}

Hence the level curve can be written $7y_1^2 + 2y_2^2 =7$.
The graph of this equation is given by:

\begin{center}
\begin{tikzpicture}
\draw[-, thick](-2,0)--(2,0);
\node[above right] at (2,0){$y_1$};
\draw[-, thick](0,-2.5)--(0,2.5);
\node[above right] at (0,2.5){$y_2$};
\draw[ultra thick, blue] (0,0) ellipse (1cm and 2cm);
\end{tikzpicture}
\end{center}

The change of variables results in new axes such that with respect to the new axes, the ellipse is oriented parallel to the coordinate axes. These are called the \textbf{principal axes} of the quadratic form.
\end{solution}

The following is another example of diagonalizing a quadratic form.

\begin{example}{Choosing new axes to simplify a quadratic form}{new-axes2}
Consider the level curve
\begin{equation*}
5x_1^{2}-6x_1x_2+5x_2^{2}=8
\end{equation*}
shown in the following graph.

\begin{center}
\begin{tikzpicture}[scale=0.5]
\draw[-, thick](-2,0)--(2,0);
\node[above right] at (2,0){$x_1$};
\draw[-, thick](0,-2)--(0,2);
\node[above right] at (0,2){$x_2$};
\draw[blue, ultra thick, domain=-1.58113:1.58113] plot(\x, {0.2*(3*\x-2*sqrt(2)*sqrt(5-2*\x*\x))});
\draw[blue, ultra thick, domain=-1.58113:1.58113] plot(\x, {0.2*(2*sqrt(2)*sqrt(5-2*\x*\x)+3*\x)});
\end{tikzpicture}
\end{center}

Use a change of variables to choose new axes such that the ellipse is oriented parallel to the new coordinate axes. In other words, use a change of variables to rewrite $q$ to eliminate the $x_1x_2$ term.
\end{example}

\begin{solution}
First, express the level curve as $\vect{x}^TA\vect{x}$ where $\vect{x} = \begin{mymatrix}{r}
x_1 \\
x_2
\end{mymatrix}$ and $A$ is symmetric. Let $A = \begin{mymatrix}{rr}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{mymatrix}$. Then $q = \vect{x}^T A \vect{x}$ is given by
\begin{eqnarray*}
q &=&  \begin{mymatrix}{cc}
x_1 & x_2
\end{mymatrix}
\begin{mymatrix}{rr}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{mymatrix}
\begin{mymatrix}{r}
x_1 \\
x_2
\end{mymatrix}\\
&=& a_{11}x_1^2 + (a_{12} + a_{21})x_1x_2 + a_{22}x_2^2
\end{eqnarray*}

Equating this to the given description for $q$, we have
\[
5x_1^2 -6x_1x_2 + 5x_2^2 =  a_{11}x_1^2 + (a_{12} + a_{21})x_1x_2 + a_{22}x_2^2
\]
This implies that $a_{11} = 5, a_{22} = 5$ and in order for $A$ to be symmetric, $a_{12} = a_{22} = \frac{1}{2} (a_{12}+a_{21}) = -3$. The result is $A = \begin{mymatrix}{rr}
5 & -3 \\
-3 & 5
\end{mymatrix}$. We can write $q = \vect{x}^TA\vect{x}$ as
\begin{equation*}
\begin{mymatrix}{cc}
x_1 & x_2
\end{mymatrix} \begin{mymatrix}{rr}
5 & -3 \\
-3 & 5
\end{mymatrix} \begin{mymatrix}{c}
x_1 \\
x_2
\end{mymatrix} =8
\end{equation*}

Next, orthogonally diagonalize the matrix $A$ to write $U^TAU = D$. The details are left to the reader and the necessary matrices are given by
\begin{eqnarray*}
U &=& \begin{mymatrix}{rr}
\vspace{0.05in}\frac{1}{2}\sqrt{2} & \vspace{0.05in}\frac{1}{2}\sqrt{2} \\
\vspace{0.05in}\frac{1}{2}\sqrt{2} & -\vspace{0.05in}\frac{1}{2}\sqrt{2}
\end{mymatrix} \\
D &=&
\begin{mymatrix}{rr}
2 & 0 \\
0 & 8
\end{mymatrix}
\end{eqnarray*}

Write $\vect{y} = \begin{mymatrix}{r}
y_1 \\
y_2
\end{mymatrix}$, such that $\vect{x} = U \vect{y}$. Then it follows that $q$ is given by
\begin{eqnarray*}
q &=& d_{11}y_1^2 + d_{22}y_2^2 \\
&=& 2y_1^{2}+8y_2^{2}
\end{eqnarray*}
Therefore the level curve can be written as $2y_1^{2}+8y_2^{2}=8$.

This is an ellipse which is parallel to the coordinate axes. Its graph is of
the form

\begin{center}
\begin{tikzpicture}
\draw[-, thick](-2.5,0)--(2.5,0);
\node[above right] at (2.5,0){$y_1$};
\draw[-, thick](0,-2)--(0,2);
\node[above right] at (0,2){$y_2$};
\draw[ultra thick, blue] (0,0) ellipse (2cm and 1cm);
\end{tikzpicture}
\end{center}

\noindent Thus this change of variables chooses new axes  such that with respect to these new axes, the
ellipse is oriented parallel to the coordinate axes.
\end{solution}


\chapter{Physically-based animation} \label{chapter:pba}
\section{Particles} \label{sec:particles}
\subsection{Basic equation}
A particle is a moving point with a mass. Generally the mass is a constant over time while its position and velocity can vary. We therefore consider the mass $ m $ (in $ kg $) as an attribute while its position $ x $ (in $ m $) and its velocity $ v $ (in $m.s^{-1}$) are its state variables.
Particles obey Newton's law:
\begin{equation} \label{eq:newton}
ma = \Sigma f
\end{equation}
where $a$ is the particle's acceleration (in $m.s^{-2}$). This defines the Ordinary Differential Equation (ODE) $a(t) = f(x,v,t)$. Physically-based animation requires us to repeatedly solve it over the interval $[t,t+dt]$ and redisplay.

From equation \ref{eq:newton} we can deduce $a=1/m\;\Sigma f$ and integrate time over a time step dt, and so on. The simplest integration method is Euler's explicit scheme:
\begin{eqnarray}
v(t+dt) &=& v(t)+a(t)dt \nonumber \\
x(t+dt) &=& x(t)+v(t)dt \label{eq:expliciteuler}
\end{eqnarray}

Particles can live in any k-dimensional space $\Re^k$, where state variables and forces are k-dimensional vectors of scalar values. The dynamics equation \ref{eq:newton} applies to each scalar value.
When considering $n$ particles the equations can be conveniently written in matrix form:
\begin{eqnarray*}
\ma M \ve a &=& \ve f\\
\ve a &=& \ma M^{-1} \ve f
\end{eqnarray*}
where \ma M is a diagonal matrix of dimension $kn\times kn$ , \ve a and \ve f are vectors of dimension $kn$ gathering all the scalar components associated with each particle.

Numerical integration can generate instabilities leading to the divergence of the simulated system. To avoid this, one solution is to decrease the time step. The other solution is to use an implicit integration scheme, which takes into account the variation of the forces during the time step. The simplest one is the implicit Euler's method which applies a step based on the forces at the end of the time step instead of the beginning. Equation \ref{eq:expliciteuler} becomes:
\begin{eqnarray}
v(t+dt) &=& v(t)+a(t+dt)dt \nonumber\\
x(t+dt) &=& x(t)+v(t+dt)dt \label{eq:impliciteuler}
\end{eqnarray}
Since $a(t+dt)$ is unknown we have to solve an equation.
If we write $v(t+dt) = v(t)+\Delta v$ the matrix form equation to solve is:
\begin{equation}
\label{eq:matimplicit}
\left( \ma M + dt \ma D + dt^2 \ma K \right) \ve{\Delta v} = dt \left( \ve f(t) + \ma D \ve{v}(t) \right)
\end{equation}
where the damping matrix $\ma D = \delta \ve f/\delta \ve v$ encodes the variation of force given a variation of velocity, and the stiffness matrix $\ma K = \delta \ve f/\delta \ve p$ encodes the variation of force given a variation of position.

\subsection{Forces}
The forces are responsible for the accelerations of the bodies. Their physical unit is the Newton ($N=kg.m.s^{-2}$).
Here we briefly review the most commonly used forces.

\subsubsection{Weight}
A uniform gravitational field $g$ (in $m.s^{-2}$) applies a force
\begin{equation} \label{eq:gravity}
f = mg
\end{equation}
to each particle where $m$ is the mass of the particle.

\subsubsection{Linear damping}
Damping transforms kinetic energy to heat by applying a force opposed to the velocity. It tends to slow down the objects. Linear damping is proportional to the velocity, thus
\begin{equation}\label{eq:lineardamping}
f=-\nu v
\end{equation}
where $v$ is the velocity of the particle and $\nu$ a positive scalar (in $kg.s^{-1}$).

\subsubsection{Air damping}
Air damping is proportional to the square of the velocity of the body with respect to the air:
\begin{equation}
f = -\rho S_u C_u v^2 u
\end{equation}
where $\rho$ is the volumic mass the air ($kg.m^{-3}$), $v$ the velocity of the object, $u$ a no-dimensional unit vector in the direction of the velocity, $S$ the area ($m^2$) of the object projected along $u$, and $C_u$ a no-dimensional coefficient associated with the shape of the object and the direction $u$.

\subsubsection{Linear springs}
A springs applies an elastic force between two points. It is modeled using its rest length $l_0$ (in $m$) and its stiffness $k$ (in $N.m^{-1}$).
Let $i$ and $j$ be the indices of points linked by a given spring.
The force applied by a linear spring to point $i$ is given by:
\begin{equation}
\label{eq:spring}
f_i = k( l-l_0 ) u
\end{equation}
where $l=\|x_j - x_i\|$ is the distance between the points and $u$ a unit vector pointing from point $i$ to point $j$. The force $f_j$ applied to point $j$ is the opposite: $f_j = -f_i$. Nonlinear springs can be used to model more complex behaviors.

\subsubsection{Linear damped springs}
Damping forces are commonly associated with springs in order to dissipate energy. They are opposed to the relative velocity of the points. They are typically modeled using a coefficient $\nu$ (in $kg.s^{-1}$).
The force applied by a linear damped spring to point $i$ is given by:
\begin{equation}
\label{eq:dampedspring}
f_i = \left( k( l-l_0 ) + \nu v_{ij} \right) u
\end{equation}
where $v_{ij} = (v_j-v_i).u$ is the relative velocity of the particles along direction $u$.

\subsubsection{Finite elements}
Finite elements is a powerful paradigm for modeling continuous material. At our level, we can see them as springs acting on more than two points simultaneously. For example, a tetrahedral finite element acts on the four vertices of a tetrahedron and allows a more effective control of stiffness and volume than using springs.

%===========================================================================================

\section{Solids}
A solid is a moving reference frame with a mass matrix. In two dimensions it has three degrees of freedom (DOFs), two translations and one rotation, while in three dimensions it has six DOFs, three translations and three independent rotation values. The remainder of this document focuses on three dimensions.

\subsection{Orientation}
There are different ways of modeling orientation ot one frame with respect to another in three dimensions, each of them with advantages and drawbacks:
\begin{itemize}
\item matrices directly define the axes of the solid with respect to a reference frame. They allow fast projections from one frame to another but they contain nine dependent entries and they can not be set up intuitively;
\item Euler angles are compact (three parameters) and intuitive but they have singularities and they can not be easily combined;
 \item (axis, angle) pairs are more intuitive and more compact (four parameters) than matrices but they do not allow projections and combinations;
\item quaternions are compact (four parameters) and allow easy projections and combinations, but they are not easy to set up intuitively.
\end{itemize}

\subsubsection{Orientation matrices}
Orientations matrices are $3\times 3$ matrices, each column gathering the coordinates of one axis of the rotated frame with respect to the reference frame. Each column is thus a unit vector orthogonal to the others. This creates six relations among the nine parameters, leaving three independent DOFs.

\subsubsection{Euler angles}
Euler angles model a sequence of three rotations along three pairwise-independent directions. For example, the following matrix product represents a rotation $\alpha$ along axis $x$ followed by a rotation $\beta$ along rotated axis $y$ followed by a rotation $\gamma$ along the twice rotated axis $z$.
%\begin{equation}\label{eq:angles euler}
$$
\left(\begin{array}{ccc}
1 & 0 & 0 \\
0 & \cos\alpha & -\sin\alpha \\
0 & \sin\alpha &  \cos\alpha
\end{array}\right)
\left(\begin{array}{ccc}
\sin\beta & 0 &  \cos\beta\\
0 & 1 & 0 \\
\cos\beta & 0 & -\sin\beta
\end{array}\right)
\left(\begin{array}{ccc}
\cos\gamma & -\sin\gamma & 0\\
\sin\gamma & \cos\gamma & 0\\
0 & 0 & 1\\
\end{array}\right)
$$
%\end{equation}
Alternatively, this can be seen as a rotation  $\gamma$ along axis $z$ followed by a rotation $\beta$ along the fixed axis $y$ followed by a rotation $\alpha$ along the fixed axis $x$. An example of singularity is the fact that in this system, rotation $(\pi,\pi,0)$ is equivalent with rotation $(0,0,\pi)$. Another example is the fact that rotation $(\alpha,\pi /2, \gamma)$ is equivalent with rotation $(0,\pi /2, \alpha+\gamma)$ for any $\alpha$ and $\gamma$ (this loss of one DOF is called \emph{gimbal lock}).

\subsubsection{Axis, angle}
The rotation $\theta$ along an axis defined by a unit vector $n$ has the following matrix:
$$
\rot{\theta}{u} = \mat{I} + \sin\theta\oppvec{n} + (1-\cos\theta)\oppvec{n}^2
$$
where matrix $\oppvec{n}$  is the vector product matrix operator:
%\begin{equation}\label{eq:oppvec}
$$
\oppvec{n} = \left(\begin{array}{ccc}
0 & -n_z & n_y \\
n_z & 0 & -n_x \\
-n_y & n_x & 0
\end{array}\right)
$$
%\end{equation}
It is possible to convert a matrix back to (axis, angle) by noticing that  $\trace{\mat R}=1+2\cos\theta$ et que $\mat R -\transp{\mat R} = 2\sin\theta\oppvec{n}$

\subsubsection{Quaternions}
Quaternions are an extension of complex numbers: $ \bm q = w + x\bm i + y \bm j + z \bm k = (w,\vect v)$.\\
w is the real part, \vect v the imagianry part.
Properties of \bm i, \bm j, \bm k:
$$
\begin{array}{l}
  \bm i^2 = \bm j^2 = \bm k^2 = -1\\
  \bm{ij}=\bm k,\;\bm{ji} = -\bm k\\
  \bm{jk}=\bm i,\;\bm{kj} = -\bm i\\
  \bm{ki}=\bm j,\;\bm{ik} = -\bm j\\
\end{array}
$$
A 3d vector is a pure imaginary quaternion:
$$
\bm p = (0,x,y,z)
$$
Product of quaternions (not commutative):
$$
\bm{q_1q_2} = (w_1w_2 - \bm v_1.\bm v_2, \; w_1\bm v_2 + w_2\bm v_1 + \bm v_1 \wedge \bm v_2)
$$
Conjugate quaternion:
$$
\begin{array}{l}
  \bm{\bar q} = w - x\bm i - y \bm j - z \bm k\\
  \bm{q\bar q} = w^2 + x^2 + y^2 + z^2
\end{array}
$$
Unit quaternions used to model rotations:
$$
\bm{q\bar q} = 1
$$
Rotation $(\theta, \bm u)$: {\em ($\bm u^2=1$)}
$$
\bm q_{(\theta,u)} = ( \cos{\frac{\theta}{2}}, u_x\sin{\frac{\theta}{2}}, u_y\sin{\frac{\theta}{2}}, u_z\sin{\frac{\theta}{2}})
$$
Rotation of a vector \bm p:$\;\;\;\bm{ qp\bar{q} }$\\
Rotation matrix associated with a unit quaternion:
$$
\left( \begin{array}{ccc}
  1 - 2y^2 - 2z^2 & 2xy - 2wz & 2xz + 2wy \\
  2xy + 2wz & 1-2x^2-2z^2 & 2yz - 2wx \\
  2xz - 2wy & 2yz + 2wx & 1 - 2x^2 - 2y^2
\end{array} \right)
$$
Combination of rotations: $\rot{\alpha}{u}\rot{\beta}{v} \longrightarrow q_{(\alpha,u)}q_{(\beta,v)}$\\
Inverse rotation: $\inv{ q_{(\theta,u)}} = q_{(-\theta,u)} = q_{(\theta,-u)} = (-w,\vect v) = (w,\vect -v)$ \\
Conversion $(w, \vect v) \longrightarrow ( \theta, \vect u)$ :
\begin{eqnarray*}
\cos(\theta/2) &=& w\\
\sin(\theta/2) &=& \|\vect v\|\\
\vect u &=& \vect v/\|\vect v\|
\end{eqnarray*}

The time derivative of the unit quaternion $q$ defining the orientation of a solid with angular velocity $\omega$ (vector of $\RRR$, see section \ref{sec:omega}) is: $\dot q = \frac{1}{2}\omega q$.

\subsection{Kinematics}
\todo{choose omega or Omega. Simplify notations where possible.}
\todo{choose n or u.}
\subsubsection{Derivative in \Rep{0} of a vector fixed in \Rep{1}. Angular velocity.} \label{sec:omega}
Consider vector \fixedans{\vect u}{1}, fixed in frame \rep{1}. Frame \rep{1} rotates with respect to frame \rep{0}. Consider the projection \vecin{\fixedans{\vect u}{1}}{0} of this vector to \rep{0}, which we sometimes call \vect u for clarity, and its derivative in \rep{0} which we write $\derivedans{\fixedans{\bm u}{1}}{0}$.

Let \mat{R(dt)} be the rotation of \rep{1} between time $t$ and $t+dt$. We write:
\begin{eqnarray}
 \vect u(t+dt) &=& \mat{R(dt)} \vect u(t)\\
 \vect u(t+dt) - \vect u(t)&=& (\mat{R(dt)}-\ident{}) \vect u(t) \label{eq ri}
\end{eqnarray}
Let $\dot{\theta}$ be the angular velocity along the rotation axis, which we set to \vect z for clarity. The first-order Taylor series is:
$$
 \mat{R(dt)}-\ident{} =
 \left(\begin{array}{ccc}
  cos(\dot{\theta}dt)-1 & -sin(\dot{\theta}dt) & 0\\
   sin(\dot{\theta}dt)& cos(\dot{\theta}dt)-1& 0\\
  0 & 0 & 0
 \end{array}\right)
 \longrightarrow
 \left(\begin{array}{ccc}
  0 & -\dot{\theta}dt & 0\\
  \dot{\theta}dt & 0 & 0\\
  0 & 0 & 0
 \end{array}\right)
 =
 \dot{\theta}dt \oppvec{z}
$$
which can be easily extended to any rotation axis. Let $\vecrot{1}{0}=\dot{\theta}\vect n$. Dividing expression \ref{eq ri} by $dt$ and decreasing $dt$ to $0$ gives $\dot{\mat R} = \oppvec{ \vecrot{1}{0} }$.

We can write the time derivative in \rep{0}: $\derivedans{\fixedans{\bm u}{1}}{0}  = \vecrot{1}{0} \wedge  \fixedans{\vect u}{1}$, or more simply:

\begin{equation}\label{vrot}
\begin{array}{rcl}
 \dot{\vect u} &=& \dot{\mat R} \vect u \\
               &=& \oppvec{ \vecrot{1}{0} } \vect u \\
               &=& \vecrot{1}{0} \wedge \vect u
\end{array}
\end{equation}

\subsection{Velocity in \Rep{0} of a point fixed in \Rep{1}. Velocity field.}
We consider the velocity $\vfdans{A}{1}{0}$ in \rep{0} of a point $A$ fixed in \rep{1} while \rep{1} moves with respect to \rep{0}. Let $O_0$ be the origin of \rep{0} and $O_1$ the origin of \rep{1}. The following relation holds:
$$ \vfdans{A}{1}{0} = \vfdans{O_1}{1}{0} + \vecrot{1}{0} \wedge \vecf{O_1A} \label{eq vit} \label{eq vit solide}
$$

\subsection{Acceleration in \Rep{0} of  point fixed in \Rep{1}. Acceleration field. }
By deriving equation \ref{eq vit}, and based on the fact that $\vecf{O_1A}$ is fixed in \rep{1}, we get the acceleration of A, fixed in \rep{1}, with respect to \rep{0}:
\begin{equation}\label{eq acc}
 \afdans{A}{1}{0} = \afdans{O_1}{1}{0} + \accrot{1}{0}\wedge \vecf{O_1A} + \vecrot{1}{0} \wedge \left( \vecrot{1}{0} \wedge \vecf{O_1A} \right)
\end{equation}

\subsection{Derivative in \rep{0} of a vector defined in \rep{1}}
Let $(\vect e_1, \vect e_e, \vect e_3)$ be a base of \rep{1}. We have:
\begin{eqnarray*}
 \vecin{u}{1} &=& \sum_i x_i \vect e_i\\
 \dot{\vect u} &=& \sum_i \dot x_i \vect e_i + \sum_i x_i \dot{\vect e}_i
\end{eqnarray*}
and thus:
\begin{equation}\label{eq vec mob}
 \derivedans{u}{0} = \derivedans{u}{1} + \vecrot{1}{0} \wedge \vect u
\end{equation}

\subsection{Velocity in \rep{0} of a point moving in \rep{1}.}
Let \vmdans{A}{1} be the velocity of point $A$ with respect to \rep{1}. We have:
\begin{equation}\label{eq vit mob}
\vmdans{A}{0} = \vmdans{A}{1} + \vfdans{O_1}{1}{0} + \vecrot{1}{0} \wedge \vecf{O_1A}
\end{equation}
Note that $O_1$ being the origin of frame \rep{1}, we have $\vmdans{O_1}{0} = \vfdans{O_1}{1}{0}$.

\subsection{Acceleration in \rep{0} of a point moving in \rep{1}. Coriolis acceleration.}
EBy deriving equation \ref{eq vit mob} nous we get:
$$
 \amdans{A}{0} = \underbrace{\amdans{A}{1} + \vecrot{1}{0}\wedge \vmdans{A}{1}}_{\overset{\circ}{\vmdans{A}{1}}} + \amdans{O_1}{0} + \underbrace{\accrot{1}{0}\wedge \vect{O_1}{A} + \vecrot{1}{0}\wedge \vmdans{A}{1} + \vecrot{1}{0} \wedge (\vecrot{1}{0}\wedge \vecf{O_1A})}_{\overset{\circ}{\vecrot{1}{0} \wedge \vecf{O_1A}}}
$$
or:
\begin{equation}\label{eq acc mob}
 \amdans{A}{0} = \amdans{A}{1} +  \amdans{O_1}{0} + \vecrot{1}{0} \wedge (\vecrot{1}{0}\wedge \vecf{O_1A}) + 2\vecrot{1}{0}\wedge \vmdans{A}{1}
\end{equation}
with:
\begin{itemize}
\item $\amdans{A}{1} = \sum_i \ddot x_i \vect e_i$ relative acceleration
\item $\amdans{O_1}{0}$ frame acceleration (?)
\item $\vecrot{1}{0} \wedge (\vecrot{1}{0}\wedge \vecf{O_1A})$ centripetal acceleration
\item $2\vecrot{1}{0}\wedge \vmdans{A}{1}$ Coriolis acceleration
\end{itemize}

\subsection{Dynamics}
Solids accelerate linearly due to forces, and accelerate angularly due to torques. A given torque has the same value everywhere in the solid. However, a given force generates different torques at different points. The torque $\tau$ applied at point $c$ generated by a force $f$ applied at point $b$ is: $\tau=cb\wedge f$.

The acceleration $\ddot c$ of the mass center of a solid and its angular acceleration $\dot \omega$ with respect to the world are given by the relations:

    \begin{eqnarray*}
        m \bf{ \ddot c } = \sum\bf{f_{ext}} \\%\label{eq:PFD1}\\
        \bf{ I_M \dot \omega } + \bm{ \omega \times I_M \omega} = \sum\bf{\tau_{ext}} %\label{eq:PFD2}
    \end{eqnarray*}
where $m$ is the mass of the solid, $\sum {\bf f_{ext}}$ is the sum of the forces applied to the solid, ${\bf I_M}$ is the inertia matrix et $\sum {\bf \tau_{ext}}$ the sum of the torques applied to the solid and expressed at its mass center. The inertia matrix is given by:
$${\bf I_M} = \int_x \int_y \int_z \rho (x,y,z)\begin{bmatrix}  y^2+z^2 & -xy & -xz \\ -xy & x^2+z^2 & -yz \\ -xz & -yz & x^2+y^2 \end{bmatrix} dx dy dz$$
where $\rho(x,y,z)$ is the volumic mass of the naterial (in $kg.m^{-3}$).


%!TEX root = ../TTT4150-Summary.tex
\section{Kalman filtering}

A \emph{Kalman filter} recursively estimates the state of a process, such that it minimizes the mean squared error. Or, maximize separation of signal and noise.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Process model}

The \emph{discretized} process is
\begin{equation}
\begin{split}
	x_k &= \Phi x_{x-1} + w_{k-1} \\
	z_k &= H x_k + v_k
\end{split}
\end{equation}
where
\begin{itemize}
	\item $\Phi$ is the (state) \emph{transition matrix},
	\item $H$ is the \emph{design matrix},
	\item $w_k$ is random white process noise $p(w) \sim N(0,Q)$, and
	\item $v_k$ is random white measurement noise $p(v) \sim N(0,R)$.
\end{itemize}

The transition matrix is calculated from the continuous-time representation
\begin{equation}
	\dot{x} = F x + G u
\end{equation}
as
\begin{equation}
	\Phi = \euler^{F \Delta t} = I + F \Delta t + \frac{(F \Delta t)^2}{2!} + \dots
\end{equation}
or, for time-variant $F$
\begin{equation}
	\Phi_k = \laplace{(sI - F)^{-1}}_{t = \Delta t}.
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Method}

The goal is to compute an \emph{a posteriori} estimate\footnote{\emph{After} measuring.} $\hat{x}_k$ based on an \emph{a priori} estimate\footnote{\emph{Before} measuring.} $\hat{x}_k^-$, a measurement $z_k$, and a measurement prediction $H \hat{x}_k^-$. This is how we do it:
\begin{equation}
	\hat{x}_k = \hat{x}_k^- + K_k(z_k - H \hat{x}_k^-)
\end{equation}

The gain matrix $K$ is chosen to minimize the a posteriori error covariance $P_k = E \left[ e_k e_k\T \right]$, where $e_k \equiv x_k - \hat{x}_k$. Some math leads to
\begin{equation}
	K_k = P_k^- H\T \left( H P_k^- H\T + R \right)^{-1}.
\end{equation}
We have $\lim_{R \rightarrow 0} K_k = H^{-1}$, which gives $\hat{x}_k = H^{-1} z_k$. Makes sense, because zero measurement error covariance $R$ should let us trust the measurement fully. We also have $\lim_{P_k^- \rightarrow 0} K_k = 0$, giving $\hat{x}_k = \hat{x}_k^-$. Also makes sense, because zero a priori estimate error covariance $P_k^-$ should make us not trust the measurement at all.

These equations are split into the time update equations
\begin{equation}
\begin{split}
	\hat{x}_k^- &= \Phi_{k-1} \hat{x}_{k-1} \\
	P_k^-       &= \Phi_{k-1} \hat{P}_{k-1} \Phi_{k-1}\T + Q
\end{split}
\end{equation}
and the measurement update equations
\begin{equation}
\begin{split}
	K_k       &= P_k^- H\T \left( H P_k^- H\T + R \right)^{-1} \\
	\hat{x}_k &= \hat{x}_k^- + K_k(z_k - H \hat{x}_k^-) \\
	\hat{P}_k       &= \left( I - K_k H \right) P_k^-.
\end{split}
\end{equation}

Often, $Q$ and $R$ are simply considered tuning parameters. Large $R$ means we expect a large measurement error variance, and the filter converges slowly because it cannot trust the measurements. A small $R$ does the opposite: Converges fast, but possibly so fast that the estimate follows the measurement noise.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{IMU + GNSS integration}

GNSS has good long time accuracy, and gives measurements without drift. INS has good short time accuracy, but drifts a lot. Combining both in a \emph{complementary filter} gives ``the best of both worlds''.


\section{Cartesian Tensors}
In this section, we are only interested in the Cartesian coordinates in a right-handed basis.
\subsection{A Closer Look at Vectors}
Given the basis, we can write $\underline{x}\in\mathbb R^3$ in the form $x_i\underline{e_i}$ where the summation convention is used.
We should not identify the vector $\underline{x}$ with component $x_i$ since we may want to choose another basis for certain purposes.
But if we have $\underline{x}=x_i\underline{e_i}=x_i'\underline{e_i'}$ for right-handed bases $\underline{e_i},\underline{e_i'}$, then
$$x_i'=x_j'\delta_{ij}=x_j'\underline{e_j'}\cdot\underline{e_i'}=\underline{e_i'}\cdot(x_j'\underline{e_j'})=\underline{e_i'}\cdot(x_j\underline{e_j})=x_j\underline{e_i'}\cdot\underline{e_j}=R_{ij}x_j,R_{ij}=\underline{e_i'}\cdot\underline{e_j}$$
Playing the same game yields $x_i=\underline{e_i}\cdot\underline{e_j'}x_j'=R_{ji}x_j'$.
Combining them gives $x_i=R_{ji}R_{jk}x_k$, so $0=(R_{ji}R_{jk}-\delta_{ik})x_k$, which has to hold for any choice of $x_k$, therefore $R_{ji}R_{jk}=\delta_{ik}$.
If we set $R$ to be the matrix with entries $R_{ij}$, then what we obtained above means $R^\top R=I$.
So $R\in\operatorname{O}(3)$.
Now $x_i\underline{e_i}=x_i'\underline{e_i'}=R_{ij}x_j\underline{e_i'}=R_{ji}x_i\underline{e_j'}$, so $\underline{e_i}=R_{ji}\underline{e_j'}$, so $R$ has to be in $\operatorname{SO}(3)$ since both bases are right-handed.
In summary, changing from $\{\underline{e_i}\}$ to $\{\underline{e_i'}\}$ induces the change in components by multiplication of a matrix in $\operatorname{SO}(3)$, i.e. $x_i'=R_{ij}x_j$.
We call such objects rank-$1$ tensors of vectors.
\subsection{A Closer Look at Scalars}
Consider $\sigma=\underline{a}\cdot\underline{b}$.
Using $\underline{e_i}$ with $\underline{a}=a_i\underline{e_i},\underline{b}=b_i\underline{e_i}$, then $\sigma=a_ib_j\underline{e_i}\cdot\underline{e_j}=a_ib_j\delta{ij}=a_ib_i$.
If we used another set of basis vectors $\underline{a}=a_i'\underline{e_i'},\underline{b}=b_i'\underline{e_i'}$, then $\sigma'=a_i'b_i'$ has
$$\sigma'=a_i'b_i'=R_{ij}a_jR_{ik}b_k=R_{ij}R_{ik}a_jb_k=\delta_{jk}a_jb_k=a_jb_j=\sigma$$
as one may have expected.
Call such transformation of scalars rank-$0$ tensors.
\subsection{A Closer Look at Linear Maps}
Consider linear map $T:\mathbb R^3\to\mathbb R^3$ with $\underline{x}\mapsto\underline{y}=T(\underline{x})=\underline{x}-(\underline{x}\cdot\underline{n})\underline{n}$ which is jus the projection of $\underline{x}$ down the plane with normal $\underline{n}$.
If we use basis $\{\underline{e_i}\}$, then
$$y_i\underline{e_i}=T(x_j\underline{e_j})=x_jT(\underline{e_j})=x_j(\underline{e_j}-n_in_j\underline{e_i})=x_j(\delta_{ij}-n_in_j)\underline{e_i}$$
So $y_i=T_{ij}x_j$ where $T_{ij}=\delta_{ij}-n_in_j$.
If we used another basis $\underline{e_i'}$, we would have got $y_i'=T_{ij}'x_j'$ where $T_{ij}'=\delta_{ij}-n_i'n_j'$.
Note that using $n_i'=R_{ip}n_p$, etc., we have
$$T_{ij}'=\delta{ij}-R_{ip}R_{jq}n_pn_q=R_{ip}R_{jq}(\delta_{pq}-n_pn_q)=R_{ip}T_{pq}R_{jq}$$
So changing from one set of right handed orthonormal basis to another induces change in components of linear map $T$ (as a matrix) by $T_{ij}'=R_{ip}R_{jq}T_{pq}$, or $T'=RTR^\top$.
We call objects changing like that to be rank-$2$ tensors.
\subsection{Cartesian Tensors of General Rank}
\begin{definition}
    An object with components $T_{i_1\cdots i_n}$ is called a tensor of rank $n$ if its component transform according to $T_{i_1\cdots i_n}'=R_{i_1j_1}\cdots R_{i_nj_n}T_{j_1\cdots j_n}$ when we change from one right-handed Cartesian basis $\{\underline{e_i}\}$ to $\{\underline{e_i'}\}$ where $\det R=1$ and $R_{i_pi_r}R_{i_qi_r}=\delta_{i_pi_q}$ for $p,q,r$ distinct.
\end{definition}
Note that $R_{ij}$'s are rotation matrices.
\begin{example}
    1. If $u_{i_1},v_{i_2},\ldots,w_{i_n}$ are components of set of $n$ vectors, then $T_{i_1\cdots i_k}=u_{i_1}v_{i_2}\cdots w_{i_n}$ is a tensor of rank $n$.
    Suppose we change from $\{\underline{e_i}\}$ to $\{\underline{e_i'}\}$, then
    $$T_{i_1\cdots i_n}'=u_{i_1}'v_{i_2}'\cdots w_{i_n}'=R_{i_1j_1}u_{j_1}R_{i_2j_2}u_{j_2}\cdots R_{i_nj_n}u_{j_n}=R_{i_1j_1}\cdots R_{i_nj_n}T_{j_1\cdots j_n}$$
    2. The Kronecker delta $\delta_{ij}$ is a tensor of rank $2$ as it is independent of choice of basis.
    Indeed, we want $R_{ip}R_{jq}\delta_{pq}=R_{ip}R_{jp}=\delta_{ij}=\delta_{ij}'$.\\
    3. The Levi-Civita epsilon again is independent of choice of basis, so $\epsilon_{ijk}'=\epsilon_{ijk}$.
    We have
    $$R_{ip}R_{jq}R_{kr}\epsilon_{pqr}=\det(R)\epsilon_{ijk}=\epsilon_{ijk}=\epsilon_{ijk}'$$
    So it is a tensor of rank $3$.\\
    4. Experimental evidence suggests a linear relationship between code $j$ produced in some medium that is exposed to electric field $\underline{E}$.
    So a given Cartesian basis $\{\underline{e_i}\}$, we must have numbers $\sigma_{ij}$ such that $J_i=\sigma_{ij}E_j$, so if we change basis from $\{\underline{e_i}\}$ to $\{\underline{e_i'}\}$, then $\sigma_{ij}'E_j'=J_i'=R_{ip}J_p=R_{ip}\sigma_{pq}E_q=R_{ip}R_{jq}\sigma_{pq}E_j'$, so $\sigma_{ij}'=R_{ip}R_{jq}\sigma_{pq}$.
    So $\sigma$ is a tensor of rank $2$.
    This is an example of something called the quotient theorem, which will be proved at the end of the course.
\end{example}
\begin{example}[Non-example]
    Not every array of numbers is a tensor.
    For example, in some given basis $\{\underline{e_i}\}$ we define an array
    $$(a_{ij})=\begin{pmatrix}
        1&2&3\\
        4&5&6\\
        7&8&\pi
    \end{pmatrix}$$
    and $a_{ij}=0$ in any other choice of basis, then $a_{ij}$ is not the component of a second rank tensor.
\end{example}
\begin{definition}
    If $a,b$ are rank-$n$ tensors with components $a_{i_1\cdots i_n},b_{i_1\cdots i_n}$, then the object $a+b$ by $(a+b)_{i_1\cdots i_n}=a_{i_1\cdots i_n}+b_{i_1\cdots i_n}$ is also a tensor of rank $n$.
    If $\alpha$ is a scalar, then we can define the tensor $\alpha a$ by $(\alpha a)_{i_1\cdots i_n}=\alpha a_{i_1\cdots i_n}$.
\end{definition}
\begin{definition}
    If $U$ is a tensor of rank $n$ and $V$ a tensor of rank $m$, then their tensor product $U\otimes V$ is a tensor of rank $m+n$ defined by
    $$(U\otimes V)_{i_1\cdots i_nj_1\cdots j_m}=U_{i_1\cdots i_n}V_{j_1\cdots j_m}$$
\end{definition}
\begin{definition}
    Suppose $n\ge 2$ and $T$ is a tensor of rank $n$, we can define a new tensor of rank $n-2$ by contraction on two indices (i.e. summing over two chosen indices).
\end{definition}
It is easy to check that these are indeed all tensors.
We say $T_{i_1\cdots i_n}$ is symmetric in $i_1,i_2$ if $T_{i_1i_2\cdots i_n}=T_{i_2i_1\cdots i_n}$.
This is obviously well-behaved.
Note that we can generalize it to symmetries in any pair of indices.
We say it is antisymmetric in $i_1,i_2$ if $T_{i_1i_2\cdots i_n}=-T_{i_2i_1\cdots i_n}$.
We say it is totally symmetric if it is symmetric in each pair of indices, and totally antisymmetric if it is antisymmetric in any two indices.
\begin{example}
    Both $\delta_{ij}$ and $a_ia_ja_k$ are totally symmetric tensors.
    Also $\epsilon_{ijk}$ is totally antisymmetric.
    In fact, one can see immediately that the Levi-Civita $\epsilon$ is the only antisymmetric tensor of rank $3$ up to proportionality.
\end{example}
Also, there are no nonzero totally antisymmetric tensor of rank $n\ge 4$ in $\mathbb R^3$.
\subsection{Tensor Calculus}
We say $T_{i_1\cdots i_n}(\underline{x})$ is a tensor field of rank $n$ if for each $\underline{x_0}\in\mathbb R^3$, $T_{i_1\cdots i_n}(\underline{x_0})$ is a tensor of rank $n$.
Note that $x_i'=R_{ij}x_j$ when we transform to one orthonormal right-handed basis to the other.
Also $x_j=R_{kj}x_k'$.
By the chain rule, $\partial/\partial x_i'=(\partial x_j/\partial x_i')(\partial/\partial x_j)=R_{ij}\partial/\partial x_j$.
\begin{proposition}
    Suppose $T_{i_1\cdots i_n}(\underline{x})$ is a tensor field of rank $n$, then
    $$A_{j_1\cdots j_mi_1\cdots i_n}(\underline{x})=\frac{\partial}{\partial x_{j_1}}\cdots\frac{\partial}{\partial x_{j_m}}T_{i_1\cdots i_n}(\underline{x})$$
    is a tensor field of rank $m+n$.
\end{proposition}
\begin{proof}
    From definition and chain rule.
\end{proof}
\begin{example}
    1. If $\phi$ is a scalar field, then components of $\nabla\phi$ changes according to $[\nabla\phi]_i'=\partial\phi/\partial x_i'=R_{ij}\partial\phi/\partial x_j=R_{ij}[\nabla\phi]_j$, so $\nabla\phi$ is a rank $1$ tensor field (or vector field).\\
    2. If $\underline{v}$ is a vector field, then using the same trick we can see that $\nabla\cdot\underline{v}$ is a rank $0$ tensor (or scalar field).\\
    3. If $\underline{v}$ is a vector field, so is $\nabla\times\underline{v}$.
\end{example}
\begin{example}
    Recall the divergence theorem for vector fields:
    $$\int_V\nabla\cdot\underline{F}\,\mathrm dV=\int_{\partial V}\underline{F}\cdot\mathrm dS$$
    Equivalently (or not),
    $$\int_V\frac{\partial F_i}{\partial x_i}\,\mathrm dV=\int_{\partial V}v_in_i\,\mathrm dS$$
    Turns out we can do this on tensor fields as well, where we have
    $$\int_V\frac{\partial}{\partial x_{i_k}}T_{i_1\cdots i_n}\,\mathrm dV=\int_{\partial V}T_{i_1\cdots i_n}n_{i_k}\,\mathrm dS$$
    which follows from the case for vector fields on the field
    $$v_{i_k}=a_{i_1}b_{i_2}\cdots c_{i_n}T_{i_1\cdots i_k\cdots i_n}$$
\end{example}
\subsection{Tensors of Rank 2}
An arbitrary rank-$2$ tensor $T_{ij}$ can be written as
$$T_{ij}=\frac{1}{2}(T_{ij}+T_{ji})+\frac{1}{2}(T_{ij}-T_{ji})=S_{ij}+A_{ij}$$
So $S_{ij}$ is symmetric and $A_{ij}$ is antisymmetric.
Note that $S_{ij}$ only has $6$ independent components, and $A_{ij}$ has $3$ independent components.
This is all consistent since a rank $3$ tensor has $9=6+3$ independent components.
\begin{proposition}
    A rank $2$ tensor can be written as $T_{ij}=S_{ij}+\epsilon_{ijk}\omega_k$ where $S_{ij}$ is symmetric and $\omega_k=\epsilon_{kpq}T_{pq}/2$.
    Also, this decomposition is unique.
\end{proposition}
\begin{proof}
    Just expand by taking $S_{ij}=(T_{ij}+T_{ji})/2$ for existence.
    As for uniqueness, suppose $S_{ij}+\epsilon_{ijk}\omega_k=\tilde{S}_{ij}+\epsilon_{ijk}\tilde\omega_k$.
    But we can take the symmetric part of each sides to get $S_{ij}=\tilde{S}_{ij}$, hence $\omega_k=\tilde\omega_k$.
\end{proof}
\begin{example}
    Suppose each point $\underline{x}$ in an elastic body undergoes small displacement $\underline{u}(\underline{x})$, then consider two points, initially seperated by $\delta\underline{x}$, then after the displacement they are seperated by
    $$\underline{u}(\underline{x}+\delta\underline{x})+\underline{x}+\delta\underline{x}-\underline{u}(\underline{x})-\underline{x}=\delta\underline{x}+(\underline{u}(\underline{x}+\delta\underline{x})-\underline{u}(\underline{x}))$$
    So the change in seperation would be $\underline{\underline{x}+\delta\underline{x}}-\underline{u}(\underline{x})$.
    Now using Cartesian and suffix notation, we have $u_i(\underline{x}+\delta\underline{x})-u_i(\underline{x})=\delta x_j\partial u_i/\partial x_j+o(|\delta\underline{x}|)$
    We write $\partial u_i/\partial x_j=e_{ij}+\epsilon_{ijk}\omega_k$ where
    $$e_{ij}=\frac{1}{2}\left(\frac{\partial u_i}{\partial x_j}+\frac{\partial u_j}{\partial x_i}\right),\omega_k=\frac{1}{2}\epsilon_{kpq}\partial u_p/\partial x_q=-\frac{1}{2}[\nabla\times\underline{u}]_k$$
    $e_{ij}$ here is called the linear strain tensor.
    So we have
    $$\underline{u}(\underline{x}+\delta\underline{x})-\underline{u}(\underline{x})=e_{ij}\delta x_j+[\delta\underline{x}\times\underline{\omega}]_i+o(|\delta\underline{x}|)$$
    So $e_{ij}$ tells you how the material strains,
\end{example}
Suppose a body occupies a volume $V$ has density $\rho(\underline{x})$ and suppose each point is rotating with angular velocity $\underline{\omega}$ through the origin, then the velocity of the point $\underline{x}$ is $\underline{\omega}\times\underline{x}$.
Then the total angular momentum is
$$\underline{L}=\int_V\rho(\underline{x})(\underline{x}\times\underline{v})\,\mathrm dV=\int_V\rho(\underline{x})(\underline{x}\times(\underline{\omega}\times\underline{x}))\,\mathrm dV$$
Using a right-handed basis $\{\underline{e_i}\}$ of $\mathbb R^3$, we have
$$L_i=\int_{\mathcal V}\rho(\underline{x})(x_kx_k\omega_i-x_ix_j\omega_j)\,\mathrm dV=I_{ij}\omega_j,I_{ij}=\int_{\mathcal V}\rho(\underline{x})(x_kx_k\delta_{ij}-x_ix_j)\,\mathrm dV$$
where $\mathcal V=\{(x_1,x_2,x_3):\underline{x}=x_i\underline{e_i}\in V\}$.
If we change our basis to another $\{\underline{e_i'}\}$, then we have (with $x_i'=R_{ij}x_j$)
\begin{align*}
    I_{ij}'&=\int_{\mathcal V'}\rho(\underline{x})(x_k'x_k'\delta_{ij}-x_i'x_j')\,\mathrm dV\\
    &=R_{ip}R_{jq}\int_{\mathcal V}\rho(\underline{x})(x_kx_k\delta_{pq}-x_px_q)|J|\,\mathrm dV\\
    &=R_{ip}R_{jq}I_{pq}
\end{align*}
So $I_{ij}$ is really a tensor.
We call it the inertial tensor.
\begin{example}
    Consider an ellipsoid
    $$\frac{x_1^2}{a^2}+\frac{x_2^2}{b^2}+\frac{x_3^2}{c^2}=1$$
    with $\rho(\underline{x})\equiv\rho_0$.
    By symmetry, if $i\neq j$, then $I_{ij}=0$.
    Now
    $$I_{11}=\rho_0\int_Vx_2^2x_3^2\,\mathrm dV$$
    By using scaled spherical polars $x_1=ar\cos\phi\sin\theta,x_2=br\sin\phi\sin\theta,x_3=cr\cos\theta$, so $\mathrm dV=abcr^2\sin\theta\,\mathrm dr\,\mathrm d\theta\,\mathrm d\phi$, we have
    $$I_{11}=\int_0^{2\pi}\int_0^\pi\int_0^1 r^2(b^2\sin^2\phi\sin^2\theta+c^2\cos^2\theta)abcr^2\sin\theta\,\mathrm dr\,\mathrm d\theta\,\mathrm d\phi=\frac{M}{5}(b^2+c^2)$$
    So
    $$(I_{ij})=\frac{M}{5}\begin{pmatrix}
        b^2+c^2&0&0\\
        0&a^2+c^2&0\\
        0&0&a^2+b^2
    \end{pmatrix}$$
    If in particular $a=b=c$, then $I_{ij}\propto\delta_{ij}$.
\end{example}
\begin{proposition}
    If $T_{ij}$ is real and symmetric, then there exists choice of basis in which $T_{ij}=0$ whenever $i\neq j$.
\end{proposition}
\begin{proof}
    In Vectors \& Matrices.
\end{proof}
\subsection{Isotropic Tensors}
\begin{definition}
    Say $T_{i_1\cdots i_n}$ is isotropic if $T_{i_1\cdots i_n}'=T_{i_1\cdots i_n}$ when transforming from a basis to the other.
    That is, for any rotational $R$, we have
    $$T_{i_1\cdots i_n}=R_{i_1j_1}\cdots R_{i_nj_n}T_{j_1\cdots j_n}$$
\end{definition}
\begin{example}
    1. Scalars are isotropic.\\
    2. $\delta_{ij}$ is isotropic.\\
    3. $\epsilon_{ijk}$ is also isotropic.
\end{example}
It turns out that we can classify all isotropic tensors in $\mathbb R^3$, and we can generalise this to $\mathbb R^n$.
We state this in the proposition below, which we shall provide a partial proof.
\begin{proposition}
    In $\mathbb R^3$:\\
    1. All scalars are isotropic.\\
    2. There are no nonzero isotropic rank-$1$ tensors (vectors).\\
    3. Most general isotropic tensor of rank $2$ is $\alpha\delta_{ij}$ where $\alpha$ is a scalar.\\
    4. Most general isotropic tensor of rank $3$ is $\beta\epsilon_{ijk}$ where $\beta$ is a scalar.\\
    5. Most general isotropic tensor of rank $4$ is $\alpha\delta_{ij}\delta_{kl}+\beta\delta_{il}\delta_{jk}+\gamma\delta_{ik}\delta_{jl}$ where $\alpha,\beta,\gamma$ are scalars.\\
    6. Tensors of higher rank is a linear combination of $\epsilon$'s and $\delta$'s, e.g. $\delta_{ij}\epsilon_{pqr}$ is an isotropic rank $5$ tensor.
\end{proposition}
\begin{proof}
    1 is obvious.\\
    For 2, assume $v_i$ is an isotropic tensor of rank $1$, then $v_i=R_{ij}v_j$ for all choice of rotation $R$.
    If we choose
    $$(R_{ij})=\begin{pmatrix}
        -1&0&0\\
        0&-1&0\\
        0&0&1
    \end{pmatrix}$$
    then we immediately get $v_1=v_2=0$.
    Similarly $v_3=0$, so $v=0$.\\
    For 3, suppose $T_{ij}$ is isotropic, then $T_{ij}=R_{ip}R_{jq}T_{pq}$ for any rotation $R$.
    Choose
    $$(R_{ij})=\begin{pmatrix}
        0&1&0\\
        -1&0&0\\
        0&0&1
    \end{pmatrix}$$
    Then
    $$T_{23}=R_{2p}R_{3q}T_{pq}=R_{21}R_{33}T_{13}=-T_{13},T_{13}=R_{1p}R_{3q}T_{pq}=R_{12}R_{33}T_{23}=T_{23}$$
    so we conclude $T_{13}=T_{23}=0$.
    Now $T_{11}=R_{1p}R_{1q}T_{pq}=T_{22}$, so $T_{11}=T_{22}$.
    Consider another rotation matrix
    $$(R_{ij})=\begin{pmatrix}
        1&0&0\\
        0&0&1\\
        0&-1&0
    \end{pmatrix}$$
    then
    $$T_{31}=R_{3p}R_{1q}T_{pq}=R_{32}R_{11}R_{21}=-R_{21},T_{21}=R_{2p}R_{1q}T_{pq}=R_{23}R_{11}T_{31}=T_{31}$$
    So $T_{31}=T_{21}=0$.
    Lastly
    $$T_{32}=R_{3p}R_{2q}T_{pq}=R_{32}R_{23}T_{23}=0,T_{12}=R_{1p}R_{2q}T_{pq}=R_{11}R_{23}T_{13}=0$$
    So in conclusion $T_{ij}=0$ whenever $i\neq j$
    Also $T_{33}=R_{3p}R_{3q}T_{pq}=R_{32}R_{32}T_{22}=T_{22}$, so $T_{11}=T_{22}=T_{33}$.
    Hence $T_{ij}=T_{11}\delta_{ij}$.
    Take $\alpha=T_{11}$ completes the proof.\\
    4,5,6 can be proved by similar idea.
\end{proof}
Consider tensors of the form
$$T_{i_1\cdots i_n}=\int_{V_R}f(r)x_{i_1}\cdots x_{i_n}\,\mathrm dV$$
where $r^2=x_px_p$ and $V_R$ is a ball of radius $R$ centered at $0$.
Then when we go to another frame of reference by $R$,
$$T_{i_1\cdots i_n}'=R_{i_1j_1}\cdots R_{i_nj_n}T_{j_1\cdots j_n}=R_{i_1j_1}\cdots R_{i_nj_n}\int_{V_R}f(r')x_{j_1}\cdots x_{j_n}\,\mathrm dV$$
where $r'^2=r^2$ since $R$ is a rotation.
Set $y_{i_k}=R_{i_kj_k}x_{j_k}$ and do a change of variable in this way, we get
$$T_{i_1\cdots i_n}'=\int_{V_R}f(r')y_{i_1}\cdots y_{i_n}\,\mathrm dV=T_{i_1\cdots i_n}$$
Since $V_R$ is indeendent of rotation.
So $T$ is indeed isotropic.
Taking $R\to\infty$ allows us to view it as an integration over $\mathbb R^3$.
\begin{example}
    Consider
    $$T_{ij}=\int_{\mathbb R^3}e^{-r^5}x_ix_j\,\mathrm dV=T_{11}\delta_{ij}$$
    by our classification theorem.
    Also $T_{ii}=4\pi/5$, so $T_{ij}=4\pi\delta_{ij}/15$.
\end{example}
\begin{example}
    The inertial tensor of a ball with radius $R>0$ and constant density $\rho_0$, so
    $$I_{ij}=\rho_0\int_{V_R}x_kx_k\delta_{ij}-x_kx_j\,\mathrm dV$$
    The right hand side is the sum of two isotropic tensor of rank $2$, so $I_{ij}=\alpha\delta_{ij}$.
    Contract on $i,j$ gives $\alpha=2MR^2/5$ where $M=\rho_0 4\pi R^3/3$.
\end{example}
\subsection{Multilinear Maps and Quotient Theorem}
Given some right-handed orthonormal basis, let $T_{ij}$ denote the components of rank $2$ tensor.
Define a bilinear map $t:\mathbb R^3\times\mathbb R^3\to\mathbb R$ by $t(\underline{a},\underline{b})=T_{ij}a_ib_j$, which one can note is independent of the basis we chose hence the map is well-defined.
Conversely, for a bilinear $t:\mathbb R^3\times\mathbb R^3\to\mathbb R$, and we choose a certain basis $\{\underline{e_i}\}$, then we can write $t(\underline{a},\underline{b})=a_ib_jt(\underline{e_i},\underline{e_j})$, so $T_{ij}=t(\underline{e_i},\underline{e_j})$ is a rank-$2$ tensor since  $t$ is bilinear.
This gives a one-to-one correspondence between bilinear maps and rank-$2$ tensors.
In particular, if a (bilinear) map $(\underline{a},\underline{b})\mapsto T_{ij}a_ib_j$ is well-defined, then $T_{ij}$ is naturally a tensor.\\
In general, we can correspondingly identify a rank-$n$ tensor in $\mathbb R^3$ by multilinear maps $(\mathbb R^3)^n\to\mathbb R$.
\begin{proposition}[Quotient Theorem]
    Given basis $\{\underline{e_i}\}$, let $T_{i_1\cdots i_nj_1\cdots j_m}$ be array of numbers such that $v_{i_1\cdots i_n}=T_{i_1\cdots i_nj_1\cdots j_m}u_{j_1\cdots j_m}$ is a tensor for any tensor $u$, then $T$ is a tensor.
\end{proposition}
\begin{proof}
    Take $u_{j_1\cdots j_m}=c^1_{j_1}\cdots c^m_{j_m}$, where $\underline{c^k}$ are vectors.
    So
    $$v_{i_1\cdots i_n}=T_{i_1\cdots i_nj_1\cdots j_m}c^1_{j_1}\cdots c^m_{j_m}$$
    is a tensor by hypothesis.
    Let $\underline{a^1},\ldots,\underline{a^n}$ be vectors, then we can contract $v$ by $v_{i_1\cdots i_n}a_{i_1}^1\cdots a_{i_n}^n$, which is a scalar that is independent of basis, so the map
    $$(\underline{a^1},\ldots,\underline{a^n},\underline{c^1},\ldots,\underline{c^n})\mapsto T_{i_1\cdots i_nj_1\cdots j_m}a_{i_1}^1\cdots a_{i_n}^nc_{j_1}^1\cdots c_{j_m}^m$$
    is independent of choice of coordinates, so $T$ is a tensor.
\end{proof}
\begin{example}
    Recall linear strain tensor $e_{ij}=(\partial u_i/\partial x_j+\partial u_j/\partial x_i)/2$ where $\underline{u}(\underline{x})$ is the displacement of the particle at $\underline{x}$ of a body undergoing deformation.
    Experimental evidence suggests a linear relationship between stresses (internal forces) and strain.
    We measure stress using stress tensor $\sigma_{ij}$.
    There are $3^4=81$ numbers $c_{ijkl}$ such that $\sigma_{ij}=c_{ijkl}e_{kl}$.
    This is just a generalization of Hookes' Law to higher dimensions.
    Now if we know that $c_{ijkl}=c_{ijlk}$ we know that $c_{ijkl}$ is a tensor from the quotient theorem.
    In this case we call this array $c_{ijkl}$ is the stiffness tensor.
    For isotropic material, we know that $c_{ijkl}=\alpha\delta_{ij}\delta_{kl}+\beta\delta_{ik}\delta_{jl}+\gamma\delta_{il}\delta_{jk}$, so $\sigma_{ij}=\alpha e_{kk}\delta_{ij}+\beta e_{ij}+\gamma e_{ji}=\alpha e_{kk}\delta_{ij}+2\mu e_{ij}$ where $\mu=\beta+\gamma$.
    We can invert for $e_{ij}$ by contract on indices $i,j$, so $\sigma_{kk}=(3\alpha+2\mu)e_{kk}$, so $e_{kk}=\sigma_{kk}/(3\alpha+2\mu)$.
    So $2\mu e_{ij}=\sigma_{ij}-\alpha\sigma_{kk}\delta_{ij}/(3\alpha+2\mu)$.
\end{example}