diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/2DimGravity.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/2DimGravity.png new file mode 100644 index 000000000..333400f14 Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/2DimGravity.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/2DimHOVV.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/2DimHOVV.png new file mode 100644 index 000000000..fe7012a6c Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/2DimHOVV.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/BlockEulerCromer.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/BlockEulerCromer.png new file mode 100644 index 000000000..ef4359856 Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/BlockEulerCromer.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/EarthSunEuler.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/EarthSunEuler.png new file mode 100644 index 000000000..995224674 Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/EarthSunEuler.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/EarthSunVV.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/EarthSunVV.png new file mode 100644 index 000000000..38ebd1119 Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/EarthSunVV.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/EulerIntegration.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/EulerIntegration.png new file mode 100644 index 000000000..5970c662a Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/EulerIntegration.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/FallingBaseball.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/FallingBaseball.png new file mode 100644 index 000000000..85609e5f1 Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/FallingBaseball.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/ForcedBlockEulerCromer.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/ForcedBlockEulerCromer.png new file mode 100644 index 000000000..ae3970536 Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/ForcedBlockEulerCromer.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/Phasespace.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/Phasespace.png new file mode 100644 index 000000000..b40ed4c2c Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/Phasespace.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/RadialGVV.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/RadialGVV.png new file mode 100644 index 000000000..17714bf44 Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/RadialGVV.png differ diff --git a/doc/src/LectureNotes/testbook/Results/FigureFiles/RadialHOVV.png b/doc/src/LectureNotes/testbook/Results/FigureFiles/RadialHOVV.png new file mode 100644 index 000000000..511124a9f Binary files /dev/null and b/doc/src/LectureNotes/testbook/Results/FigureFiles/RadialHOVV.png differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/chapter1.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter1.doctree new file mode 100644 index 000000000..f6aed626f Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter1.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/chapter2.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter2.doctree new file mode 100644 index 000000000..f6c9db0c0 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter2.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/chapter3.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter3.doctree new file mode 100644 index 000000000..2424a001c Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter3.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/chapter4.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter4.doctree new file mode 100644 index 000000000..60ac77144 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter4.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/chapter5.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter5.doctree new file mode 100644 index 000000000..0239874a7 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter5.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/chapter6.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter6.doctree new file mode 100644 index 000000000..6ea3af819 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter6.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/chapter7.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter7.doctree new file mode 100644 index 000000000..bddd055b5 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/chapter7.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/content.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/content.doctree new file mode 100644 index 000000000..311766860 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/content.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/environment.pickle b/doc/src/LectureNotes/testbook/_build/.doctrees/environment.pickle new file mode 100644 index 000000000..0e823cde0 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/environment.pickle differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/glue_cache.json b/doc/src/LectureNotes/testbook/_build/.doctrees/glue_cache.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/.doctrees/glue_cache.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/intro.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/intro.doctree new file mode 100644 index 000000000..c55a462f1 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/intro.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/CONDUCT.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/CONDUCT.doctree new file mode 100644 index 000000000..ea5837757 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/CONDUCT.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/CONTRIBUTING.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/CONTRIBUTING.doctree new file mode 100644 index 000000000..0e1d28d73 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/CONTRIBUTING.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/README.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/README.doctree new file mode 100644 index 000000000..b60e4ad13 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/README.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/content.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/content.doctree new file mode 100644 index 000000000..a6a5fa1b9 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/content.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/intro.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/intro.doctree new file mode 100644 index 000000000..debf892cf Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/intro.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/markdown.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/markdown.doctree new file mode 100644 index 000000000..3d6ebc8b8 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/markdown.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/notebooks.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/notebooks.doctree new file mode 100644 index 000000000..dbbc12acf Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/lecturenotes/lecturenotes/notebooks.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/markdown.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/markdown.doctree new file mode 100644 index 000000000..56dd6080f Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/markdown.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/.doctrees/notebooks.doctree b/doc/src/LectureNotes/testbook/_build/.doctrees/notebooks.doctree new file mode 100644 index 000000000..a72eafcd9 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/.doctrees/notebooks.doctree differ diff --git a/doc/src/LectureNotes/testbook/_build/html/.buildinfo b/doc/src/LectureNotes/testbook/_build/html/.buildinfo new file mode 100644 index 000000000..0e8fbe757 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/.buildinfo @@ -0,0 +1,4 @@ +# Sphinx build info version 1 +# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. +config: 1323fce32d20fd5823a85710237f4b7c +tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_125_1.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_125_1.png new file mode 100644 index 000000000..1408e1b74 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_125_1.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_29_1.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_29_1.png new file mode 100644 index 000000000..ad49b2519 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_29_1.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_3_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_3_0.png new file mode 100644 index 000000000..eb6c5ae72 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter1_3_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter2_121_1.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter2_121_1.png new file mode 100644 index 000000000..1408e1b74 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter2_121_1.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter2_25_1.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter2_25_1.png new file mode 100644 index 000000000..ad49b2519 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter2_25_1.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter4_108_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter4_108_0.png new file mode 100644 index 000000000..fa2c7e328 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter4_108_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter4_138_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter4_138_0.png new file mode 100644 index 000000000..42dda929f Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter4_138_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter5_110_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter5_110_0.png new file mode 100644 index 000000000..f8c4c2a3e Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter5_110_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter5_49_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter5_49_0.png new file mode 100644 index 000000000..f88629313 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter5_49_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_37_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_37_0.png new file mode 100644 index 000000000..25f17c671 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_37_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_45_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_45_0.png new file mode 100644 index 000000000..c69d5decf Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_45_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_47_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_47_0.png new file mode 100644 index 000000000..41fbb898d Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_47_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_51_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_51_0.png new file mode 100644 index 000000000..8d0e64f65 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_51_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_62_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_62_0.png new file mode 100644 index 000000000..eab36649e Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_62_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_66_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_66_0.png new file mode 100644 index 000000000..3128d8856 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_66_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_74_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_74_0.png new file mode 100644 index 000000000..1a2535d84 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_74_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_76_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_76_0.png new file mode 100644 index 000000000..cfbcb68f0 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/chapter6_76_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/notebooks_2_0.png b/doc/src/LectureNotes/testbook/_build/html/_images/notebooks_2_0.png new file mode 100644 index 000000000..ab6666ca3 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/notebooks_2_0.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_images/notebooks_2_01.png b/doc/src/LectureNotes/testbook/_build/html/_images/notebooks_2_01.png new file mode 100644 index 000000000..ab6666ca3 Binary files /dev/null and b/doc/src/LectureNotes/testbook/_build/html/_images/notebooks_2_01.png differ diff --git a/doc/src/LectureNotes/testbook/_build/html/_panels_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css b/doc/src/LectureNotes/testbook/_build/html/_panels_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css new file mode 100644 index 000000000..fc14abc85 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_panels_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css @@ -0,0 +1 @@ +details.dropdown .summary-title{padding-right:3em !important;-moz-user-select:none;-ms-user-select:none;-webkit-user-select:none;user-select:none}details.dropdown:hover{cursor:pointer}details.dropdown .summary-content{cursor:default}details.dropdown summary{list-style:none;padding:1em}details.dropdown summary .octicon.no-title{vertical-align:middle}details.dropdown[open] summary .octicon.no-title{visibility:hidden}details.dropdown summary::-webkit-details-marker{display:none}details.dropdown summary:focus{outline:none}details.dropdown summary:hover .summary-up svg,details.dropdown summary:hover .summary-down svg{opacity:1}details.dropdown .summary-up svg,details.dropdown .summary-down svg{display:block;opacity:.6}details.dropdown .summary-up,details.dropdown .summary-down{pointer-events:none;position:absolute;right:1em;top:.75em}details.dropdown[open] .summary-down{visibility:hidden}details.dropdown:not([open]) .summary-up{visibility:hidden}details.dropdown.fade-in[open] summary~*{-moz-animation:panels-fade-in .5s ease-in-out;-webkit-animation:panels-fade-in .5s ease-in-out;animation:panels-fade-in .5s ease-in-out}details.dropdown.fade-in-slide-down[open] summary~*{-moz-animation:panels-fade-in .5s ease-in-out, panels-slide-down .5s ease-in-out;-webkit-animation:panels-fade-in .5s ease-in-out, panels-slide-down .5s ease-in-out;animation:panels-fade-in .5s ease-in-out, panels-slide-down .5s ease-in-out}@keyframes panels-fade-in{0%{opacity:0}100%{opacity:1}}@keyframes panels-slide-down{0%{transform:translate(0, -10px)}100%{transform:translate(0, 0)}}.octicon{display:inline-block;fill:currentColor;vertical-align:text-top}.tabbed-content{box-shadow:0 -.0625rem var(--tabs-color-overline),0 .0625rem var(--tabs-color-underline);display:none;order:99;padding-bottom:.75rem;padding-top:.75rem;width:100%}.tabbed-content>:first-child{margin-top:0 !important}.tabbed-content>:last-child{margin-bottom:0 !important}.tabbed-content>.tabbed-set{margin:0}.tabbed-set{border-radius:.125rem;display:flex;flex-wrap:wrap;margin:1em 0;position:relative}.tabbed-set>input{opacity:0;position:absolute}.tabbed-set>input:checked+label{border-color:var(--tabs-color-label-active);color:var(--tabs-color-label-active)}.tabbed-set>input:checked+label+.tabbed-content{display:block}.tabbed-set>input:focus+label{outline-style:auto}.tabbed-set>input:not(.focus-visible)+label{outline:none;-webkit-tap-highlight-color:transparent}.tabbed-set>label{border-bottom:.125rem solid transparent;color:var(--tabs-color-label-inactive);cursor:pointer;font-size:var(--tabs-size-label);font-weight:700;padding:1em 1.25em .5em;transition:color 250ms;width:auto;z-index:1}html .tabbed-set>label:hover{color:var(--tabs-color-label-active)} diff --git a/doc/src/LectureNotes/testbook/_build/html/_panels_static/panels-variables.06eb56fa6e07937060861dad626602ad.css b/doc/src/LectureNotes/testbook/_build/html/_panels_static/panels-variables.06eb56fa6e07937060861dad626602ad.css new file mode 100644 index 000000000..adc616622 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_panels_static/panels-variables.06eb56fa6e07937060861dad626602ad.css @@ -0,0 +1,7 @@ +:root { +--tabs-color-label-active: hsla(231, 99%, 66%, 1); +--tabs-color-label-inactive: rgba(178, 206, 245, 0.62); +--tabs-color-overline: rgb(207, 236, 238); +--tabs-color-underline: rgb(207, 236, 238); +--tabs-size-label: 1rem; +} \ No newline at end of file diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/chapter1.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter1.ipynb new file mode 100644 index 000000000..457efd109 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter1.ipynb @@ -0,0 +1,224 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Introduction\n", + "\n", + "Classical mechanics is a topic which has been taught intensively over\n", + "several centuries. It is, with its many variants and ways of\n", + "presenting the educational material, normally the first **real** physics\n", + "course many of us meet and it lays the foundation for further physics\n", + "studies. Many of the equations and ways of reasoning about the\n", + "underlying laws of motion and pertinent forces, shape our approaches and understanding\n", + "of the scientific method and discourse, as well as the way we develop our insights\n", + "and deeper understanding about physical systems. \n", + "\n", + "There is a wealth of\n", + "well-tested (from both a physics point of view and a pedagogical\n", + "standpoint) exercises and problems which can be solved\n", + "analytically. However, many of these problems represent idealized and\n", + "less realistic situations. The large majority of these problems are\n", + "solved by paper and pencil and are traditionally aimed\n", + "at what we normally refer to as continuous models from which we may find an analytical solution. As a consequence,\n", + "when teaching mechanics, it implies that we can seldomly venture beyond an idealized case\n", + "in order to develop our understandings and insights about the\n", + "underlying forces and laws of motion.\n", + "\n", + "\n", + "On the other hand, numerical algorithms call for approximate discrete\n", + "models and much of the development of methods for continuous models\n", + "are nowadays being replaced by methods for discrete models in science and\n", + "industry, simply because **much larger classes of problems can be addressed** with discrete models, often by simpler and more\n", + "generic methodologies.\n", + "\n", + "As we will see below, when properly scaling the equations at hand,\n", + "discrete models open up for more advanced abstractions and the possibility to\n", + "study real life systems, with the added bonus that we can explore and\n", + "deepen our basic understanding of various physical systems\n", + "\n", + "Analytical solutions are as important as before. In addition, such\n", + "solutions provide us with invaluable benchmarks and tests for our\n", + "discrete models. Such benchmarks, as we will see below, allow us \n", + "to discuss possible sources of errors and their behaviors. And\n", + "finally, since most of our models are based on various algorithms from\n", + "numerical mathematics, we have a unique oppotunity to gain a deeper\n", + "understanding of the mathematical approaches we are using.\n", + "\n", + "\n", + "\n", + "With computing and data science as important elements in essentially\n", + "all aspects of a modern society, we could then try to define Computing as\n", + "**solving scientific problems using all possible tools, including\n", + "symbolic computing, computers and numerical algorithms, and analytical\n", + "paper and pencil solutions**. \n", + "Computing provides us with the tools to develope our own understanding of the scientific method by enhancing algorithmic thinking.\n", + "\n", + "\n", + "The way we will teach this course reflects\n", + "this definition of computing. The course contains both classical paper\n", + "and pencil exercises as well as computational projects and exercises. The\n", + "hope is that this will allow you to explore the physics of systems\n", + "governed by the degrees of freedom of classical mechanics at a deeper\n", + "level, and that these insights about the scientific method will help\n", + "you to develop a better understanding of how the underlying forces and\n", + "equations of motion and how they impact a given system. Furthermore, by introducing various numerical methods\n", + "via computational projects and exercises, we aim at developing your competences and skills about these topics.\n", + "\n", + "\n", + "These competences will enable you to\n", + "\n", + "* understand how algorithms are used to solve mathematical problems,\n", + "\n", + "* derive, verify, and implement algorithms,\n", + "\n", + "* understand what can go wrong with algorithms,\n", + "\n", + "* use these algorithms to construct reproducible scientific outcomes and to engage in science in ethical ways, and\n", + "\n", + "* think algorithmically for the purposes of gaining deeper insights about scientific problems.\n", + "\n", + "All these elements are central for maturing and gaining a better understanding of the modern scientific process *per se*.\n", + "\n", + "The power of the scientific method lies in identifying a given problem\n", + "as a special case of an abstract class of problems, identifying\n", + "general solution methods for this class of problems, and applying a\n", + "general method to the specific problem (applying means, in the case of\n", + "computing, calculations by pen and paper, symbolic computing, or\n", + "numerical computing by ready-made and/or self-written software). This\n", + "generic view on problems and methods is particularly important for\n", + "understanding how to apply available, generic software to solve a\n", + "particular problem.\n", + "\n", + "*However, verification of algorithms and understanding their limitations requires much of the classical knowledge about continuous models.*\n", + "\n", + "\n", + "\n", + "## A well-known examples to illustrate many of the above concepts\n", + "\n", + "Before we venture into a reminder on Python and mechanics relevant applications, let us briefly outline some of the\n", + "abovementioned topics using an example many of you may have seen before in for example CMSE201. \n", + "A simple algorithm for integration is the Trapezoidal rule. \n", + "Integration of a function $f(x)$ by the Trapezoidal Rule is given by following algorithm for an interval $x \\in [a,b]$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^b(f(x) dx = \\frac{1}{2}\\left [f(a)+2f(a+h)+\\dots+2f(b-h)+f(b)\\right] +O(h^2),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $h$ is the so-called stepsize defined by the number of integration points $N$ as $h=(b-a)/(n)$.\n", + "Python offers an extremely versatile programming environment, allowing for\n", + "the inclusion of analytical studies in a numerical program. Here we show an\n", + "example code with the **trapezoidal rule**. We use also **SymPy** to evaluate the exact value of the integral and compute the absolute error\n", + "with respect to the numerically evaluated one of the integral\n", + "$\\int_0^1 dx x^2 = 1/3$.\n", + "The following code for the trapezoidal rule allows you to plot the relative error by comparing with the exact result. By increasing to $10^8$ points one arrives at a region where numerical errors start to accumulate." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "\n", + "from math import log10\n", + "import numpy as np\n", + "from sympy import Symbol, integrate\n", + "import matplotlib.pyplot as plt\n", + "# function for the trapezoidal rule\n", + "def Trapez(a,b,f,n):\n", + " h = (b-a)/float(n)\n", + " s = 0\n", + " x = a\n", + " for i in range(1,n,1):\n", + " x = x+h\n", + " s = s+ f(x)\n", + " s = 0.5*(f(a)+f(b)) +s\n", + " return h*s\n", + "# function to compute pi\n", + "def function(x):\n", + " return x*x\n", + "# define integration limits\n", + "a = 0.0; b = 1.0;\n", + "# find result from sympy\n", + "# define x as a symbol to be used by sympy\n", + "x = Symbol('x')\n", + "exact = integrate(function(x), (x, a, b))\n", + "# set up the arrays for plotting the relative error\n", + "n = np.zeros(9); y = np.zeros(9);\n", + "# find the relative error as function of integration points\n", + "for i in range(1, 8, 1):\n", + " npts = 10**i\n", + " result = Trapez(a,b,function,npts)\n", + " RelativeError = abs((exact-result)/exact)\n", + " n[i] = log10(npts); y[i] = log10(RelativeError);\n", + "plt.plot(n,y, 'ro')\n", + "plt.xlabel('n')\n", + "plt.ylabel('Relative error')\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This example shows the potential of combining numerical algorithms with symbolic calculations, allowing us to \n", + "\n", + "* Validate and verify their algorithms. \n", + "\n", + "* Including concepts like unit testing, one has the possibility to test and test several or all parts of the code.\n", + "\n", + "* Validation and verification are then included *naturally* and one can develop a better attitude to what is meant with an ethically sound scientific approach.\n", + "\n", + "* The above example allows the student to also test the mathematical error of the algorithm for the trapezoidal rule by changing the number of integration points. The students get **trained from day one to think error analysis**. \n", + "\n", + "* With a Jupyter notebook you can keep exploring similar examples and turn them in as your own notebooks. \n", + "\n", + "In this process we can easily bake in\n", + "1. How to structure a code in terms of functions\n", + "\n", + "2. How to make a module\n", + "\n", + "3. How to read input data flexibly from the command line\n", + "\n", + "4. How to create graphical/web user interfaces\n", + "\n", + "5. How to write unit tests (test functions or doctests)\n", + "\n", + "6. How to refactor code in terms of classes (instead of functions only)\n", + "\n", + "7. How to conduct and automate large-scale numerical experiments\n", + "\n", + "8. How to write scientific reports in various formats (LaTeX, HTML)\n", + "\n", + "The conventions and techniques outlined here will save you a lot of time when you incrementally extend software over time from simpler to more complicated problems. In particular, you will benefit from many good habits:\n", + "1. New code is added in a modular fashion to a library (modules)\n", + "\n", + "2. Programs are run through convenient user interfaces\n", + "\n", + "3. It takes one quick command to let all your code undergo heavy testing \n", + "\n", + "4. Tedious manual work with running programs is automated,\n", + "\n", + "5. Your scientific investigations are reproducible, scientific reports with top quality typesetting are produced both for paper and electronic devices." + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/chapter2.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter2.ipynb new file mode 100644 index 000000000..6eeb8a756 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter2.ipynb @@ -0,0 +1,2207 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Space, Time, Motion, Reference Frames and Reminder on vectors and other mathematical quantities\n", + "\n", + "Our studies will start with the motion of different types of objects\n", + "such as a falling ball, a runner, a bicycle etc etc. It means that an\n", + "object's position in space varies with time.\n", + "In order to study such systems we need to define\n", + "* choice of origin\n", + "\n", + "* choice of the direction of the axes\n", + "\n", + "* choice of positive direction (left-handed or right-handed system of reference)\n", + "\n", + "* choice of units and dimensions\n", + "\n", + "These choices lead to some important questions such as\n", + "\n", + "* is the physics of a system independent of the origin of the axes?\n", + "\n", + "* is the physics independent of the directions of the axes, that is are there privileged axes?\n", + "\n", + "* is the physics independent of the orientation of system?\n", + "\n", + "* is the physics independent of the scale of the length?\n", + "\n", + "### Dimension, units and labels\n", + "\n", + "Throughout this course we will use the standardized SI units. The standard unit for length is thus one meter 1m, for mass\n", + "one kilogram 1kg, for time one second 1s, for force one Newton 1kgm/s$^2$ and for energy 1 Joule 1kgm$^2$s$^{-2}$.\n", + "\n", + "We will use the following notations for various variables (vectors are always boldfaced in these lecture notes):\n", + "* position $\\boldsymbol{r}$, in one dimention we will normally just use $x$,\n", + "\n", + "* mass $m$,\n", + "\n", + "* time $t$,\n", + "\n", + "* velocity $\\boldsymbol{v}$ or just $v$ in one dimension,\n", + "\n", + "* acceleration $\\boldsymbol{a}$ or just $a$ in one dimension,\n", + "\n", + "* momentum $\\boldsymbol{p}$ or just $p$ in one dimension,\n", + "\n", + "* kinetic energy $K$,\n", + "\n", + "* potential energy $V$ and\n", + "\n", + "* frequency $\\omega$.\n", + "\n", + "More variables will be defined as we need them.\n", + "\n", + "It is also important to keep track of dimensionalities. Don't mix this up with a chosen unit for a given variable. We mark the dimensionality in these lectures as $[a]$, where $a$ is the quantity we are interested in. Thus\n", + "\n", + "* $[\\boldsymbol{r}]=$ length\n", + "\n", + "* $[m]=$ mass\n", + "\n", + "* $[K]=$ energy\n", + "\n", + "* $[t]=$ time\n", + "\n", + "* $[\\boldsymbol{v}]=$ length over time\n", + "\n", + "* $[\\boldsymbol{a}]=$ length over time squared\n", + "\n", + "* $[\\boldsymbol{p}]=$ mass times length over time\n", + "\n", + "* $[\\omega]=$ 1/time\n", + "\n", + "## Elements of Vector Algebra\n", + "\n", + "**Note**: This section is under revision\n", + "\n", + "In these lectures we will use boldfaced lower-case letters to label a vector. A vector $\\boldsymbol{a}$ in three dimensions is thus defined as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{a} =(a_x,a_y, a_z),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and using the unit vectors in a cartesian system we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{a} = a_x\\boldsymbol{e}_x+a_y\\boldsymbol{e}_y+a_z\\boldsymbol{e}_z,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where the unit vectors have magnitude $\\vert\\boldsymbol{e}_i\\vert = 1$ with $i=x,y,z$.\n", + "\n", + "Using the fact that multiplication of reals is distributive we can show that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{a}(\\boldsymbol{b}+\\boldsymbol{c})=\\boldsymbol{a}\\boldsymbol{b}+\\boldsymbol{a}\\boldsymbol{c},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Similarly we can also show that (using product rule for differentiating reals)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d}{dt}(\\boldsymbol{a}\\boldsymbol{b})=\\boldsymbol{a}\\frac{d\\boldsymbol{b}}{dt}+\\boldsymbol{b}\\frac{d\\boldsymbol{a}}{dt}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can repeat these operations for the cross products and show that they are distribuitive" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{a}\\times(\\boldsymbol{b}+\\boldsymbol{c})=\\boldsymbol{a}\\times\\boldsymbol{b}+\\boldsymbol{a}\\times\\boldsymbol{c}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have also that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d}{dt}(\\boldsymbol{a}\\times\\boldsymbol{b})=\\boldsymbol{a}\\times\\frac{d\\boldsymbol{b}}{dt}+\\boldsymbol{b}\\times\\frac{d\\boldsymbol{a}}{dt}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The rotation of a three-dimensional vector $\\boldsymbol{a}=(a_x,a_y,a_z)$ in the $xy$ plane around an angle $\\phi$ results in a new vector $\\boldsymbol{b}=(b_x,b_y,b_z)$. This operation can be expressed in terms of linear algebra as a matrix (the rotation matrix) multiplied with a vector. We can write this as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{bmatrix} b_x \\\\ b_y \\\\ b_z \\end{bmatrix} = \\begin{bmatrix} \\cos{\\phi} & \\sin{\\phi} & 0 \\\\ -\\sin{\\phi} & \\cos{\\phi} & 0 \\\\ 0 & 0 & 1\\end{bmatrix}\\begin{bmatrix} a_x \\\\ a_y \\\\ a_z \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can write this in a more compact form as $\\boldsymbol{b} = \\boldsymbol{R}\\boldsymbol{a}$, where the rotation matrix is defined as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{R} = \\begin{bmatrix} \\cos{\\phi} & \\sin{\\phi} & 0 \\\\ -\\sin{\\phi} & \\cos{\\phi} & 0 \\\\ 0 & 0 & 1\\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Falling baseball in one dimension\n", + "\n", + "We anticipate the mathematical model to come and assume that we have a\n", + "model for the motion of a falling baseball without air resistance.\n", + "Our system (the baseball) is at an initial height $y_0$ (which we will\n", + "specify in the program below) at the initial time $t_0=0$. In our program example here we will plot the position in steps of $\\Delta t$ up to a final time $t_f$. \n", + "The mathematical formula for the position $y(t)$ as function of time $t$ is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t) = y_0-\\frac{1}{2}gt^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $g=9.80665=0.980655\\times 10^1$m/s$^2$ is a constant representing the standard acceleration due to gravity.\n", + "We have here adopted the conventional standard value. This does not take into account other effects, such as buoyancy or drag.\n", + "Furthermore, we stop when the ball hits the ground, which takes place at" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t) = 0= y_0-\\frac{1}{2}gt^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which gives us a final time $t_f=\\sqrt{2y_0/g}$. \n", + "\n", + "As of now we simply assume that we know the formula for the falling object. Afterwards, we will derive it.\n", + "\n", + "\n", + "## Our Python Encounter\n", + "\n", + "We start with preparing folders for storing our calculations, figures and if needed, specific data files we use as input or output files." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "\n", + "# Common imports\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "\n", + "# Where to save the figures and data files\n", + "PROJECT_ROOT_DIR = \"Results\"\n", + "FIGURE_ID = \"Results/FigureFiles\"\n", + "DATA_ID = \"DataFiles/\"\n", + "\n", + "if not os.path.exists(PROJECT_ROOT_DIR):\n", + " os.mkdir(PROJECT_ROOT_DIR)\n", + "\n", + "if not os.path.exists(FIGURE_ID):\n", + " os.makedirs(FIGURE_ID)\n", + "\n", + "if not os.path.exists(DATA_ID):\n", + " os.makedirs(DATA_ID)\n", + "\n", + "def image_path(fig_id):\n", + " return os.path.join(FIGURE_ID, fig_id)\n", + "\n", + "def data_path(dat_id):\n", + " return os.path.join(DATA_ID, dat_id)\n", + "\n", + "def save_fig(fig_id):\n", + " plt.savefig(image_path(fig_id) + \".png\", format='png')\n", + "\n", + "#in case we have an input file we wish to read in\n", + "#infile = open(data_path(\"MassEval2016.dat\"),'r')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You could also define a function for making our plots. You\n", + "can obviously avoid this and simply set up various **matplotlib**\n", + "commands every time you need them. You may however find it convenient\n", + "to collect all such commands in one function and simply call this\n", + "function." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from pylab import plt, mpl\n", + "plt.style.use('seaborn')\n", + "mpl.rcParams['font.family'] = 'serif'\n", + "\n", + "def MakePlot(x,y, styles, labels, axlabels):\n", + " plt.figure(figsize=(10,6))\n", + " for i in range(len(x)):\n", + " plt.plot(x[i], y[i], styles[i], label = labels[i])\n", + " plt.xlabel(axlabels[0])\n", + " plt.ylabel(axlabels[1])\n", + " plt.legend(loc=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thereafter we start setting up the code for the falling object." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "import matplotlib.patches as mpatches\n", + "\n", + "g = 9.80655 #m/s^2\n", + "y_0 = 10.0 # initial position in meters\n", + "DeltaT = 0.1 # time step\n", + "# final time when y = 0, t = sqrt(2*10/g)\n", + "tfinal = np.sqrt(2.0*y_0/g)\n", + "#set up arrays \n", + "t = np.arange(0,tfinal,DeltaT)\n", + "y =y_0 -g*.5*t**2\n", + "# Then make a nice printout in table form using Pandas\n", + "import pandas as pd\n", + "from IPython.display import display\n", + "data = {'t[s]': t,\n", + " 'y[m]': y\n", + " }\n", + "RawData = pd.DataFrame(data)\n", + "display(RawData)\n", + "plt.style.use('ggplot')\n", + "plt.figure(figsize=(8,8))\n", + "plt.scatter(t, y, color = 'b')\n", + "blue_patch = mpatches.Patch(color = 'b', label = 'Height y as function of time t')\n", + "plt.legend(handles=[blue_patch])\n", + "plt.xlabel(\"t[s]\")\n", + "plt.ylabel(\"y[m]\")\n", + "save_fig(\"FallingBaseball\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here we used **pandas** (see below) to systemize the output of the position as function of time.\n", + "\n", + "\n", + "\n", + "## Average quantities\n", + "We define now the average velocity as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\overline{v}(t) = \\frac{y(t+\\Delta t)-y(t)}{\\Delta t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the code we have set the time step $\\Delta t$ to a given value. We could define it in terms of the number of points $n$ as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\Delta t = \\frac{t_{\\mathrm{final}-}t_{\\mathrm{initial}}}{n+1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since we have discretized the variables, we introduce the counter $i$ and let $y(t)\\rightarrow y(t_i)=y_i$ and $t\\rightarrow t_i$\n", + "with $i=0,1,\\dots, n$. This gives us the following shorthand notations that we will use for the rest of this course. We define" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y_i = y(t_i),\\hspace{0.2cm} i=0,1,2,\\dots,n.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This applies to other variables which depend on say time. Examples are the velocities, accelerations, momenta etc.\n", + "Furthermore we use the shorthand" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y_{i\\pm 1} = y(t_i\\pm \\Delta t),\\hspace{0.12cm} i=0,1,2,\\dots,n.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Compact equations\n", + "We can then rewrite in a more compact form the average velocity as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\overline{v}_i = \\frac{y_{i+1}-y_{i}}{\\Delta t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The velocity is defined as the change in position per unit time.\n", + "In the limit $\\Delta t \\rightarrow 0$ this defines the instantaneous velocity, which is nothing but the slope of the position at a time $t$.\n", + "We have thus" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t) = \\frac{dy}{dt}=\\lim_{\\Delta t \\rightarrow 0}\\frac{y(t+\\Delta t)-y(t)}{\\Delta t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Similarly, we can define the average acceleration as the change in velocity per unit time as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\overline{a}_i = \\frac{v_{i+1}-v_{i}}{\\Delta t},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "resulting in the instantaneous acceleration" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "a(t) = \\frac{dv}{dt}=\\lim_{\\Delta t\\rightarrow 0}\\frac{v(t+\\Delta t)-v(t)}{\\Delta t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**A note on notations**: When writing for example the velocity as $v(t)$ we are then referring to the continuous and instantaneous value. A subscript like\n", + "$v_i$ refers always to the discretized values.\n", + "\n", + "\n", + "## A differential equation\n", + "\n", + "We can rewrite the instantaneous acceleration as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "a(t) = \\frac{dv}{dt}=\\frac{d}{dt}\\frac{dy}{dt}=\\frac{d^2y}{dt^2}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This forms the starting point for our definition of forces later. It is a famous second-order differential equation. If the acceleration is constant we can now recover the formula for the falling ball we started with.\n", + "The acceleration can depend on the position and the velocity. To be more formal we should then write the above differential equation as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2y}{dt^2}=a(t,y(t),\\frac{dy}{dt}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With given initial conditions for $y(t_0)$ and $v(t_0)$ we can then\n", + "integrate the above equation and find the velocities and positions at\n", + "a given time $t$.\n", + "\n", + "If we multiply with mass, we have one of the famous expressions for Newton's second law," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "F(y,v,t)=m\\frac{d^2y}{dt^2}=ma(t,y(t),\\frac{dy}{dt}),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $F$ is the force acting on an object with mass $m$. We see that it also has the right dimension, mass times length divided by time squared.\n", + "We will come back to this soon.\n", + "\n", + "\n", + "## Integrating our equations\n", + "\n", + "Formally we can then, starting with the acceleration (suppose we have measured it, how could we do that?)\n", + "compute say the height of a building. To see this we perform the following integrations from an initial time $t_0$ to a given time $t$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_{t_0}^t dt a(t) = \\int_{t_0}^t dt \\frac{dv}{dt} = v(t)-v(t_0),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t)=v(t_0)+\\int_{t_0}^t dt a(t).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When we know the velocity as function of time, we can find the position as function of time starting from the defintion of velocity as the derivative with respect to time, that is we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_{t_0}^t dt v(t) = \\int_{t_0}^t dt \\frac{dy}{dt} = y(t)-y(t_0),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t)=y(t_0)+\\int_{t_0}^t dt v(t).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "These equations define what is called the integration method for\n", + "finding the position and the velocity as functions of time. There is\n", + "no loss of generality if we extend these equations to more than one\n", + "spatial dimension.\n", + "\n", + "\n", + "## Constant acceleration case, the velocity\n", + "\n", + "Let us compute the velocity using the constant value for the acceleration given by $-g$. We have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t)=v(t_0)+\\int_{t_0}^t dt a(t)=v(t_0)+\\int_{t_0}^t dt (-g).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using our initial time as $t_0=0$s and setting the initial velocity $v(t_0)=v_0=0$m/s we get when integrating" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t)=-gt.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The more general case is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t)=v_0-g(t-t_0).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can then integrate the velocity and obtain the final formula for the position as function of time through" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t)=y(t_0)+\\int_{t_0}^t dt v(t)=y_0+\\int_{t_0}^t dt v(t)=y_0+\\int_{t_0}^t dt (-gt),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With $y_0=10$m and $t_0=0$s, we obtain the equation we started with" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t)=10-\\frac{1}{2}gt^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Computing the averages\n", + "\n", + "After this mathematical background we are now ready to compute the mean velocity using our data." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Now we can compute the mean velocity using our data\n", + "# We define first an array Vaverage\n", + "n = np.size(t)\n", + "Vaverage = np.zeros(n)\n", + "for i in range(1,n-1):\n", + " Vaverage[i] = (y[i+1]-y[i])/DeltaT\n", + "# Now we can compute the mean accelearatio using our data\n", + "# We define first an array Aaverage\n", + "n = np.size(t)\n", + "Aaverage = np.zeros(n)\n", + "Aaverage[0] = -g\n", + "for i in range(1,n-1):\n", + " Aaverage[i] = (Vaverage[i+1]-Vaverage[i])/DeltaT\n", + "data = {'t[s]': t,\n", + " 'y[m]': y,\n", + " 'v[m/s]': Vaverage,\n", + " 'a[m/s^2]': Aaverage\n", + " }\n", + "NewData = pd.DataFrame(data)\n", + "display(NewData[0:n-2])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that we don't print the last values! \n", + "\n", + "\n", + "\n", + "\n", + "## Including Air Resistance in our model\n", + "\n", + "In our discussions till now of the falling baseball, we have ignored\n", + "air resistance and simply assumed that our system is only influenced\n", + "by the gravitational force. We will postpone the derivation of air\n", + "resistance till later, after our discussion of Newton's laws and\n", + "forces.\n", + "\n", + "For our discussions here it suffices to state that the accelerations is now modified to" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{a}(t) = -g +D\\boldsymbol{v}(t)\\vert v(t)\\vert,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\vert v(t)\\vert$ is the absolute value of the velocity and $D$ is a constant which pertains to the specific object we are studying.\n", + "Since we are dealing with motion in one dimension, we can simplify the above to" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "a(t) = -g +Dv^2(t).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can rewrite this as a differential equation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "a(t) = \\frac{dv}{dt}=\\frac{d^2y}{dt^2}= -g +Dv^2(t).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using the integral equations discussed above we can integrate twice\n", + "and obtain first the velocity as function of time and thereafter the\n", + "position as function of time.\n", + "\n", + "For this particular case, we can actually obtain an analytical\n", + "solution for the velocity and for the position. Here we will first\n", + "compute the solutions analytically, thereafter we will derive Euler's\n", + "method for solving these differential equations numerically.\n", + "\n", + "\n", + "## Analytical solutions\n", + "\n", + "For simplicity let us just write $v(t)$ as $v$. We have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{dv}{dt}= -g +Dv^2(t).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can solve this using the technique of separation of variables. We\n", + "isolate on the left all terms that involve $v$ and on the right all\n", + "terms that involve time. We get then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{dv}{g -Dv^2(t) }= -dt,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We scale now the equation to the left by introducing a constant\n", + "$v_T=\\sqrt{g/D}$. This constant has dimension length/time. Can you\n", + "show this?\n", + "\n", + "Next we integrate the left-hand side (lhs) from $v_0=0$ m/s to $v$ and\n", + "the right-hand side (rhs) from $t_0=0$ to $t$ and obtain" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_{0}^v\\frac{dv}{g -Dv^2(t) }= \\frac{v_T}{g}\\mathrm{arctanh}(\\frac{v}{v_T}) =-\\int_0^tdt = -t.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can reorganize these equations as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v_T\\mathrm{arctanh}(\\frac{v}{v_T}) =-gt,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which gives us $v$ as function of time" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t)=v_T\\tanh{-(\\frac{gt}{v_T})}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Finding the final height\n", + "\n", + "With the velocity we can then find the height $y(t)$ by integrating yet another time, that is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t)=y(t_0)+\\int_{t_0}^t dt v(t)=\\int_{0}^t dt[v_T\\tanh{-(\\frac{gt}{v_T})}].\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This integral is a little bit trickier but we can look it up in a table over \n", + "known integrals and we get" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t)=y(t_0)-\\frac{v_T^2}{g}\\log{[\\cosh{(\\frac{gt}{v_T})}]}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Alternatively we could have used the symbolic Python package **Sympy** (example will be inserted later). \n", + "\n", + "In most cases however, we need to revert to numerical solutions. \n", + "\n", + "\n", + "\n", + "## Our first attempt at solving differential equations\n", + "\n", + "Here we will try the simplest possible approach to solving the second-order differential \n", + "equation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "a(t) =\\frac{d^2y}{dt^2}= -g +Dv^2(t).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We rewrite it as two coupled first-order equations (this is a standard approach)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{dy}{dt} = v(t),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with initial condition $y(t_0)=y_0$ and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "a(t) =\\frac{dv}{dt}= -g +Dv^2(t),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with initial condition $v(t_0)=v_0$.\n", + "\n", + "Many of the algorithms for solving differential equations start with simple Taylor equations.\n", + "If we now Taylor expand $y$ and $v$ around a value $t+\\Delta t$ we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t+\\Delta t) = y(t)+\\Delta t \\frac{dy}{dt}+\\frac{\\Delta t^2}{2!} \\frac{d^2y}{dt^2}+O(\\Delta t^3),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t+\\Delta t) = v(t)+\\Delta t \\frac{dv}{dt}+\\frac{\\Delta t^2}{2!} \\frac{d^2v}{dt^2}+O(\\Delta t^3).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using the fact that $dy/dt = v$ and $dv/dt=a$ and keeping only terms up to $\\Delta t$ we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y(t+\\Delta t) = y(t)+\\Delta t v(t)+O(\\Delta t^2),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v(t+\\Delta t) = v(t)+\\Delta t a(t)+O(\\Delta t^2).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Discretizing our equations\n", + "\n", + "Using our discretized versions of the equations with for example\n", + "$y_{i}=y(t_i)$ and $y_{i\\pm 1}=y(t_i+\\Delta t)$, we can rewrite the\n", + "above equations as (and truncating at $\\Delta t$)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y_{i+1} = y_i+\\Delta t v_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v_{i+1} = v_i+\\Delta t a_i.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "These are the famous Euler equations (forward Euler).\n", + "\n", + "To solve these equations numerically we start at a time $t_0$ and simply integrate up these equations to a final time $t_f$,\n", + "The step size $\\Delta t$ is an input parameter in our code.\n", + "You can define it directly in the code below as" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "DeltaT = 0.1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With a given final time **tfinal** we can then find the number of integration points via the **ceil** function included in the **math** package of Python\n", + "as" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#define final time, assuming that initial time is zero\n", + "from math import ceil\n", + "tfinal = 0.5\n", + "n = ceil(tfinal/DeltaT)\n", + "print(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The **ceil** function returns the smallest integer not less than the input in say" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "x = 21.15\n", + "print(ceil(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which in the case here is 22." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "x = 21.75\n", + "print(ceil(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which also yields 22. The **floor** function in the **math** package\n", + "is used to return the closest integer value which is less than or equal to the specified expression or value.\n", + "Compare the previous result to the usage of **floor**" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from math import floor\n", + "x = 21.75\n", + "print(floor(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Alternatively, we can define ourselves the number of integration(mesh) points. In this case we could have" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "n = 10\n", + "tinitial = 0.0\n", + "tfinal = 0.5\n", + "DeltaT = (tfinal-tinitial)/(n)\n", + "print(DeltaT)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since we will set up one-dimensional arrays that contain the values of\n", + "various variables like time, position, velocity, acceleration etc, we\n", + "need to know the value of $n$, the number of data points (or\n", + "integration or mesh points). With $n$ we can initialize a given array\n", + "by setting all elelements to zero, as done here" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# define array a\n", + "a = np.zeros(n)\n", + "print(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Code for implementing Euler's method\n", + "In the code here we implement this simple Eurler scheme choosing a value for $D=0.0245$ m/s." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Common imports\n", + "import numpy as np\n", + "import pandas as pd\n", + "from math import *\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "\n", + "# Where to save the figures and data files\n", + "PROJECT_ROOT_DIR = \"Results\"\n", + "FIGURE_ID = \"Results/FigureFiles\"\n", + "DATA_ID = \"DataFiles/\"\n", + "\n", + "if not os.path.exists(PROJECT_ROOT_DIR):\n", + " os.mkdir(PROJECT_ROOT_DIR)\n", + "\n", + "if not os.path.exists(FIGURE_ID):\n", + " os.makedirs(FIGURE_ID)\n", + "\n", + "if not os.path.exists(DATA_ID):\n", + " os.makedirs(DATA_ID)\n", + "\n", + "def image_path(fig_id):\n", + " return os.path.join(FIGURE_ID, fig_id)\n", + "\n", + "def data_path(dat_id):\n", + " return os.path.join(DATA_ID, dat_id)\n", + "\n", + "def save_fig(fig_id):\n", + " plt.savefig(image_path(fig_id) + \".png\", format='png')\n", + "\n", + "\n", + "g = 9.80655 #m/s^2\n", + "D = 0.00245 #m/s\n", + "DeltaT = 0.1\n", + "#set up arrays \n", + "tfinal = 0.5\n", + "n = ceil(tfinal/DeltaT)\n", + "# define scaling constant vT\n", + "vT = sqrt(g/D)\n", + "# set up arrays for t, a, v, and y and we can compare our results with analytical ones\n", + "t = np.zeros(n)\n", + "a = np.zeros(n)\n", + "v = np.zeros(n)\n", + "y = np.zeros(n)\n", + "yanalytic = np.zeros(n)\n", + "# Initial conditions\n", + "v[0] = 0.0 #m/s\n", + "y[0] = 10.0 #m\n", + "yanalytic[0] = y[0]\n", + "# Start integrating using Euler's method\n", + "for i in range(n-1):\n", + " # expression for acceleration\n", + " a[i] = -g + D*v[i]*v[i]\n", + " # update velocity and position\n", + " y[i+1] = y[i] + DeltaT*v[i]\n", + " v[i+1] = v[i] + DeltaT*a[i]\n", + " # update time to next time step and compute analytical answer\n", + " t[i+1] = t[i] + DeltaT\n", + " yanalytic[i+1] = y[0]-(vT*vT/g)*log(cosh(g*t[i+1]/vT))\n", + " if ( y[i+1] < 0.0):\n", + " break\n", + "a[n-1] = -g + D*v[n-1]*v[n-1]\n", + "data = {'t[s]': t,\n", + " 'y[m]': y-yanalytic,\n", + " 'v[m/s]': v,\n", + " 'a[m/s^2]': a\n", + " }\n", + "NewData = pd.DataFrame(data)\n", + "display(NewData)\n", + "#finally we plot the data\n", + "fig, axs = plt.subplots(3, 1)\n", + "axs[0].plot(t, y, t, yanalytic)\n", + "axs[0].set_xlim(0, tfinal)\n", + "axs[0].set_ylabel('y and exact')\n", + "axs[1].plot(t, v)\n", + "axs[1].set_ylabel('v[m/s]')\n", + "axs[2].plot(t, a)\n", + "axs[2].set_xlabel('time[s]')\n", + "axs[2].set_ylabel('a[m/s^2]')\n", + "fig.tight_layout()\n", + "save_fig(\"EulerIntegration\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Try different values for $\\Delta t$ and study the difference between the exact solution and the numerical solution.\n", + "\n", + "\n", + "## Simple extension, the Euler-Cromer method\n", + "\n", + "The Euler-Cromer method is a simple variant of the standard Euler\n", + "method. We use the newly updated velocity $v_{i+1}$ as an input to the\n", + "new position, that is, instead of" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y_{i+1} = y_i+\\Delta t v_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v_{i+1} = v_i+\\Delta t a_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "we use now the newly calculate for $v_{i+1}$ as input to $y_{i+1}$, that is \n", + "we compute first" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v_{i+1} = v_i+\\Delta t a_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y_{i+1} = y_i+\\Delta t v_{i+1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Implementing the Euler-Cromer method yields a simple change to the previous code. We only need to change the following line in the loop over time\n", + "steps" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "for i in range(n-1):\n", + " # more codes in between here\n", + " v[i+1] = v[i] + DeltaT*a[i]\n", + " y[i+1] = y[i] + DeltaT*v[i+1]\n", + " # more code" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python practicalities, Software and needed installations\n", + "\n", + "We will make extensive use of Python as programming language and its\n", + "myriad of available libraries. You will find\n", + "Jupyter notebooks invaluable in your work. \n", + "\n", + "If you have Python installed (we strongly recommend Python3) and you feel\n", + "pretty familiar with installing different packages, we recommend that\n", + "you install the following Python packages via **pip** as \n", + "\n", + "1. pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow \n", + "\n", + "For Python3, replace **pip** with **pip3**.\n", + "\n", + "For OSX users we recommend, after having installed Xcode, to\n", + "install **brew**. Brew allows for a seamless installation of additional\n", + "software via for example \n", + "\n", + "1. brew install python3\n", + "\n", + "For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution,\n", + "you can use **pip** as well and simply install Python as \n", + "\n", + "1. sudo apt-get install python3 (or python for pyhton2.7)\n", + "\n", + "etc etc. \n", + "\n", + "\n", + "\n", + "## Python installers\n", + "\n", + "If you don't want to perform these operations separately and venture\n", + "into the hassle of exploring how to set up dependencies and paths, we\n", + "recommend two widely used distrubutions which set up all relevant\n", + "dependencies for Python, namely \n", + "\n", + "* [Anaconda](https://docs.anaconda.com/), \n", + "\n", + "which is an open source\n", + "distribution of the Python and R programming languages for large-scale\n", + "data processing, predictive analytics, and scientific computing, that\n", + "aims to simplify package management and deployment. Package versions\n", + "are managed by the package management system **conda**. \n", + "\n", + "* [Enthought canopy](https://www.enthought.com/product/canopy/) \n", + "\n", + "is a Python\n", + "distribution for scientific and analytic computing distribution and\n", + "analysis environment, available for free and under a commercial\n", + "license.\n", + "\n", + "Furthermore, [Google's Colab](https://colab.research.google.com/notebooks/welcome.ipynb) is a free Jupyter notebook environment that requires \n", + "no setup and runs entirely in the cloud. Try it out!\n", + "\n", + "## Useful Python libraries\n", + "Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there)\n", + "\n", + "* [NumPy](https://www.numpy.org/) is a highly popular library for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays\n", + "\n", + "* [The pandas](https://pandas.pydata.org/) library provides high-performance, easy-to-use data structures and data analysis tools \n", + "\n", + "* [Xarray](http://xarray.pydata.org/en/stable/) is a Python package that makes working with labelled multi-dimensional arrays simple, efficient, and fun!\n", + "\n", + "* [Scipy](https://www.scipy.org/) (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering. \n", + "\n", + "* [Matplotlib](https://matplotlib.org/) is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.\n", + "\n", + "* [Autograd](https://github.com/HIPS/autograd) can automatically differentiate native Python and Numpy code. It can handle a large subset of Python's features, including loops, ifs, recursion and closures, and it can even take derivatives of derivatives of derivatives\n", + "\n", + "* [SymPy](https://www.sympy.org/en/index.html) is a Python library for symbolic mathematics. \n", + "\n", + "* [scikit-learn](https://scikit-learn.org/stable/) has simple and efficient tools for machine learning, data mining and data analysis\n", + "\n", + "* [TensorFlow](https://www.tensorflow.org/) is a Python library for fast numerical computing created and released by Google\n", + "\n", + "* [Keras](https://keras.io/) is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano\n", + "\n", + "* And many more such as [pytorch](https://pytorch.org/), [Theano](https://pypi.org/project/Theano/) etc \n", + "\n", + "Your jupyter notebook can easily be\n", + "converted into a nicely rendered **PDF** file or a Latex file for\n", + "further processing. For example, convert to latex as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " pycod jupyter nbconvert filename.ipynb --to latex \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And to add more versatility, the Python package [SymPy](http://www.sympy.org/en/index.html) is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python. \n", + "\n", + "\n", + "\n", + "## Numpy examples and Important Matrix and vector handling packages\n", + "\n", + "There are several central software libraries for linear algebra and eigenvalue problems. Several of the more\n", + "popular ones have been wrapped into ofter software packages like those from the widely used text **Numerical Recipes**. The original source codes in many of the available packages are often taken from the widely used\n", + "software package LAPACK, which follows two other popular packages\n", + "developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly here.\n", + "\n", + " * LINPACK: package for linear equations and least square problems.\n", + "\n", + " * LAPACK:package for solving symmetric, unsymmetric and generalized eigenvalue problems. From LAPACK's website it is possible to download for free all source codes from this library. Both C/C++ and Fortran versions are available.\n", + "\n", + " * BLAS (I, II and III): (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations. Blas I is vector operations, II vector-matrix operations and III matrix-matrix operations. Highly parallelized and efficient codes, all available for download from .\n", + "\n", + "## Basic Matrix Features\n", + "\n", + "**Matrix properties reminder.**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\mathbf{A} =\n", + " \\begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\\\\n", + " a_{21} & a_{22} & a_{23} & a_{24} \\\\\n", + " a_{31} & a_{32} & a_{33} & a_{34} \\\\\n", + " a_{41} & a_{42} & a_{43} & a_{44}\n", + " \\end{bmatrix}\\qquad\n", + "\\mathbf{I} =\n", + " \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\\n", + " 0 & 1 & 0 & 0 \\\\\n", + " 0 & 0 & 1 & 0 \\\\\n", + " 0 & 0 & 0 & 1\n", + " \\end{bmatrix}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The inverse of a matrix is defined by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\mathbf{A}^{-1} \\cdot \\mathbf{A} = I\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
Relations Name matrix elements
$A = A^{T}$ symmetric $a_{ij} = a_{ji}$
$A = \\left (A^{T} \\right )^{-1}$ real orthogonal $\\sum_k a_{ik} a_{jk} = \\sum_k a_{ki} a_{kj} = \\delta_{ij}$
$A = A^{ * }$ real matrix $a_{ij} = a_{ij}^{ * }$
$A = A^{\\dagger}$ hermitian $a_{ij} = a_{ji}^{ * }$
$A = \\left (A^{\\dagger} \\right )^{-1}$ unitary $\\sum_k a_{ik} a_{jk}^{ * } = \\sum_k a_{ki}^{ * } a_{kj} = \\delta_{ij}$
\n", + "\n", + "\n", + "\n", + "\n", + "### Some famous Matrices\n", + "\n", + " * Diagonal if $a_{ij}=0$ for $i\\ne j$\n", + "\n", + " * Upper triangular if $a_{ij}=0$ for $i > j$\n", + "\n", + " * Lower triangular if $a_{ij}=0$ for $i < j$\n", + "\n", + " * Upper Hessenberg if $a_{ij}=0$ for $i > j+1$\n", + "\n", + " * Lower Hessenberg if $a_{ij}=0$ for $i < j+1$\n", + "\n", + " * Tridiagonal if $a_{ij}=0$ for $|i -j| > 1$\n", + "\n", + " * Lower banded with bandwidth $p$: $a_{ij}=0$ for $i > j+p$\n", + "\n", + " * Upper banded with bandwidth $p$: $a_{ij}=0$ for $i < j+p$\n", + "\n", + " * Banded, block upper triangular, block lower triangular....\n", + "\n", + "### More Basic Matrix Features\n", + "\n", + "**Some Equivalent Statements.**\n", + "\n", + "For an $N\\times N$ matrix $\\mathbf{A}$ the following properties are all equivalent\n", + "\n", + " * If the inverse of $\\mathbf{A}$ exists, $\\mathbf{A}$ is nonsingular.\n", + "\n", + " * The equation $\\mathbf{Ax}=0$ implies $\\mathbf{x}=0$.\n", + "\n", + " * The rows of $\\mathbf{A}$ form a basis of $R^N$.\n", + "\n", + " * The columns of $\\mathbf{A}$ form a basis of $R^N$.\n", + "\n", + " * $\\mathbf{A}$ is a product of elementary matrices.\n", + "\n", + " * $0$ is not eigenvalue of $\\mathbf{A}$.\n", + "\n", + "\n", + "\n", + "\n", + "## Numpy and arrays\n", + "[Numpy](http://www.numpy.org/) provides an easy way to handle arrays in Python. The standard way to import this library is as" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution," + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "n = 10\n", + "x = np.random.normal(size=n)\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We defined a vector $x$ with $n=10$ elements with its values given by the Normal distribution $N(0,1)$.\n", + "Another alternative is to declare a vector as follows" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "x = np.array([1, 2, 3])\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here we have defined a vector with three elements, with $x_0=1$, $x_1=2$ and $x_2=3$. Note that both Python and C++\n", + "start numbering array elements from $0$ and on. This means that a vector with $n$ elements has a sequence of entities $x_0, x_1, x_2, \\dots, x_{n-1}$. We could also let (recommended) Numpy to compute the logarithms of a specific array as" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "x = np.log(np.array([4, 7, 8]))\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the last example we used Numpy's unary function $np.log$. This function is\n", + "highly tuned to compute array elements since the code is vectorized\n", + "and does not require looping. We normaly recommend that you use the\n", + "Numpy intrinsic functions instead of the corresponding **log** function\n", + "from Python's **math** module. The looping is done explicitely by the\n", + "**np.log** function. The alternative, and slower way to compute the\n", + "logarithms of a vector would be to write" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "from math import log\n", + "x = np.array([4, 7, 8])\n", + "for i in range(0, len(x)):\n", + " x[i] = log(x[i])\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We note that our code is much longer already and we need to import the **log** function from the **math** module. \n", + "The attentive reader will also notice that the output is $[1, 1, 2]$. Python interprets automagically our numbers as integers (like the **automatic** keyword in C++). To change this we could define our array elements to be double precision numbers as" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "x = np.log(np.array([4, 7, 8], dtype = np.float64))\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "x = np.log(np.array([4.0, 7.0, 8.0])\n", + "print(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the **itemsize** functionality (the array $x$ is actually an object which inherits the functionalities defined in Numpy) as" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "x = np.log(np.array([4.0, 7.0, 8.0])\n", + "print(x.itemsize)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Matrices in Python\n", + "\n", + "Having defined vectors, we are now ready to try out matrices. We can\n", + "define a $3 \\times 3 $ real matrix $\\hat{A}$ as (recall that we user\n", + "lowercase letters for vectors and uppercase letters for matrices)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))\n", + "print(A)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If we use the **shape** function we would get $(3, 3)$ as output, that is verifying that our matrix is a $3\\times 3$ matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))\n", + "# print the first column, row-major order and elements start with 0\n", + "print(A[:,0])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can continue this was by printing out other columns or rows. The example here prints out the second column" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))\n", + "# print the first column, row-major order and elements start with 0\n", + "print(A[1,:])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the [Numpy website for more details](http://www.numpy.org/). Useful functions when defining a matrix are the **np.zeros** function which declares a matrix of a given dimension and sets all elements to zero" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "n = 10\n", + "# define a matrix of dimension 10 x 10 and set all elements to zero\n", + "A = np.zeros( (n, n) )\n", + "print(A)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or initializing all elements to" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "n = 10\n", + "# define a matrix of dimension 10 x 10 and set all elements to one\n", + "A = np.ones( (n, n) )\n", + "print(A)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or as unitarily distributed random numbers (see the material on random number generators in the statistics part)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "n = 10\n", + "# define a matrix of dimension 10 x 10 and set all elements to random numbers with x \\in [0, 1]\n", + "A = np.random.rand(n, n)\n", + "print(A)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Meet the Pandas\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "

\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Another useful Python package is\n", + "[pandas](https://pandas.pydata.org/), which is an open source library\n", + "providing high-performance, easy-to-use data structures and data\n", + "analysis tools for Python. **pandas** stands for panel data, a term borrowed from econometrics and is an efficient library for data analysis with an emphasis on tabular data.\n", + "**pandas** has two major classes, the **DataFrame** class with two-dimensional data objects and tabular data organized in columns and the class **Series** with a focus on one-dimensional data objects. Both classes allow you to index data easily as we will see in the examples below. \n", + "**pandas** allows you also to perform mathematical operations on the data, spanning from simple reshapings of vectors and matrices to statistical operations. \n", + "\n", + "The following simple example shows how we can, in an easy way make tables of our data. Here we define a data set which includes names, place of birth and date of birth, and displays the data in an easy to read way. We will see repeated use of **pandas**, in particular in connection with classification of data." + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import pandas as pd\n", + "from IPython.display import display\n", + "data = {'First Name': [\"Frodo\", \"Bilbo\", \"Aragorn II\", \"Samwise\"],\n", + " 'Last Name': [\"Baggins\", \"Baggins\",\"Elessar\",\"Gamgee\"],\n", + " 'Place of birth': [\"Shire\", \"Shire\", \"Eriador\", \"Shire\"],\n", + " 'Date of Birth T.A.': [2968, 2890, 2931, 2980]\n", + " }\n", + "data_pandas = pd.DataFrame(data)\n", + "display(data_pandas)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the above we have imported **pandas** with the shorthand **pd**, the latter has become the standard way we import **pandas**. We make then a list of various variables\n", + "and reorganize the above lists into a **DataFrame** and then print out a neat table with specific column labels as *Name*, *place of birth* and *date of birth*.\n", + "Displaying these results, we see that the indices are given by the default numbers from zero to three.\n", + "**pandas** is extremely flexible and we can easily change the above indices by defining a new type of indexing as" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])\n", + "display(data_pandas)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thereafter we display the content of the row which begins with the index **Aragorn**" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "display(data_pandas.loc['Aragorn'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can easily append data to this, for example" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "new_hobbit = {'First Name': [\"Peregrin\"],\n", + " 'Last Name': [\"Took\"],\n", + " 'Place of birth': [\"Shire\"],\n", + " 'Date of Birth T.A.': [2990]\n", + " }\n", + "data_pandas=data_pandas.append(pd.DataFrame(new_hobbit, index=['Pippin']))\n", + "display(data_pandas)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here are other examples where we use the **DataFrame** functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix \n", + "of dimensionality $10\\times 5$ and compute the mean value and standard deviation of each column. Similarly, we can perform mathematial operations like squaring the matrix elements and many other operations." + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import pandas as pd\n", + "from IPython.display import display\n", + "np.random.seed(100)\n", + "# setting up a 10 x 5 matrix\n", + "rows = 10\n", + "cols = 5\n", + "a = np.random.randn(rows,cols)\n", + "df = pd.DataFrame(a)\n", + "display(df)\n", + "print(df.mean())\n", + "print(df.std())\n", + "display(df**2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thereafter we can select specific columns only and plot final results" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']\n", + "df.index = np.arange(10)\n", + "\n", + "display(df)\n", + "print(df['Second'].mean() )\n", + "print(df.info())\n", + "print(df.describe())\n", + "\n", + "from pylab import plt, mpl\n", + "plt.style.use('seaborn')\n", + "mpl.rcParams['font.family'] = 'serif'\n", + "\n", + "df.cumsum().plot(lw=2.0, figsize=(10,6))\n", + "plt.show()\n", + "\n", + "\n", + "df.plot.bar(figsize=(10,6), rot=15)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can produce a $4\\times 4$ matrix" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "b = np.arange(16).reshape((4,4))\n", + "print(b)\n", + "df1 = pd.DataFrame(b)\n", + "print(df1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and many other operations. \n", + "\n", + "The **Series** class is another important class included in\n", + "**pandas**. You can view it as a specialization of **DataFrame** but where\n", + "we have just a single column of data. It shares many of the same features as _DataFrame. As with **DataFrame**,\n", + "most operations are vectorized, achieving thereby a high performance when dealing with computations of arrays, in particular labeled arrays.\n", + "As we will see below it leads also to a very concice code close to the mathematical operations we may be interested in.\n", + "For multidimensional arrays, we recommend strongly [xarray](http://xarray.pydata.org/en/stable/). **xarray** has much of the same flexibility as **pandas**, but allows for the extension to higher dimensions than two." + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/chapter3.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter3.ipynb new file mode 100644 index 000000000..e08bcd29c --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter3.ipynb @@ -0,0 +1,1643 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Basic Steps of Scientific Investigations\n", + "\n", + "An overarching aim in this course is to give you a deeper\n", + "understanding of the scientific method. The problems we study will all\n", + "involve cases where we can apply classical mechanics. In our previous\n", + "material we already assumed that we had a model for the motion of an\n", + "object. Alternatively we could have data from experiment (like Usain\n", + "Bolt's 100m world record run in 2008). Or we could have performed\n", + "ourselves an experiment and we want to understand which forces are at\n", + "play and whether these forces can be understood in terms of\n", + "fundamental forces.\n", + "\n", + "Our first step consists in identifying the problem. What we sketch\n", + "here may include a mix of experiment and theoretical simulations, or\n", + "just experiment or only theory.\n", + "\n", + "\n", + "## Identifying our System\n", + "\n", + "Here we can ask questions like\n", + "1. What kind of object is moving\n", + "\n", + "2. What kind of data do we have\n", + "\n", + "3. How do we measure position, velocity, acceleration etc\n", + "\n", + "4. Which initial conditions influence our system\n", + "\n", + "5. Other aspects which allow us to identify the system\n", + "\n", + "## Defining a Model\n", + "\n", + "With our eventual data and observations we would now like to develop a\n", + "model for the system. In the end we want obviously to be able to\n", + "understand which forces are at play and how they influence our\n", + "specific system. That is, can we extract some deeper insights about a\n", + "system?\n", + "\n", + "We need then to\n", + "1. Find the forces that act on our system\n", + "\n", + "2. Introduce models for the forces\n", + "\n", + "3. Identify the equations which can govern the system (Newton's second law for example)\n", + "\n", + "4. More elements we deem important for defining our model\n", + "\n", + "## Solving the Equations\n", + "\n", + "With the model at hand, we can then solve the equations. In classical mechanics we normally end up with solving sets of coupled ordinary differential equations or partial differential equations.\n", + "1. Using Newton's second law we have equations of the type $\\boldsymbol{F}=m\\boldsymbol{a}=md\\boldsymbol{v}/dt$\n", + "\n", + "2. We need to define the initial conditions (typically the initial velocity and position as functions of time) and/or initial conditions and boundary conditions\n", + "\n", + "3. The solution of the equations give us then the position, the velocity and other time-dependent quantities which may specify the motion of a given object.\n", + "\n", + "We are not yet done. With our lovely solvers, we need to start thinking.\n", + "\n", + "\n", + "Now it is time to ask the big questions. What do our results mean? Can we give a simple interpretation in terms of fundamental laws? What do our results mean? Are they correct?\n", + "Thus, typical questions we may ask are\n", + "1. Are our results for say $\\boldsymbol{r}(t)$ valid? Do we trust what we did? Can you validate and verify the correctness of your results?\n", + "\n", + "2. Evaluate the answers and their implications\n", + "\n", + "3. Compare with experimental data if possible. Does our model make sense?\n", + "\n", + "4. and obviously many other questions.\n", + "\n", + "The analysis stage feeds back to the first stage. It may happen that\n", + "the data we had were not good enough, there could be large statistical\n", + "uncertainties. We may need to collect more data or perhaps we did a\n", + "sloppy job in identifying the degrees of freedom.\n", + "\n", + "All these steps are essential elements in a scientific\n", + "enquiry. Hopefully, through a mix of numerical simulations, analytical\n", + "calculations and experiments we may gain a deeper insight about the\n", + "physics of a specific system.\n", + "\n", + "Let us now remind ourselves of Newton's laws, since these are the laws of motion we will study in this course.\n", + "\n", + "\n", + "## Newton's Laws\n", + "\n", + "When analyzing a physical system we normally start with distinguishing between the object we are studying (we will label this in more general terms as our **system**) and how this system interacts with the environment (which often means everything else!)\n", + "\n", + "In our investigations we will thus analyze a specific physics problem in terms of the system and the environment.\n", + "In doing so we need to identify the forces that act on the system and assume that the\n", + "forces acting on the system must have a source, an identifiable cause in\n", + "the environment.\n", + "\n", + "A force acting on for example a falling object must be related to an interaction with something in the environment.\n", + "This also means that we do not consider internal forces. The latter are forces between\n", + "one part of the object and another part. In this course we will mainly focus on external forces.\n", + "\n", + "Forces are either contact forces or long-range forces.\n", + "\n", + "Contact forces, as evident from the name, are forces that occur at the contact between\n", + "the system and the environment. Well-known long-range forces are the gravitional force and the electromagnetic force.\n", + "\n", + "\n", + "\n", + "## Setting up a model for forces acting on an object\n", + "\n", + "In order to set up the forces which act on an object, the following steps may be useful\n", + "1. Divide the problem into system and environment.\n", + "\n", + "2. Draw a figure of the object and everything in contact with the object.\n", + "\n", + "3. Draw a closed curve around the system.\n", + "\n", + "4. Find contact points—these are the points where contact forces may act.\n", + "\n", + "5. Give names and symbols to all the contact forces.\n", + "\n", + "6. Identify the long-range forces.\n", + "\n", + "7. Make a drawing of the object. Draw the forces as arrows, vectors, starting from where the force is acting. The direction of the vector(s) indicates the (positive) direction of the force. Try to make the length of the arrow indicate the relative magnitude of the forces.\n", + "\n", + "8. Draw in the axes of the coordinate system. It is often convenient to make one axis parallel to the direction of motion. When you choose the direction of the axis you also choose the positive direction for the axis.\n", + "\n", + "## Newton's Laws, the Second one first\n", + "\n", + "\n", + "Newton’s second law of motion: The force $\\boldsymbol{F}$ on an object of inertial mass $m$\n", + "is related to the acceleration a of the object through" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F} = m\\boldsymbol{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\boldsymbol{a}$ is the acceleration.\n", + "\n", + "Newton’s laws of motion are laws of nature that have been found by experimental\n", + "investigations and have been shown to hold up to continued experimental investigations.\n", + "Newton’s laws are valid over a wide range of length- and time-scales. We\n", + "use Newton’s laws of motion to describe everything from the motion of atoms to the\n", + "motion of galaxies.\n", + "\n", + "The second law is a vector equation with the acceleration having the same\n", + "direction as the force. The acceleration is proportional to the force via the mass $m$ of the system under study.\n", + "\n", + "\n", + "Newton’s second law introduces a new property of an object, the so-called \n", + "inertial mass $m$. We determine the inertial mass of an object by measuring the\n", + "acceleration for a given applied force.\n", + "\n", + "\n", + "\n", + "## Then the First Law\n", + "\n", + "\n", + "What happens if the net external force on a body is zero? Applying Newton’s second\n", + "law, we find:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F} = 0 = m\\boldsymbol{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which gives using the definition of the acceleration" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{a} = \\frac{d\\boldsymbol{v}}{dt}=0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The acceleration is zero, which means that the velocity of the object is constant. This\n", + "is often referred to as Newton’s first law. An object in a state of uniform motion tends to remain in\n", + "that state unless an external force changes its state of motion.\n", + "Why do we need a separate law for this? Is it not simply a special case of Newton’s\n", + "second law? Yes, Newton’s first law can be deduced from the second law as we have\n", + "illustrated. However, the first law is often used for a different purpose: Newton’s\n", + "First Law tells us about the limit of applicability of Newton’s Second law. Newton’s\n", + "Second law can only be used in reference systems where the First law is obeyed. But\n", + "is not the First law always valid? No! The First law is only valid in reference systems\n", + "that are not accelerated. If you observe the motion of a ball from an accelerating\n", + "car, the ball will appear to accelerate even if there are no forces acting on it. We call\n", + "systems that are not accelerating inertial systems, and Newton’s first law is often\n", + "called the law of inertia. Newton’s first and second laws of motion are only valid in\n", + "inertial systems. \n", + "\n", + "A system is an inertial system if it is not accelerated. It means that the reference system\n", + "must not be accelerating linearly or rotating. Unfortunately, this means that most\n", + "systems we know are not really inertial systems. For example, the surface of the\n", + "Earth is clearly not an inertial system, because the Earth is rotating. The Earth is also\n", + "not an inertial system, because it ismoving in a curved path around the Sun. However,\n", + "even if the surface of the Earth is not strictly an inertial system, it may be considered\n", + "to be approximately an inertial system for many laboratory-size experiments.\n", + "\n", + "\n", + "## And finally the Third Law\n", + "\n", + "\n", + "If there is a force from object A on object B, there is also a force from object B on object A.\n", + "This fundamental principle of interactions is called Newton’s third law. We do not\n", + "know of any force that do not obey this law: All forces appear in pairs. Newton’s\n", + "third law is usually formulated as: For every action there is an equal and opposite\n", + "reaction.\n", + "\n", + "\n", + "\n", + "## Motion of a Single Object\n", + "\n", + "Here we consider the motion of a single particle moving under\n", + "the influence of some set of forces. We will consider some problems where\n", + "the force does not depend on the position. In that case Newton's law\n", + "$m\\dot{\\boldsymbol{v}}=\\boldsymbol{F}(\\boldsymbol{v})$ is a first-order differential\n", + "equation and one solves for $\\boldsymbol{v}(t)$, then moves on to integrate\n", + "$\\boldsymbol{v}$ to get the position. In essentially all of these cases we cna find an analytical solution.\n", + "\n", + "\n", + "\n", + "## Air Resistance in One Dimension\n", + "\n", + "Air resistance tends to scale as the square of the velocity. This is\n", + "in contrast to many problems chosen for textbooks, where it is linear\n", + "in the velocity. The choice of a linear dependence is motivated by\n", + "mathematical simplicity (it keeps the differential equation linear)\n", + "rather than by physics. One can see that the force should be quadratic\n", + "in velocity by considering the momentum imparted on the air\n", + "molecules. If an object sweeps through a volume $dV$ of air in time\n", + "$dt$, the momentum imparted on the air is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "dP=\\rho_m dV v,\n", + "\\label{_auto1} \\tag{1}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $v$ is the velocity of the object and $\\rho_m$ is the mass\n", + "density of the air. If the molecules bounce back as opposed to stop\n", + "you would double the size of the term. The opposite value of the\n", + "momentum is imparted onto the object itself. Geometrically, the\n", + "differential volume is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "dV=Avdt,\n", + "\\label{_auto2} \\tag{2}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $A$ is the cross-sectional area and $vdt$ is the distance the\n", + "object moved in time $dt$.\n", + "\n", + "\n", + "## Resulting Acceleration\n", + "Plugging this into the expression above," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{dP}{dt}=-\\rho_m A v^2.\n", + "\\label{_auto3} \\tag{3}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is the force felt by the particle, and is opposite to its\n", + "direction of motion. Now, because air doesn't stop when it hits an\n", + "object, but flows around the best it can, the actual force is reduced\n", + "by a dimensionless factor $c_W$, called the drag coefficient." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "F_{\\rm drag}=-c_W\\rho_m Av^2,\n", + "\\label{_auto4} \\tag{4}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and the acceleration is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{dv}{dt}=-\\frac{c_W\\rho_mA}{m}v^2.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For a particle with initial velocity $v_0$, one can separate the $dt$\n", + "to one side of the equation, and move everything with $v$s to the\n", + "other side. We did this in our discussion of simple motion and will not repeat it here.\n", + "\n", + "On more general terms,\n", + "for many systems, e.g. an automobile, there are multiple sources of\n", + "resistance. In addition to wind resistance, where the force is\n", + "proportional to $v^2$, there are dissipative effects of the tires on\n", + "the pavement, and in the axel and drive train. These other forces can\n", + "have components that scale proportional to $v$, and components that\n", + "are independent of $v$. Those independent of $v$, e.g. the usual\n", + "$f=\\mu_K N$ frictional force you consider in your first Physics courses, only set in\n", + "once the object is actually moving. As speeds become higher, the $v^2$\n", + "components begin to dominate relative to the others. For automobiles\n", + "at freeway speeds, the $v^2$ terms are largely responsible for the\n", + "loss of efficiency. To travel a distance $L$ at fixed speed $v$, the\n", + "energy/work required to overcome the dissipative forces are $fL$,\n", + "which for a force of the form $f=\\alpha v^n$ becomes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "W=\\int dx~f=\\alpha v^n L.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For $n=0$ the work is\n", + "independent of speed, but for the wind resistance, where $n=2$,\n", + "slowing down is essential if one wishes to reduce fuel consumption. It\n", + "is also important to consider that engines are designed to be most\n", + "efficient at a chosen range of power output. Thus, some cars will get\n", + "better mileage at higher speeds (They perform better at 50 mph than at\n", + "5 mph) despite the considerations mentioned above.\n", + "\n", + "\n", + "## Going Ballistic, Projectile Motion or a Softer Approach, Falling Raindrops\n", + "\n", + "\n", + "As an example of Newton's Laws we consider projectile motion (or a\n", + "falling raindrop or a ball we throw up in the air) with a drag force. Even though air resistance is\n", + "largely proportional to the square of the velocity, we will consider\n", + "the drag force to be linear to the velocity, $\\boldsymbol{F}=-m\\gamma\\boldsymbol{v}$,\n", + "for the purposes of this exercise. The acceleration for a projectile moving upwards,\n", + "$\\boldsymbol{a}=\\boldsymbol{F}/m$, becomes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{dv_x}{dt}=-\\gamma v_x,\\\\\n", + "\\nonumber\n", + "\\frac{dv_y}{dt}=-\\gamma v_y-g,\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and $\\gamma$ has dimensions of inverse time. \n", + "\n", + "If you on the other hand have a falling raindrop, how do these equations change? See for example Figure 2.1 in Taylor.\n", + "Let us stay with a ball which is thrown up in the air at $t=0$. \n", + "\n", + "\n", + "## Ways of solving these equations\n", + "\n", + "We will go over two different ways to solve this equation. The first\n", + "by direct integration, and the second as a differential equation. To\n", + "do this by direct integration, one simply multiplies both sides of the\n", + "equations above by $dt$, then divide by the appropriate factors so\n", + "that the $v$s are all on one side of the equation and the $dt$ is on\n", + "the other. For the $x$ motion one finds an easily integrable equation," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{dv_x}{v_x}&=&-\\gamma dt,\\\\\n", + "\\nonumber\n", + "\\int_{v_{0x}}^{v_{x}}\\frac{dv_x}{v_x}&=&-\\gamma\\int_0^{t}dt,\\\\\n", + "\\nonumber\n", + "\\ln\\left(\\frac{v_{x}}{v_{0x}}\\right)&=&-\\gamma t,\\\\\n", + "\\nonumber\n", + "v_{x}(t)&=&v_{0x}e^{-\\gamma t}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is very much the result you would have written down\n", + "by inspection. For the $y$-component of the velocity," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{dv_y}{v_y+g/\\gamma}&=&-\\gamma dt\\\\\n", + "\\nonumber\n", + "\\ln\\left(\\frac{v_{y}+g/\\gamma}{v_{0y}-g/\\gamma}\\right)&=&-\\gamma t_f,\\\\\n", + "\\nonumber\n", + "v_{fy}&=&-\\frac{g}{\\gamma}+\\left(v_{0y}+\\frac{g}{\\gamma}\\right)e^{-\\gamma t}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Whereas $v_x$ starts at some value and decays\n", + "exponentially to zero, $v_y$ decays exponentially to the terminal\n", + "velocity, $v_t=-g/\\gamma$.\n", + "\n", + "\n", + "## Solving as differential equations\n", + "\n", + "Although this direct integration is simpler than the method we invoke\n", + "below, the method below will come in useful for some slightly more\n", + "difficult differential equations in the future. The differential\n", + "equation for $v_x$ is straight-forward to solve. Because it is first\n", + "order there is one arbitrary constant, $A$, and by inspection the\n", + "solution is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_x=Ae^{-\\gamma t}.\n", + "\\label{_auto5} \\tag{5}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The arbitrary constants for equations of motion are usually determined\n", + "by the initial conditions, or more generally boundary conditions. By\n", + "inspection $A=v_{0x}$, the initial $x$ component of the velocity.\n", + "\n", + "\n", + "\n", + "## Differential Equations, contn\n", + "\n", + "The differential equation for $v_y$ is a bit more complicated due to\n", + "the presence of $g$. Differential equations where all the terms are\n", + "linearly proportional to a function, in this case $v_y$, or to\n", + "derivatives of the function, e.g., $v_y$, $dv_y/dt$,\n", + "$d^2v_y/dt^2\\cdots$, are called linear differential equations. If\n", + "there are terms proportional to $v^2$, as would happen if the drag\n", + "force were proportional to the square of the velocity, the\n", + "differential equation is not longer linear. Because this expression\n", + "has only one derivative in $v$ it is a first-order linear differential\n", + "equation. If a term were added proportional to $d^2v/dt^2$ it would be\n", + "a second-order differential equation. In this case we have a term\n", + "completely independent of $v$, the gravitational acceleration $g$, and\n", + "the usual strategy is to first rewrite the equation with all the\n", + "linear terms on one side of the equal sign," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{dv_y}{dt}+\\gamma v_y=-g.\n", + "\\label{_auto6} \\tag{6}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Splitting into two parts\n", + "\n", + "Now, the solution to the equation can be broken into two\n", + "parts. Because this is a first-order differential equation we know\n", + "that there will be one arbitrary constant. Physically, the arbitrary\n", + "constant will be determined by setting the initial velocity, though it\n", + "could be determined by setting the velocity at any given time. Like\n", + "most differential equations, solutions are not \"solved\". Instead,\n", + "one guesses at a form, then shows the guess is correct. For these\n", + "types of equations, one first tries to find a single solution,\n", + "i.e. one with no arbitrary constants. This is called the {\\it\n", + "particular} solution, $y_p(t)$, though it should really be called\n", + "\"a\" particular solution because there are an infinite number of such\n", + "solutions. One then finds a solution to the {\\it homogenous} equation,\n", + "which is the equation with zero on the right-hand side," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{dv_{y,h}}{dt}+\\gamma v_{y,h}=0.\n", + "\\label{_auto7} \\tag{7}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Homogenous solutions will have arbitrary constants. \n", + "\n", + "The particular solution will solve the same equation as the original\n", + "general equation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{dv_{y,p}}{dt}+\\gamma v_{y,p}=-g.\n", + "\\label{_auto8} \\tag{8}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "However, we don't need find one with arbitrary constants. Hence, it is\n", + "called a **particular** solution.\n", + "\n", + "The sum of the two," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_y=v_{y,p}+v_{y,h},\n", + "\\label{_auto9} \\tag{9}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "is a solution of the total equation because of the linear nature of\n", + "the differential equation. One has now found a *general* solution\n", + "encompassing all solutions, because it both satisfies the general\n", + "equation (like the particular solution), and has an arbitrary constant\n", + "that can be adjusted to fit any initial condition (like the homogneous\n", + "solution). If the equation were not linear, e.g if there were a term\n", + "such as $v_y^2$ or $v_y\\dot{v}_y$, this technique would not work.\n", + "\n", + "\n", + "## More details\n", + "\n", + "Returning to the example above, the homogenous solution is the same as\n", + "that for $v_x$, because there was no gravitational acceleration in\n", + "that case," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_{y,h}=Be^{-\\gamma t}.\n", + "\\label{_auto10} \\tag{10}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this case a particular solution is one with constant velocity," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_{y,p}=-g/\\gamma.\n", + "\\label{_auto11} \\tag{11}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that this is the terminal velocity of a particle falling from a\n", + "great height. The general solution is thus," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_y=Be^{-\\gamma t}-g/\\gamma,\n", + "\\label{_auto12} \\tag{12}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and one can find $B$ from the initial velocity," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_{0y}=B-g/\\gamma,~~~B=v_{0y}+g/\\gamma.\n", + "\\label{_auto13} \\tag{13}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plugging in the expression for $B$ gives the $y$ motion given the initial velocity," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_y=(v_{0y}+g/\\gamma)e^{-\\gamma t}-g/\\gamma.\n", + "\\label{_auto14} \\tag{14}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is easy to see that this solution has $v_y=v_{0y}$ when $t=0$ and\n", + "$v_y=-g/\\gamma$ when $t\\rightarrow\\infty$.\n", + "\n", + "One can also integrate the two equations to find the coordinates $x$\n", + "and $y$ as functions of $t$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x&=&\\int_0^t dt'~v_{0x}(t')=\\frac{v_{0x}}{\\gamma}\\left(1-e^{-\\gamma t}\\right),\\\\\n", + "\\nonumber\n", + "y&=&\\int_0^t dt'~v_{0y}(t')=-\\frac{gt}{\\gamma}+\\frac{v_{0y}+g/\\gamma}{\\gamma}\\left(1-e^{-\\gamma t}\\right).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the question was to find the position at a time $t$, we would be\n", + "finished. However, the more common goal in a projectile equation\n", + "problem is to find the range, i.e. the distance $x$ at which $y$\n", + "returns to zero. For the case without a drag force this was much\n", + "simpler. The solution for the $y$ coordinate would have been\n", + "$y=v_{0y}t-gt^2/2$. One would solve for $t$ to make $y=0$, which would\n", + "be $t=2v_{0y}/g$, then plug that value for $t$ into $x=v_{0x}t$ to\n", + "find $x=2v_{0x}v_{0y}/g=v_0\\sin(2\\theta_0)/g$. One follows the same\n", + "steps here, except that the expression for $y(t)$ is more\n", + "complicated. Searching for the time where $y=0$, and we get" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "0=-\\frac{gt}{\\gamma}+\\frac{v_{0y}+g/\\gamma}{\\gamma}\\left(1-e^{-\\gamma t}\\right).\n", + "\\label{_auto15} \\tag{15}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This cannot be inverted into a simple expression $t=\\cdots$. Such\n", + "expressions are known as \"transcendental equations\", and are not the\n", + "rare instance, but are the norm. In the days before computers, one\n", + "might plot the right-hand side of the above graphically as\n", + "a function of time, then find the point where it crosses zero.\n", + "\n", + "Now, the most common way to solve for an equation of the above type\n", + "would be to apply Newton's method numerically. This involves the\n", + "following algorithm for finding solutions of some equation $F(t)=0$.\n", + "\n", + "1. First guess a value for the time, $t_{\\rm guess}$.\n", + "\n", + "2. Calculate $F$ and its derivative, $F(t_{\\rm guess})$ and $F'(t_{\\rm guess})$. \n", + "\n", + "3. Unless you guessed perfectly, $F\\ne 0$, and assuming that $\\Delta F\\approx F'\\Delta t$, one would choose \n", + "\n", + "4. $\\Delta t=-F(t_{\\rm guess})/F'(t_{\\rm guess})$.\n", + "\n", + "5. Now repeat step 1, but with $t_{\\rm guess}\\rightarrow t_{\\rm guess}+\\Delta t$.\n", + "\n", + "If the $F(t)$ were perfectly linear in $t$, one would find $t$ in one\n", + "step. Instead, one typically finds a value of $t$ that is closer to\n", + "the final answer than $t_{\\rm guess}$. One breaks the loop once one\n", + "finds $F$ within some acceptable tolerance of zero. A program to do\n", + "this will be added shortly.\n", + "\n", + "\n", + "## Motion in a Magnetic Field\n", + "\n", + "\n", + "Another example of a velocity-dependent force is magnetism," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\boldsymbol{F}&=&q\\boldsymbol{v}\\times\\boldsymbol{B},\\\\\n", + "\\nonumber\n", + "F_i&=&q\\sum_{jk}\\epsilon_{ijk}v_jB_k.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For a uniform field in the $z$ direction $\\boldsymbol{B}=B\\hat{z}$, the force can only have $x$ and $y$ components," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "F_x&=&qBv_y\\\\\n", + "\\nonumber\n", + "F_y&=&-qBv_x.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The differential equations are" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\dot{v}_x&=&\\omega_c v_y,\\omega_c= qB/m\\\\\n", + "\\nonumber\n", + "\\dot{v}_y&=&-\\omega_c v_x.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One can solve the equations by taking time derivatives of either equation, then substituting into the other equation," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\ddot{v}_x=\\omega_c\\dot{v_y}=-\\omega_c^2v_x,\\\\\n", + "\\nonumber\n", + "\\ddot{v}_y&=&-\\omega_c\\dot{v}_x=-\\omega_cv_y.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The solution to these equations can be seen by inspection," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "v_x&=&A\\sin(\\omega_ct+\\phi),\\\\\n", + "\\nonumber\n", + "v_y&=&A\\cos(\\omega_ct+\\phi).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One can integrate the equations to find the positions as a function of time," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x-x_0&=&\\int_{x_0}^x dx=\\int_0^t dt v(t)\\\\\n", + "\\nonumber\n", + "&=&\\frac{-A}{\\omega_c}\\cos(\\omega_ct+\\phi),\\\\\n", + "\\nonumber\n", + "y-y_0&=&\\frac{A}{\\omega_c}\\sin(\\omega_ct+\\phi).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The trajectory is a circle centered at $x_0,y_0$ with amplitude $A$ rotating in the clockwise direction.\n", + "\n", + "The equations of motion for the $z$ motion are" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\dot{v_z}=0,\n", + "\\label{_auto16} \\tag{16}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which leads to" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "z-z_0=V_zt.\n", + "\\label{_auto17} \\tag{17}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Added onto the circle, the motion is helical.\n", + "\n", + "Note that the kinetic energy," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "T=\\frac{1}{2}m(v_x^2+v_y^2+v_z^2)=\\frac{1}{2}m(\\omega_c^2A^2+V_z^2),\n", + "\\label{_auto18} \\tag{18}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "is constant. This is because the force is perpendicular to the\n", + "velocity, so that in any differential time element $dt$ the work done\n", + "on the particle $\\boldsymbol{F}\\cdot{dr}=dt\\boldsymbol{F}\\cdot{v}=0$.\n", + "\n", + "One should think about the implications of a velocity dependent\n", + "force. Suppose one had a constant magnetic field in deep space. If a\n", + "particle came through with velocity $v_0$, it would undergo cyclotron\n", + "motion with radius $R=v_0/\\omega_c$. However, if it were still its\n", + "motion would remain fixed. Now, suppose an observer looked at the\n", + "particle in one reference frame where the particle was moving, then\n", + "changed their velocity so that the particle's velocity appeared to be\n", + "zero. The motion would change from circular to fixed. Is this\n", + "possible?\n", + "\n", + "The solution to the puzzle above relies on understanding\n", + "relativity. Imagine that the first observer believes $\\boldsymbol{B}\\ne 0$ and\n", + "that the electric field $\\boldsymbol{E}=0$. If the observer then changes\n", + "reference frames by accelerating to a velocity $\\boldsymbol{v}$, in the new\n", + "frame $\\boldsymbol{B}$ and $\\boldsymbol{E}$ both change. If the observer moved to the\n", + "frame where the charge, originally moving with a small velocity $v$,\n", + "is now at rest, the new electric field is indeed $\\boldsymbol{v}\\times\\boldsymbol{B}$,\n", + "which then leads to the same acceleration as one had before. If the\n", + "velocity is not small compared to the speed of light, additional\n", + "$\\gamma$ factors come into play,\n", + "$\\gamma=1/\\sqrt{1-(v/c)^2}$. Relativistic motion will not be\n", + "considered in this course.\n", + "\n", + "\n", + "\n", + "\n", + "## Sliding Block tied to a Wall\n", + "\n", + "Another classical case is that of simple harmonic oscillations, here represented by a block sliding on a horizontal frictionless surface. The block is tied to a wall with a spring. If the spring is not compressed or stretched too far, the force on the block at a given position $x$ is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "F=-kx.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The negative sign means that the force acts to restore the object to an equilibrium position. Newton's equation of motion for this idealized system is then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\frac{d^2x}{dt^2}=-kx,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or we could rephrase it as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\frac{d^2x}{dt^2}=-\\frac{k}{m}x=-\\omega_0^2x,\n", + "\\label{eq:newton1} \\tag{19}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with the angular frequency $\\omega_0^2=k/m$. \n", + "\n", + "The above differential equation has the advantage that it can be solved analytically with solutions on the form" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "x(t)=Acos(\\omega_0t+\\nu),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $A$ is the amplitude and $\\nu$ the phase constant. This provides in turn an important test for the numerical\n", + "solution and the development of a program for more complicated cases which cannot be solved analytically. \n", + "\n", + "\n", + "With the position $x(t)$ and the velocity $v(t)=dx/dt$ we can reformulate Newton's equation in the following way" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{dx(t)}{dt}=v(t),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{dv(t)}{dt}=-\\omega_0^2x(t).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We are now going to solve these equations using first the standard forward Euler method. Later we will try to improve upon this.\n", + "\n", + "\n", + "Before proceeding however, it is important to note that in addition to the exact solution, we have at least two further tests which can be used to check our solution. \n", + "\n", + "Since functions like $cos$ are periodic with a period $2\\pi$, then the solution $x(t)$ has also to be periodic. This means that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "x(t+T)=x(t),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with $T$ the period defined as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "T=\\frac{2\\pi}{\\omega_0}=\\frac{2\\pi}{\\sqrt{k/m}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Observe that $T$ depends only on $k/m$ and not on the amplitude of the solution. \n", + "\n", + "\n", + "In addition to the periodicity test, the total energy has also to be conserved. \n", + "\n", + "Suppose we choose the initial conditions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "x(t=0)=1\\hspace{0.1cm} \\mathrm{m}\\hspace{1cm} v(t=0)=0\\hspace{0.1cm}\\mathrm{m/s},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "meaning that block is at rest at $t=0$ but with a potential energy" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "E_0=\\frac{1}{2}kx(t=0)^2=\\frac{1}{2}k.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The total energy at any time $t$ has however to be conserved, meaning that our solution has to fulfil the condition" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "E_0=\\frac{1}{2}kx(t)^2+\\frac{1}{2}mv(t)^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will derive this equation in our discussion on [energy conservation](https://mhjensen.github.io/Physics321/doc/pub/energyconserv/html/energyconserv.html).\n", + "\n", + "\n", + "An algorithm which implements these equations is included below.\n", + " * Choose the initial position and speed, with the most common choice $v(t=0)=0$ and some fixed value for the position. \n", + "\n", + " * Choose the method you wish to employ in solving the problem.\n", + "\n", + " * Subdivide the time interval $[t_i,t_f] $ into a grid with step size" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "h=\\frac{t_f-t_i}{N},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $N$ is the number of mesh points. \n", + " * Calculate now the total energy given by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "E_0=\\frac{1}{2}kx(t=0)^2=\\frac{1}{2}k.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Choose ODE solver to obtain $x_{i+1}$ and $v_{i+1}$ starting from the previous values $x_i$ and $v_i$.\n", + "\n", + " * When we have computed $x(v)_{i+1}$ we upgrade $t_{i+1}=t_i+h$.\n", + "\n", + " * This iterative process continues till we reach the maximum time $t_f$.\n", + "\n", + " * The results are checked against the exact solution. Furthermore, one has to check the stability of the numerical solution against the chosen number of mesh points $N$. \n", + "\n", + "The following python program ( code will be added shortly)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#\n", + "# This program solves Newtons equation for a block sliding on\n", + "# an horizontal frictionless surface.\n", + "# The block is tied to the wall with a spring, so N's eq takes the form:\n", + "#\n", + "# m d^2x/dt^2 = - kx\n", + "#\n", + "# In order to make the solution dimless, we set k/m = 1.\n", + "# This results in two coupled diff. eq's that may be written as:\n", + "#\n", + "# dx/dt = v\n", + "# dv/dt = -x\n", + "#\n", + "# The user has to specify the initial velocity and position,\n", + "# and the number of steps. The time interval is fixed to\n", + "# t \\in [0, 4\\pi) (two periods)\n", + "#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The classical pendulum and scaling the equations\n", + "\n", + "The angular equation of motion of the pendulum is given by\n", + "Newton's equation and with no external force it reads" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " ml\\frac{d^2\\theta}{dt^2}+mgsin(\\theta)=0,\n", + "\\label{_auto19} \\tag{20}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with an angular velocity and acceleration given by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " v=l\\frac{d\\theta}{dt},\n", + "\\label{_auto20} \\tag{21}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " a=l\\frac{d^2\\theta}{dt^2}.\n", + "\\label{_auto21} \\tag{22}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## More on the Pendulum\n", + "\n", + "We do however expect that the motion will gradually come to an end due a viscous drag torque acting on the pendulum. \n", + "In the presence of the drag, the above equation becomes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " ml\\frac{d^2\\theta}{dt^2}+\\nu\\frac{d\\theta}{dt} +mgsin(\\theta)=0, \\label{eq:pend1} \\tag{23}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\nu$ is now a positive constant parameterizing the viscosity\n", + "of the medium in question. In order to maintain the motion against\n", + "viscosity, it is necessary to add some external driving force. \n", + "We choose here a periodic driving force. The last equation becomes then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " ml\\frac{d^2\\theta}{dt^2}+\\nu\\frac{d\\theta}{dt} +mgsin(\\theta)=Asin(\\omega t), \\label{eq:pend2} \\tag{24}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with $A$ and $\\omega$ two constants representing the amplitude and \n", + "the angular frequency respectively. The latter is called the driving frequency.\n", + "\n", + "\n", + "\n", + "\n", + "## More on the Pendulum\n", + "\n", + "We define" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\omega_0=\\sqrt{g/l},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "the so-called natural frequency and the new dimensionless quantities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\hat{t}=\\omega_0t,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with the dimensionless driving frequency" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\hat{\\omega}=\\frac{\\omega}{\\omega_0},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and introducing the quantity $Q$, called the *quality factor*," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "Q=\\frac{mg}{\\omega_0\\nu},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and the dimensionless amplitude" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\hat{A}=\\frac{A}{mg}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2\\theta}{d\\hat{t}^2}+\\frac{1}{Q}\\frac{d\\theta}{d\\hat{t}} \n", + " +sin(\\theta)=\\hat{A}cos(\\hat{\\omega}\\hat{t}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This equation can in turn be recast in terms of two coupled first-order differential equations as follows" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d\\theta}{d\\hat{t}}=\\hat{v},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d\\hat{v}}{d\\hat{t}}=-\\frac{\\hat{v}}{Q}-sin(\\theta)+\\hat{A}cos(\\hat{\\omega}\\hat{t}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "These are the equations to be solved. The factor $Q$ represents the number of oscillations of the undriven system that must occur before its energy is significantly reduced due to the viscous drag. The amplitude $\\hat{A}$ is measured in units of the maximum possible gravitational torque while $\\hat{\\omega}$ is the angular frequency of the external torque measured in units of the pendulum's natural frequency." + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/chapter4.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter4.ipynb new file mode 100644 index 000000000..923069801 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter4.ipynb @@ -0,0 +1,2409 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Work, Energy, Momentum and Conservation laws\n", + "\n", + "Energy conservation is most convenient as a strategy for addressing\n", + "problems where time does not appear. For example, a particle goes\n", + "from position $x_0$ with speed $v_0$, to position $x_f$; what is its\n", + "new speed? However, it can also be applied to problems where time\n", + "does appear, such as in solving for the trajectory $x(t)$, or\n", + "equivalently $t(x)$.\n", + "\n", + "\n", + "\n", + "## Work and Energy\n", + "\n", + "Material to be added here.\n", + "\n", + "\n", + "\n", + "## Energy Conservation\n", + "Energy is conserved in the case where the potential energy, $V(\\boldsymbol{r})$, depends only on position, and not on time. The force is determined by $V$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\boldsymbol{F}(\\boldsymbol{r})=-\\nabla V(\\boldsymbol{r}).\n", + "\\label{_auto1} \\tag{1}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The net energy, $E=V+K$ where $K$ is the kinetic energy, is then conserved," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{d}{dt}(K+V)&=&\\frac{d}{dt}\\left(\\frac{m}{2}(v_x^2+v_y^2+v_z^2)+V(\\boldsymbol{r})\\right)\\\\\n", + "\\nonumber\n", + "&=&m\\left(v_x\\frac{dv_x}{dt}+v_y\\frac{dv_y}{dt}+v_z\\frac{dv_z}{dt}\\right)\n", + "+\\partial_xV\\frac{dx}{dt}+\\partial_yV\\frac{dy}{dt}+\\partial_zV\\frac{dz}{dt}\\\\\n", + "\\nonumber\n", + "&=&v_xF_x+v_yF_y+v_zF_z-F_xv_x-F_yv_y-F_zv_z=0.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The same proof can be written more compactly with vector notation," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{d}{dt}\\left(\\frac{m}{2}v^2+V(\\boldsymbol{r})\\right)\n", + "&=&m\\boldsymbol{v}\\cdot\\dot{\\boldsymbol{v}}+\\nabla V(\\boldsymbol{r})\\cdot\\dot{\\boldsymbol{r}}\\\\\n", + "\\nonumber\n", + "&=&\\boldsymbol{v}\\cdot\\boldsymbol{F}-\\boldsymbol{F}\\cdot\\boldsymbol{v}=0.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Inverting the expression for kinetic energy," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v=\\sqrt{2K/m}=\\sqrt{2(E-V)/m},\n", + "\\label{_auto2} \\tag{2}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "allows one to solve for the one-dimensional trajectory $x(t)$, by finding $t(x)$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "t=\\int_{x_0}^x \\frac{dx'}{v(x')}=\\int_{x_0}^x\\frac{dx'}{\\sqrt{2(E-V(x'))/m}}.\n", + "\\label{_auto3} \\tag{3}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note this would be much more difficult in higher dimensions, because\n", + "you would have to determine which points, $x,y,z$, the particles might\n", + "reach in the trajectory, whereas in one dimension you can typically\n", + "tell by simply seeing whether the kinetic energy is positive at every\n", + "point between the old position and the new position.\n", + "\n", + "\n", + "Consider a simple harmonic oscillator potential, $V(x)=kx^2/2$, with a particle emitted from $x=0$ with velocity $v_0$. Solve for the trajectory $t(x)$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "t&=&\\int_{0}^x \\frac{dx'}{\\sqrt{2(E-kx^2/2)/m}}\\\\\n", + "\\nonumber\n", + "&=&\\sqrt{m/k}\\int_0^x~\\frac{dx'}{\\sqrt{x_{\\rm max}^2-x^{\\prime 2}}},~~~x_{\\rm max}^2=2E/k.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here $E=mv_0^2/2$ and $x_{\\rm max}$ is defined as the maximum\n", + "displacement before the particle turns around. This integral is done\n", + "by the substitution $\\sin\\theta=x/x_{\\rm max}$." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "(k/m)^{1/2}t&=&\\sin^{-1}(x/x_{\\rm max}),\\\\\n", + "\\nonumber\n", + "x&=&x_{\\rm max}\\sin\\omega t,~~~\\omega=\\sqrt{k/m}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Conservation of Momentum\n", + "\n", + "\n", + "Newton's third law which we met earlier states that **For every action there is an equal and opposite reaction**, is more accurately stated as\n", + "**If two bodies exert forces on each other, these forces are equal in magnitude and opposite in direction**.\n", + "\n", + "This means that for two bodies $i$ and $j$, if the force on $i$ due to $j$ is called $\\boldsymbol{F}_{ij}$, then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\boldsymbol{F}_{ij}=-\\boldsymbol{F}_{ji}. \n", + "\\label{_auto4} \\tag{4}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Newton's second law, $\\boldsymbol{F}=m\\boldsymbol{a}$, can be written for a particle $i$ as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\boldsymbol{F}_i=\\sum_{j\\ne i} \\boldsymbol{F}_{ij}=m_i\\boldsymbol{a}_i,\n", + "\\label{_auto5} \\tag{5}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\boldsymbol{F}_i$ (a single subscript) denotes the net force acting on $i$. Because the mass of $i$ is fixed, one can see that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\boldsymbol{F}_i=\\frac{d}{dt}m_i\\boldsymbol{v}_i=\\sum_{j\\ne i}\\boldsymbol{F}_{ij}.\n", + "\\label{_auto6} \\tag{6}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, one can sum over all the particles and obtain" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{d}{dt}\\sum_i m_iv_i&=&\\sum_{ij, i\\ne j}\\boldsymbol{F}_{ij}\\\\\n", + "\\nonumber\n", + "&=&0.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The last step made use of the fact that for every term $ij$, there is\n", + "an equivalent term $ji$ with opposite force. Because the momentum is\n", + "defined as $m\\boldsymbol{v}$, for a system of particles," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{d}{dt}\\sum_im_i\\boldsymbol{v}_i=0,~~{\\rm for~isolated~particles}.\n", + "\\label{_auto7} \\tag{7}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "By \"isolated\" one means that the only force acting on any particle $i$\n", + "are those originating from other particles in the sum, i.e. \"no\n", + "external\" forces. Thus, Newton's third law leads to the conservation\n", + "of total momentum," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\boldsymbol{P}&=&\\sum_i m_i\\boldsymbol{v}_i,\\\\\n", + "\\nonumber\n", + "\\frac{d}{dt}\\boldsymbol{P}&=&0.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Consider the rocket of mass $M$ moving with velocity $v$. After a\n", + "brief instant, the velocity of the rocket is $v+\\Delta v$ and the mass\n", + "is $M-\\Delta M$. Momentum conservation gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "Mv&=&(M-\\Delta M)(v+\\Delta v)+\\Delta M(v-v_e)\\\\\n", + "0&=&-\\Delta Mv+M\\Delta v+\\Delta M(v-v_e),\\\\\n", + "0&=&M\\Delta v-\\Delta Mv_e.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the second step we ignored the term $\\Delta M\\Delta v$ because it is doubly small. The last equation gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\Delta v&=&\\frac{v_e}{M}\\Delta M,\\\\\n", + "\\nonumber\n", + "\\frac{dv}{dt}&=&\\frac{v_e}{M}\\frac{dM}{dt}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Integrating the expression with lower limits $v_0=0$ and $M_0$, one finds" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "v&=&v_e\\int_{M_0}^M \\frac{dM'}{M'}\\\\\n", + "v&=&-v_e\\ln(M/M_0)\\\\\n", + "&=&-v_e\\ln[(M_0-\\alpha t)/M_0].\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Because the total momentum of an isolated system is constant, one can\n", + "also quickly see that the center of mass of an isolated system is also\n", + "constant. The center of mass is the average position of a set of\n", + "masses weighted by the mass," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\bar{x}=\\frac{\\sum_im_ix_i}{\\sum_i m_i}.\n", + "\\label{_auto8} \\tag{8}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The rate of change of $\\bar{x}$ is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\dot{\\bar{x}}&=&\\frac{1}{M}\\sum_i m_i\\dot{x}_i=\\frac{1}{M}P_x.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thus if the total momentum is constant the center of mass moves at a\n", + "constant velocity, and if the total momentum is zero the center of\n", + "mass is fixed.\n", + "\n", + "\n", + "\n", + "## Conservation of Angular Momentum\n", + "\n", + "\n", + "Consider a case where the force always points radially," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\boldsymbol{F}(\\boldsymbol{r})=F(r)\\hat{r},\n", + "\\label{_auto9} \\tag{9}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\hat{r}$ is a unit vector pointing outward from the origin. The angular momentum is defined as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\boldsymbol{L}=\\boldsymbol{r}\\times\\boldsymbol{p}=m\\boldsymbol{r}\\times\\boldsymbol{v}.\n", + "\\label{_auto10} \\tag{10}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The rate of change of the angular momentum is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{d\\boldsymbol{L}}{dt}&=&m\\boldsymbol{v}\\times\\boldsymbol{v}+m\\boldsymbol{r}\\times\\dot{\\boldsymbol{v}}\\\\\n", + "\\nonumber\n", + "&=&m\\boldsymbol{v}\\times\\boldsymbol{v}+\\boldsymbol{r}\\times{\\boldsymbol{F}}=0.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The first term is zero because $\\boldsymbol{v}$ is parallel to itself, and the\n", + "second term is zero because $\\boldsymbol{F}$ is parallel to $\\boldsymbol{r}$.\n", + "\n", + "As an aside, one can see from the Levi-Civita symbol that the cross\n", + "product of a vector with itself is zero. Here, we consider a vector" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\boldsymbol{V}&=&\\boldsymbol{A}\\times\\boldsymbol{A},\\\\\n", + "\\nonumber\n", + "V_i&=&(\\boldsymbol{A}\\times\\boldsymbol{A})_i=\\sum_{jk}\\epsilon_{ijk}A_jA_k.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For any term $i$, there are two contributions. For example, for $i$\n", + "denoting the $x$ direction, either $j$ denotes the $y$ direction and\n", + "$k$ denotes the $z$ direction, or vice versa, so" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "V_1=\\epsilon_{123}A_2A_3+\\epsilon_{132}A_3A_2.\n", + "\\label{_auto11} \\tag{11}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is zero by the antisymmetry of $\\epsilon$ under permutations.\n", + "\n", + "If the force is not radial, $\\boldsymbol{r}\\times\\boldsymbol{F}\\ne 0$ as above, and angular momentum is no longer conserved," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{d\\boldsymbol{L}}{dt}=\\boldsymbol{r}\\times\\boldsymbol{F}\\equiv\\boldsymbol{\\tau},\n", + "\\label{_auto12} \\tag{12}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\boldsymbol{\\tau}$ is the torque.\n", + "\n", + "For a system of isolated particles, one can write" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{d}{dt}\\sum_i\\boldsymbol{L}_i&=&\\sum_{i\\ne j}\\boldsymbol{r}_i\\times \\boldsymbol{F}_{ij}\\\\\n", + "\\nonumber\n", + "&=&\\frac{1}{2}\\sum_{i\\ne j} \\boldsymbol{r}_i\\times \\boldsymbol{F}_{ij}+\\boldsymbol{r}_j\\times\\boldsymbol{F}_{ji}\\\\\n", + "\\nonumber\n", + "&=&\\frac{1}{2}\\sum_{i\\ne j} (\\boldsymbol{r}_i-\\boldsymbol{r}_j)\\times\\boldsymbol{F}_{ij}=0,\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where the last step used Newton's third law,\n", + "$\\boldsymbol{F}_{ij}=-\\boldsymbol{F}_{ji}$. If the forces between the particles are\n", + "radial, i.e. $\\boldsymbol{F}_{ij} ~||~ (\\boldsymbol{r}_i-\\boldsymbol{r}_j)$, then each term in\n", + "the sum is zero and the net angular momentum is fixed. Otherwise, you\n", + "could imagine an isolated system that would start spinning\n", + "spontaneously.\n", + "\n", + "One can write the torque about a given axis, which we will denote as $\\hat{z}$, in polar coordinates, where" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x&=&r\\sin\\theta\\cos\\phi,~~y=r\\sin\\theta\\cos\\phi,~~z=r\\cos\\theta,\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "to find the $z$ component of the torque," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\tau_z&=&xF_y-yF_x\\\\\n", + "\\nonumber\n", + "&=&-r\\sin\\theta\\left\\{\\cos\\phi \\partial_y-\\sin\\phi \\partial_x\\right\\}V(x,y,z).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One can use the chain rule to write the partial derivative w.r.t. $\\phi$ (keeping $r$ and $\\theta$ fixed)," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\partial_\\phi&=&\\frac{\\partial x}{\\partial\\phi}\\partial_x+\\frac{\\partial_y}{\\partial\\phi}\\partial_y\n", + "+\\frac{\\partial z}{\\partial\\phi}\\partial_z\\\\\n", + "\\nonumber\n", + "&=&-r\\sin\\theta\\sin\\phi\\partial_x+\\sin\\theta\\cos\\phi\\partial_y.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Combining the two equations," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\tau_z&=&-\\partial_\\phi V(r,\\theta,\\phi).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thus, if the potential is independent of the azimuthal angle $\\phi$,\n", + "there is no torque about the $z$ axis and $L_z$ is conserved.\n", + "\n", + "\n", + "\n", + "## Symmetries and Conservation Laws\n", + "\n", + "When we derived the conservation of energy, we assumed that the\n", + "potential depended only on position, not on time. If it depended\n", + "explicitly on time, one can quickly see that the energy would have\n", + "changed at a rate $\\partial_tV(x,y,z,t)$. Note that if there is no\n", + "explicit dependence on time, i.e. $V(x,y,z)$, the potential energy can\n", + "depend on time through the variations of $x,y,z$ with time. However,\n", + "that variation does not lead to energy non-conservation. Further, we\n", + "just saw that if a potential does not depend on the azimuthal angle\n", + "about some axis, $\\phi$, that the angular momentum about that axis is\n", + "conserved.\n", + "\n", + "Now, we relate momentum conservation to translational\n", + "invariance. Considering a system of particles with positions,\n", + "$\\boldsymbol{r}_i$, if one changed the coordinate system by a translation by a\n", + "differential distance $\\boldsymbol{\\epsilon}$, the net potential would change\n", + "by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\delta V(\\boldsymbol{r}_1,\\boldsymbol{r}_2\\cdots)&=&\\sum_i \\boldsymbol{\\epsilon}\\cdot\\nabla_i V(\\boldsymbol{r}_1,\\boldsymbol{r}_2,\\cdots)\\\\\n", + "\\nonumber\n", + "&=&-\\sum_i \\boldsymbol{\\epsilon}\\cdot\\boldsymbol{F}_i\\\\\n", + "\\nonumber\n", + "&=&-\\frac{d}{dt}\\sum_i \\boldsymbol{\\epsilon}\\cdot\\boldsymbol{p}_i.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thus, if the potential is unchanged by a translation of the coordinate\n", + "system, the total momentum is conserved. If the potential is\n", + "translationally invariant in a given direction, defined by a unit\n", + "vector, $\\hat{\\epsilon}$ in the $\\boldsymbol{\\epsilon}$ direction, one can see\n", + "that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\hat{\\epsilon}\\cdot\\nabla_i V(\\boldsymbol{r}_i)&=&0.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The component of the total momentum along that axis is conserved. This\n", + "is rather obvious for a single particle. If $V(\\boldsymbol{r})$ does not\n", + "depend on some coordinate $x$, then the force in the $x$ direction is\n", + "$F_x=-\\partial_xV=0$, and momentum along the $x$ direction is\n", + "constant.\n", + "\n", + "We showed how the total momentum of an isolated system of particle was conserved, even if the particles feel internal forces in all directions. In that case the potential energy could be written" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "V=\\sum_{i,j\\le i}V_{ij}(\\boldsymbol{r}_i-\\boldsymbol{r}_j).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this case, a translation leads to $\\boldsymbol{r}_i\\rightarrow\n", + "\\boldsymbol{r}_i+\\boldsymbol{\\epsilon}$, with the translation equally affecting the\n", + "coordinates of each particle. Because the potential depends only on\n", + "the relative coordinates, $\\delta V$ is manifestly zero. If one were\n", + "to go through the exercise of calculating $\\delta V$ for small\n", + "$\\boldsymbol{\\epsilon}$, one would find that the term\n", + "$\\nabla_i V(\\boldsymbol{r}_i-\\boldsymbol{r}_j)$ would be canceled by the term\n", + "$\\nabla_jV(\\boldsymbol{r}_i-\\boldsymbol{r}_j)$.\n", + "\n", + "The relation between symmetries of the potential and conserved\n", + "quantities (also called constants of motion) is one of the most\n", + "profound concepts one should gain from this course. It plays a\n", + "critical role in all fields of physics. This is especially true in\n", + "quantum mechanics, where a quantity $A$ is conserved if its operator\n", + "commutes with the Hamiltonian. For example if the momentum operator\n", + "$-i\\hbar\\partial_x$ commutes with the Hamiltonian, momentum is\n", + "conserved, and clearly this operator commutes if the Hamiltonian\n", + "(which represents the total energy, not just the potential) does not\n", + "depend on $x$. Also in quantum mechanics the angular momentum operator\n", + "is $L_z=-i\\hbar\\partial_\\phi$. In fact, if the potential is unchanged\n", + "by rotations about some axis, angular momentum about that axis is\n", + "conserved. We return to this concept, from a more formal perspective,\n", + "later in the course when Lagrangian mechanics is presented.\n", + "\n", + "\n", + "## Bulding a code for the Earth-Sun system\n", + "\n", + "We will now venture into a study of a system which is energy\n", + "conserving. The aim is to see if we (since it is not possible to solve\n", + "the general equations analytically) we can develop stable numerical\n", + "algorithms whose results we can trust!\n", + "\n", + "We solve the equations of motion numerically. We will also compute\n", + "quantities like the energy numerically.\n", + "\n", + "We start with a simpler case first, the Earth-Sun system in two dimensions only. The gravitational force $F_G$ on the earth from the sun is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_G=-\\frac{GM_{\\odot}M_E}{r^3}\\boldsymbol{r},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $G$ is the gravitational constant," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "M_E=6\\times 10^{24}\\mathrm{Kg},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "the mass of Earth," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "M_{\\odot}=2\\times 10^{30}\\mathrm{Kg},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "the mass of the Sun and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "r=1.5\\times 10^{11}\\mathrm{m},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "is the distance between Earth and the Sun. The latter defines what we call an astronomical unit **AU**.\n", + "From Newton's second law we have then for the $x$ direction" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{dt^2}=-\\frac{F_{x}}{M_E},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2y}{dt^2}=-\\frac{F_{y}}{M_E},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "for the $y$ direction.\n", + "\n", + "Here we will use that $x=r\\cos{(\\theta)}$, $y=r\\sin{(\\theta)}$ and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "r = \\sqrt{x^2+y^2}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can rewrite" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "F_{x}=-\\frac{GM_{\\odot}M_E}{r^2}\\cos{(\\theta)}=-\\frac{GM_{\\odot}M_E}{r^3}x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "F_{y}=-\\frac{GM_{\\odot}M_E}{r^2}\\sin{(\\theta)}=-\\frac{GM_{\\odot}M_E}{r^3}y,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "for the $y$ direction.\n", + "\n", + "\n", + "We can rewrite these two equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "F_{x}=-\\frac{GM_{\\odot}M_E}{r^2}\\cos{(\\theta)}=-\\frac{GM_{\\odot}M_E}{r^3}x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "F_{y}=-\\frac{GM_{\\odot}M_E}{r^2}\\sin{(\\theta)}=-\\frac{GM_{\\odot}M_E}{r^3}y,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "as four first-order coupled differential equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4\n", + "3\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4\n", + "4\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4\n", + "5\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{dy}{dt}=v_y.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Building a code for the solar system, final coupled equations\n", + "\n", + "The four coupled differential equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4\n", + "7\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4\n", + "8\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4\n", + "9\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{dy}{dt}=v_y,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "can be turned into dimensionless equations or we can introduce astronomical units with $1$ AU = $1.5\\times 10^{11}$. \n", + "\n", + "Using the equations from circular motion (with $r =1\\mathrm{AU}$)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{M_E v^2}{r} = F = \\frac{GM_{\\odot}M_E}{r^2},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "GM_{\\odot}=v^2r,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and using that the velocity of Earth (assuming circular motion) is\n", + "$v = 2\\pi r/\\mathrm{yr}=2\\pi\\mathrm{AU}/\\mathrm{yr}$, we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "GM_{\\odot}= v^2r = 4\\pi^2 \\frac{(\\mathrm{AU})^3}{\\mathrm{yr}^2}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Building a code for the solar system, discretized equations\n", + "\n", + "The four coupled differential equations can then be discretized using Euler's method as (with step length $h$)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5\n", + "4\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5\n", + "5\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5\n", + "6\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y_{i+1}=y_i+hv_{y,i},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Code Example with Euler's Method\n", + "\n", + "The code here implements Euler's method for the Earth-Sun system using a more compact way of representing the vectors. Alternatively, you could have spelled out all the variables $v_x$, $v_y$, $x$ and $y$ as one-dimensional arrays." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "\n", + "# Common imports\n", + "import numpy as np\n", + "import pandas as pd\n", + "from math import *\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "\n", + "# Where to save the figures and data files\n", + "PROJECT_ROOT_DIR = \"Results\"\n", + "FIGURE_ID = \"Results/FigureFiles\"\n", + "DATA_ID = \"DataFiles/\"\n", + "\n", + "if not os.path.exists(PROJECT_ROOT_DIR):\n", + " os.mkdir(PROJECT_ROOT_DIR)\n", + "\n", + "if not os.path.exists(FIGURE_ID):\n", + " os.makedirs(FIGURE_ID)\n", + "\n", + "if not os.path.exists(DATA_ID):\n", + " os.makedirs(DATA_ID)\n", + "\n", + "def image_path(fig_id):\n", + " return os.path.join(FIGURE_ID, fig_id)\n", + "\n", + "def data_path(dat_id):\n", + " return os.path.join(DATA_ID, dat_id)\n", + "\n", + "def save_fig(fig_id):\n", + " plt.savefig(image_path(fig_id) + \".png\", format='png')\n", + "\n", + "\n", + "DeltaT = 0.001\n", + "#set up arrays \n", + "tfinal = 10 # in years\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, a, v, and x\n", + "t = np.zeros(n)\n", + "v = np.zeros((n,2))\n", + "r = np.zeros((n,2))\n", + "# Initial conditions as compact 2-dimensional arrays\n", + "r0 = np.array([1.0,0.0])\n", + "v0 = np.array([0.0,2*pi])\n", + "r[0] = r0\n", + "v[0] = v0\n", + "Fourpi2 = 4*pi*pi\n", + "# Start integrating using Euler's method\n", + "for i in range(n-1):\n", + " # Set up the acceleration\n", + " # Here you could have defined your own function for this\n", + " rabs = sqrt(sum(r[i]*r[i]))\n", + " a = -Fourpi2*r[i]/(rabs**3)\n", + " # update velocity, time and position using Euler's forward method\n", + " v[i+1] = v[i] + DeltaT*a\n", + " r[i+1] = r[i] + DeltaT*v[i]\n", + " t[i+1] = t[i] + DeltaT\n", + "# Plot position as function of time \n", + "fig, ax = plt.subplots()\n", + "#ax.set_xlim(0, tfinal)\n", + "ax.set_ylabel('x[m]')\n", + "ax.set_xlabel('y[m]')\n", + "ax.plot(r[:,0], r[:,1])\n", + "fig.tight_layout()\n", + "save_fig(\"EarthSunEuler\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Problems with Euler's Method\n", + "\n", + "We notice here that Euler's method doesn't give a stable orbit. It\n", + "means that we cannot trust Euler's method. In a deeper way, as we will\n", + "see in homework 5, Euler's method does not conserve energy. It is an\n", + "example of an integrator which is not\n", + "[symplectic](https://en.wikipedia.org/wiki/Symplectic_integrator).\n", + "\n", + "Here we present thus two methods, which with simple changes allow us to avoid these pitfalls. The simplest possible extension is the so-called Euler-Cromer method.\n", + "The changes we need to make to our code are indeed marginal here.\n", + "We need simply to replace" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + " r[i+1] = r[i] + DeltaT*v[i]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "in the above code with the velocity at the new time $t_{i+1}$" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + " r[i+1] = r[i] + DeltaT*v[i+1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "By this simple caveat we get stable orbits.\n", + "Below we derive the Euler-Cromer method as well as one of the most utlized algorithms for sovling the above type of problems, the so-called Velocity-Verlet method. \n", + "\n", + "\n", + "## Deriving the Euler-Cromer Method\n", + "\n", + "Let us repeat Euler's method.\n", + "We have a differential equation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "y'(t_i)=f(t_i,y_i) \n", + "\\label{_auto13} \\tag{13}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and if we truncate at the first derivative, we have from the Taylor expansion" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "y_{i+1}=y(t_i) + (\\Delta t) f(t_i,y_i) + O(\\Delta t^2), \\label{eq:euler} \\tag{14}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which when complemented with $t_{i+1}=t_i+\\Delta t$ forms\n", + "the algorithm for the well-known Euler method. \n", + "Note that at every step we make an approximation error\n", + "of the order of $O(\\Delta t^2)$, however the total error is the sum over all\n", + "steps $N=(b-a)/(\\Delta t)$ for $t\\in [a,b]$, yielding thus a global error which goes like\n", + "$NO(\\Delta t^2)\\approx O(\\Delta t)$. \n", + "\n", + "To make Euler's method more precise we can obviously\n", + "decrease $\\Delta t$ (increase $N$), but this can lead to loss of numerical precision.\n", + "Euler's method is not recommended for precision calculation,\n", + "although it is handy to use in order to get a first\n", + "view on how a solution may look like.\n", + "\n", + "Euler's method is asymmetric in time, since it uses information about the derivative at the beginning\n", + "of the time interval. This means that we evaluate the position at $y_1$ using the velocity\n", + "at $v_0$. A simple variation is to determine $x_{n+1}$ using the velocity at\n", + "$v_{n+1}$, that is (in a slightly more generalized form)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation} \n", + "y_{n+1}=y_{n}+ v_{n+1}+O(\\Delta t^2)\n", + "\\label{_auto14} \\tag{15}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v_{n+1}=v_{n}+(\\Delta t) a_{n}+O(\\Delta t^2).\n", + "\\label{_auto15} \\tag{16}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The acceleration $a_n$ is a function of $a_n(y_n, v_n, t_n)$ and needs to be evaluated\n", + "as well. This is the Euler-Cromer method.\n", + "\n", + "**Exercise**: go back to the above code with Euler's method and add the Euler-Cromer method. \n", + "\n", + "\n", + "\n", + "## Deriving the Velocity-Verlet Method\n", + "\n", + "Let us stay with $x$ (position) and $v$ (velocity) as the quantities we are interested in.\n", + "\n", + "We have the Taylor expansion for the position given by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "x_{i+1} = x_i+(\\Delta t)v_i+\\frac{(\\Delta t)^2}{2}a_i+O((\\Delta t)^3).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The corresponding expansion for the velocity is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v_{i+1} = v_i+(\\Delta t)a_i+\\frac{(\\Delta t)^2}{2}v^{(2)}_i+O((\\Delta t)^3).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Via Newton's second law we have normally an analytical expression for the derivative of the velocity, namely" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "a_i= \\frac{d^2 x}{dt^2}\\vert_{i}=\\frac{d v}{dt}\\vert_{i}= \\frac{F(x_i,v_i,t_i)}{m}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If we add to this the corresponding expansion for the derivative of the velocity" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v^{(1)}_{i+1} = a_{i+1}= a_i+(\\Delta t)v^{(2)}_i+O((\\Delta t)^2)=a_i+(\\Delta t)v^{(2)}_i+O((\\Delta t)^2),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and retain only terms up to the second derivative of the velocity since our error goes as $O(h^3)$, we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "(\\Delta t)v^{(2)}_i\\approx a_{i+1}-a_i.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can then rewrite the Taylor expansion for the velocity as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v_{i+1} = v_i+\\frac{(\\Delta t)}{2}\\left( a_{i+1}+a_{i}\\right)+O((\\Delta t)^3).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The velocity Verlet method\n", + "\n", + "Our final equations for the position and the velocity become then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "x_{i+1} = x_i+(\\Delta t)v_i+\\frac{(\\Delta t)^2}{2}a_{i}+O((\\Delta t)^3),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "v_{i+1} = v_i+\\frac{(\\Delta t)}{2}\\left(a_{i+1}+a_{i}\\right)+O((\\Delta t)^3).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note well that the term $a_{i+1}$ depends on the position at $x_{i+1}$. This means that you need to calculate \n", + "the position at the updated time $t_{i+1}$ before the computing the next velocity. Note also that the derivative of the velocity at the time\n", + "$t_i$ used in the updating of the position can be reused in the calculation of the velocity update as well. \n", + "\n", + "\n", + "\n", + "## Adding the Velocity-Verlet Method\n", + "\n", + "We can now easily add the Verlet method to our original code as" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "DeltaT = 0.01\n", + "#set up arrays \n", + "tfinal = 10\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, a, v, and x\n", + "t = np.zeros(n)\n", + "v = np.zeros((n,2))\n", + "r = np.zeros((n,2))\n", + "# Initial conditions as compact 2-dimensional arrays\n", + "r0 = np.array([1.0,0.0])\n", + "v0 = np.array([0.0,2*pi])\n", + "r[0] = r0\n", + "v[0] = v0\n", + "Fourpi2 = 4*pi*pi\n", + "# Start integrating using the Velocity-Verlet method\n", + "for i in range(n-1):\n", + " # Set up forces, air resistance FD, note now that we need the norm of the vecto\n", + " # Here you could have defined your own function for this\n", + " rabs = sqrt(sum(r[i]*r[i]))\n", + " a = -Fourpi2*r[i]/(rabs**3)\n", + " # update velocity, time and position using the Velocity-Verlet method\n", + " r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a\n", + " rabs = sqrt(sum(r[i+1]*r[i+1]))\n", + " anew = -4*(pi**2)*r[i+1]/(rabs**3)\n", + " v[i+1] = v[i] + 0.5*DeltaT*(a+anew)\n", + " t[i+1] = t[i] + DeltaT\n", + "# Plot position as function of time \n", + "fig, ax = plt.subplots()\n", + "ax.set_ylabel('x[m]')\n", + "ax.set_xlabel('y[m]')\n", + "ax.plot(r[:,0], r[:,1])\n", + "fig.tight_layout()\n", + "save_fig(\"EarthSunVV\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can easily generalize the calculation of the forces by defining a function\n", + "which takes in as input the various variables. We leave this as a challenge to you.\n", + "\n", + "\n", + "## Studying Energy Conservation\n", + "\n", + "In order to study the conservation of energy, we will need to perform\n", + "a numerical integration, unless we can integrate analytically. Here we\n", + "present the Trapezoidal rule as a the simplest possible approximation.\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "## Numerical Integration\n", + "\n", + "It is also useful to consider methods to integrate numerically.\n", + "Let us consider the following case.\n", + "We have classical electron which moves in the $x$-direction along a surface. The force from the surface is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}(x)=-F_0\\sin{(\\frac{2\\pi x}{b})}\\boldsymbol{e}_x.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The constant $b$ represents the distance between atoms at the surface of the material, $F_0$ is a constant and $x$ is the position of the electron.\n", + " Using the work-energy theorem we can find the work $W$ done when moving an electron from a position $x_0$ to a final position $x$ through the\n", + " integral" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "W=-\\int_{x_0}^x \\boldsymbol{F}(x')dx' = \\int_{x_0}^x F_0\\sin{(\\frac{2\\pi x'}{b})} dx',\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which results in" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "W=\\frac{F_0b}{2\\pi}\\left[\\cos{(\\frac{2\\pi x}{b})}-\\cos{(\\frac{2\\pi x_0}{b})}\\right].\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Numerical Integration\n", + "\n", + "There are several numerical algorithms for finding an integral\n", + "numerically. The more familiar ones like the rectangular rule or the\n", + "trapezoidal rule have simple geometric interpretations.\n", + "\n", + "Let us look at the mathematical details of what are called equal-step methods, also known as Newton-Cotes quadrature.\n", + "\n", + "\n", + "## Newton-Cotes Quadrature or equal-step methods\n", + "The integral" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " I=\\int_a^bf(x) dx\n", + "\\label{eq:integraldef} \\tag{17}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "has a very simple meaning. The integral is the\n", + "area enscribed by the function $f(x)$ starting from $x=a$ to $x=b$. It is subdivided in several smaller areas whose evaluation is to be approximated by different techniques. The areas under the curve can for example be approximated by rectangular boxes or trapezoids.\n", + "\n", + "\n", + "\n", + "\n", + "## Basic philosophy of equal-step methods\n", + "In considering equal step methods, our basic approach is that of approximating\n", + "a function $f(x)$ with a polynomial of at most \n", + "degree $N-1$, given $N$ integration points. If our polynomial is of degree $1$,\n", + "the function will be approximated with $f(x)\\approx a_0+a_1x$.\n", + "\n", + "\n", + "\n", + "\n", + "## Simple algorithm for equal step methods\n", + "The algorithm for these integration methods is rather simple, and the number of approximations perhaps unlimited!\n", + "\n", + "* Choose a step size $h=(b-a)/N$ where $N$ is the number of steps and $a$ and $b$ the lower and upper limits of integration.\n", + "\n", + "* With a given step length we rewrite the integral as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^bf(x) dx= \\int_a^{a+h}f(x)dx + \\int_{a+h}^{a+2h}f(x)dx+\\dots \\int_{b-h}^{b}f(x)dx.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* The strategy then is to find a reliable polynomial approximation for $f(x)$ in the various intervals. Choosing a given approximation for $f(x)$, we obtain a specific approximation to the integral.\n", + "\n", + "* With this approximation to $f(x)$ we perform the integration by computing the integrals over all subintervals.\n", + "\n", + "## Simple algorithm for equal step methods\n", + "\n", + "One possible strategy then is to find a reliable polynomial expansion for $f(x)$ in the smaller\n", + "subintervals. Consider for example evaluating" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^{a+2h}f(x)dx,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which we rewrite as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\int_a^{a+2h}f(x)dx=\\int_{x_0-h}^{x_0+h}f(x)dx.\n", + "\\label{eq:hhint} \\tag{18}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have chosen a midpoint $x_0$ and have defined $x_0=a+h$.\n", + "\n", + "\n", + "\n", + "\n", + "## The rectangle method\n", + "\n", + "A very simple approach is the so-called midpoint or rectangle method.\n", + "In this case the integration area is split in a given number of rectangles with length $h$ and height given by the mid-point value of the function. This gives the following simple rule for approximating an integral" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "I=\\int_a^bf(x) dx \\approx h\\sum_{i=1}^N f(x_{i-1/2}), \n", + "\\label{eq:rectangle} \\tag{19}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $f(x_{i-1/2})$ is the midpoint value of $f$ for a given rectangle. We will discuss its truncation \n", + "error below. It is easy to implement this algorithm, as shown below\n", + "\n", + "\n", + "## Truncation error for the rectangular rule\n", + "\n", + "The correct mathematical expression for the local error for the rectangular rule $R_i(h)$ for element $i$ is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_{-h}^hf(x)dx - R_i(h)=-\\frac{h^3}{24}f^{(2)}(\\xi),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and the global error reads" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^bf(x)dx -R_h(f)=-\\frac{b-a}{24}h^2f^{(2)}(\\xi),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $R_h$ is the result obtained with rectangular rule and $\\xi \\in [a,b]$.\n", + "\n", + "\n", + "\n", + "## Codes for the Rectangular rule\n", + "\n", + "We go back to our simple example above and set $F_0=b=1$ and choose $x_0=0$ and $x=1/2$, and have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "W=\\frac{1}{\\pi}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The code here computes the integral using the rectangle rule and $n=100$ integration points we have a relative error of\n", + "$10^{-5}$." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from math import sin, pi\n", + "import numpy as np\n", + "from sympy import Symbol, integrate\n", + "# function for the Rectangular rule \n", + "def Rectangular(a,b,f,n):\n", + " h = (b-a)/float(n)\n", + " s = 0\n", + " for i in range(0,n,1):\n", + " x = (i+0.5)*h\n", + " s = s+ f(x)\n", + " return h*s\n", + "# function to integrate\n", + "def function(x):\n", + " return sin(2*pi*x)\n", + "# define integration limits and integration points \n", + "a = 0.0; b = 0.5;\n", + "n = 100\n", + "Exact = 1./pi\n", + "print(\"Relative error= \", abs( (Rectangular(a,b,function,n)-Exact)/Exact))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The trapezoidal rule\n", + "\n", + "The other integral gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_{x_0-h}^{x_0}f(x)dx=\\frac{h}{2}\\left(f(x_0) + f(x_0-h)\\right)+O(h^3),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and adding up we obtain" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " \\int_{x_0-h}^{x_0+h}f(x)dx=\\frac{h}{2}\\left(f(x_0+h) + 2f(x_0) + f(x_0-h)\\right)+O(h^3),\n", + "\\label{eq:trapez} \\tag{20}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which is the well-known trapezoidal rule. Concerning the error in the approximation made,\n", + "$O(h^3)=O((b-a)^3/N^3)$, you should note \n", + "that this is the local error. Since we are splitting the integral from\n", + "$a$ to $b$ in $N$ pieces, we will have to perform approximately $N$ \n", + "such operations.\n", + "\n", + "This means that the *global error* goes like $\\approx O(h^2)$. \n", + "The trapezoidal reads then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " I=\\int_a^bf(x) dx=h\\left(f(a)/2 + f(a+h) +f(a+2h)+\n", + " \\dots +f(b-h)+ f_{b}/2\\right),\n", + "\\label{eq:trapez1} \\tag{21}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with a global error which goes like $O(h^2)$. \n", + "\n", + "Hereafter we use the shorthand notations $f_{-h}=f(x_0-h)$, $f_{0}=f(x_0)$\n", + "and $f_{h}=f(x_0+h)$.\n", + "\n", + "\n", + "## Error in the trapezoidal rule\n", + "\n", + "The correct mathematical expression for the local error for the trapezoidal rule is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^bf(x)dx -\\frac{b-a}{2}\\left[f(a)+f(b)\\right]=-\\frac{h^3}{12}f^{(2)}(\\xi),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and the global error reads" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^bf(x)dx -T_h(f)=-\\frac{b-a}{12}h^2f^{(2)}(\\xi),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $T_h$ is the trapezoidal result and $\\xi \\in [a,b]$.\n", + "\n", + "\n", + "\n", + "## Algorithm for the trapezoidal rule\n", + "The trapezoidal rule is easy to implement numerically \n", + "through the following simple algorithm\n", + "\n", + " * Choose the number of mesh points and fix the step length.\n", + "\n", + " * calculate $f(a)$ and $f(b)$ and multiply with $h/2$.\n", + "\n", + " * Perform a loop over $n=1$ to $n-1$ ($f(a)$ and $f(b)$ are known) and sum up the terms $f(a+h) +f(a+2h)+f(a+3h)+\\dots +f(b-h)$. Each step in the loop corresponds to a given value $a+nh$.\n", + "\n", + " * Multiply the final result by $h$ and add $hf(a)/2$ and $hf(b)/2$.\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "## Trapezoidal Rule\n", + "\n", + "We use the same function and integrate now using the trapoezoidal rule." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "from sympy import Symbol, integrate\n", + "# function for the trapezoidal rule\n", + "def Trapez(a,b,f,n):\n", + " h = (b-a)/float(n)\n", + " s = 0\n", + " x = a\n", + " for i in range(1,n,1):\n", + " x = x+h\n", + " s = s+ f(x)\n", + " s = 0.5*(f(a)+f(b)) +s\n", + " return h*s\n", + "# function to integrate\n", + "def function(x):\n", + " return sin(2*pi*x)\n", + "# define integration limits and integration points \n", + "a = 0.0; b = 0.5;\n", + "n = 100\n", + "Exact = 1./pi\n", + "print(\"Relative error= \", abs( (Trapez(a,b,function,n)-Exact)/Exact))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Simpsons' rule\n", + "\n", + "Instead of using the above first-order polynomials \n", + "approximations for $f$, we attempt at using a second-order polynomials.\n", + "In this case we need three points in order to define a second-order \n", + "polynomial approximation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "f(x) \\approx P_2(x)=a_0+a_1x+a_2x^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using again Lagrange's interpolation formula we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "P_2(x)=\\frac{(x-x_0)(x-x_1)}{(x_2-x_0)(x_2-x_1)}y_2+\n", + " \\frac{(x-x_0)(x-x_2)}{(x_1-x_0)(x_1-x_2)}y_1+\n", + " \\frac{(x-x_1)(x-x_2)}{(x_0-x_1)(x_0-x_2)}y_0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Inserting this formula in the integral of Eq. ([18](#eq:hhint)) we obtain" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_{-h}^{+h}f(x)dx=\\frac{h}{3}\\left(f_h + 4f_0 + f_{-h}\\right)+O(h^5),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which is Simpson's rule. \n", + "\n", + "\n", + "\n", + "## Simpson's rule\n", + "Note that the improved accuracy in the evaluation of\n", + "the derivatives gives a better error approximation, $O(h^5)$ vs.\\ $O(h^3)$ .\n", + "But this is again the *local error approximation*. \n", + "Using Simpson's rule we can easily compute\n", + "the integral of Eq. ([17](#eq:integraldef)) to be" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " I=\\int_a^bf(x) dx=\\frac{h}{3}\\left(f(a) + 4f(a+h) +2f(a+2h)+\n", + " \\dots +4f(b-h)+ f_{b}\\right),\n", + "\\label{eq:simpson} \\tag{22}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with a global error which goes like $O(h^4)$. \n", + "\n", + "\n", + "\n", + "## Mathematical expressions for the truncation error\n", + "More formal expressions for the local and global errors are for the local error" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^bf(x)dx -\\frac{b-a}{6}\\left[f(a)+4f((a+b)/2)+f(b)\\right]=-\\frac{h^5}{90}f^{(4)}(\\xi),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and for the global error" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_a^bf(x)dx -S_h(f)=-\\frac{b-a}{180}h^4f^{(4)}(\\xi).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with $\\xi\\in[a,b]$ and $S_h$ the results obtained with Simpson's method.\n", + "\n", + "\n", + "\n", + "## Algorithm for Simpson's rule\n", + "The method \n", + "can easily be implemented numerically through the following simple algorithm\n", + "\n", + " * Choose the number of mesh points and fix the step.\n", + "\n", + " * calculate $f(a)$ and $f(b)$\n", + "\n", + " * Perform a loop over $n=1$ to $n-1$ ($f(a)$ and $f(b)$ are known) and sum up the terms $4f(a+h) +2f(a+2h)+4f(a+3h)+\\dots +4f(b-h)$. Each step in the loop corresponds to a given value $a+nh$. Odd values of $n$ give $4$ as factor while even values yield $2$ as factor.\n", + "\n", + " * Multiply the final result by $\\frac{h}{3}$.\n", + "\n", + "## Code example" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from math import sin, pi\n", + "import numpy as np\n", + "from sympy import Symbol, integrate\n", + "# function for the trapezoidal rule \n", + "def Simpson(a,b,f,n):\n", + " h = (b-a)/float(n)\n", + " sum = f(a)/float(2);\n", + " for i in range(1,n):\n", + " sum = sum + f(a+i*h)*(3+(-1)**(i+1))\n", + " sum = sum + f(b)/float(2)\n", + " return sum*h/3.0\n", + "# function to integrate \n", + "def function(x):\n", + " return sin(2*pi*x)\n", + "# define integration limits and integration points \n", + "a = 0.0; b = 0.5;\n", + "n = 100\n", + "Exact = 1./pi\n", + "print(\"Relative error= \", abs( (Simpson(a,b,function,n)-Exact)/Exact))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We see that Simpson's rule gives a much better estimation of the relative error with the same amount of points as we had for the Rectangle rule and the Trapezoidal rule." + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/chapter5.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter5.ipynb new file mode 100644 index 000000000..f201dab57 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter5.ipynb @@ -0,0 +1,2857 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Harmonic Oscillator\n", + "\n", + "The harmonic oscillator is omnipresent in physics. Although you may think \n", + "of this as being related to springs, it, or an equivalent\n", + "mathematical representation, appears in just about any problem where a\n", + "mode is sitting near its potential energy minimum. At that point,\n", + "$\\partial_x V(x)=0$, and the first non-zero term (aside from a\n", + "constant) in the potential energy is that of a harmonic oscillator. In\n", + "a solid, sound modes (phonons) are built on a picture of coupled\n", + "harmonic oscillators, and in relativistic field theory the fundamental\n", + "interactions are also built on coupled oscillators positioned\n", + "infinitesimally close to one another in space. The phenomena of a\n", + "resonance of an oscillator driven at a fixed frequency plays out\n", + "repeatedly in atomic, nuclear and high-energy physics, when quantum\n", + "mechanically the evolution of a state oscillates according to\n", + "$e^{-iEt}$ and exciting discrete quantum states has very similar\n", + "mathematics as exciting discrete states of an oscillator.\n", + "\n", + "The potential energy for a single particle as a function of its position $x$ can be written as a Taylor expansion about some point $x_0$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "V(x)=V(x_0)+(x-x_0)\\left.\\partial_xV(x)\\right|_{x_0}+\\frac{1}{2}(x-x_0)^2\\left.\\partial_x^2V(x)\\right|_{x_0}\n", + "+\\frac{1}{3!}\\left.\\partial_x^3V(x)\\right|_{x_0}+\\cdots\n", + "\\label{_auto1} \\tag{1}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the position $x_0$ is at the minimum of the resonance, the first two non-zero terms of the potential are" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "V(x)&\\approx& V(x_0)+\\frac{1}{2}(x-x_0)^2\\left.\\partial_x^2V(x)\\right|_{x_0},\\\\\n", + "\\nonumber\n", + "&=&V(x_0)+\\frac{1}{2}k(x-x_0)^2,~~~~k\\equiv \\left.\\partial_x^2V(x)\\right|_{x_0},\\\\\n", + "\\nonumber\n", + "F&=&-\\partial_xV(x)=-k(x-x_0).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Put into Newton's 2nd law (assuming $x_0=0$)," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "m\\ddot{x}&=&-kx,\\\\\n", + "x&=&A\\cos(\\omega_0 t-\\phi),~~~\\omega_0=\\sqrt{k/m}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here $A$ and $\\phi$ are arbitrary. Equivalently, one could have\n", + "written this as $A\\cos(\\omega_0 t)+B\\sin(\\omega_0 t)$, or as the real\n", + "part of $Ae^{i\\omega_0 t}$. In this last case $A$ could be an\n", + "arbitrary complex constant. Thus, there are 2 arbitrary constants\n", + "(either $A$ and $B$ or $A$ and $\\phi$, or the real and imaginary part\n", + "of one complex constant. This is the expectation for a second order\n", + "differential equation, and also agrees with the physical expectation\n", + "that if you know a particle's initial velocity and position you should\n", + "be able to define its future motion, and that those two arbitrary\n", + "conditions should translate to two arbitrary constants.\n", + "\n", + "A key feature of harmonic motion is that the system repeats itself\n", + "after a time $T=1/f$, where $f$ is the frequency, and $\\omega=2\\pi f$\n", + "is the angular frequency. The period of the motion is independent of\n", + "the amplitude. However, this independence is only exact when one can\n", + "neglect higher terms of the potential, $x^3, x^4\\cdots$. Once can\n", + "neglect these terms for sufficiently small amplitudes, and for larger\n", + "amplitudes the motion is no longer purely sinusoidal, and even though\n", + "the motion repeats itself, the time for repeating the motion is no\n", + "longer independent of the amplitude.\n", + "\n", + "One can also calculate the velocity and the kinetic energy as a function of time," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\dot{x}&=&-\\omega_0A\\sin(\\omega_0 t-\\phi),\\\\\n", + "\\nonumber\n", + "K&=&\\frac{1}{2}m\\dot{x}^2=\\frac{m\\omega_0^2A^2}{2}\\sin^2(\\omega_0t-\\phi),\\\\\n", + "\\nonumber\n", + "&=&\\frac{k}{2}A^2\\sin^2(\\omega_0t-\\phi).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The total energy is then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "E=K+V=\\frac{1}{2}m\\dot{x}^2+\\frac{1}{2}kx^2=\\frac{1}{2}kA^2.\n", + "\\label{_auto2} \\tag{2}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The total energy then goes as the square of the amplitude.\n", + "\n", + "\n", + "A pendulum is an example of a harmonic oscillator. By expanding the\n", + "kinetic and potential energies for small angles find the frequency for\n", + "a pendulum of length $L$ with all the mass $m$ centered at the end by\n", + "writing the eq.s of motion in the form of a harmonic oscillator.\n", + "\n", + "The potential energy and kinetic energies are (for $x$ being the displacement)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "V&=&mgL(1-\\cos\\theta)\\approx mgL\\frac{x^2}{2L^2},\\\\\n", + "K&=&\\frac{1}{2}mL^2\\dot{\\theta}^2\\approx \\frac{m}{2}\\dot{x}^2.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For small $x$ Newton's 2nd law becomes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\ddot{x}=-\\frac{mg}{L}x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and the spring constant would appear to be $k=mg/L$, which makes the\n", + "frequency equal to $\\omega_0=\\sqrt{g/L}$. Note that the frequency is\n", + "independent of the mass.\n", + "\n", + "\n", + "## Damped Oscillators\n", + "\n", + "We consider only the case where the damping force is proportional to\n", + "the velocity. This is counter to dragging friction, where the force is\n", + "proportional in strength to the normal force and independent of\n", + "velocity, and is also inconsistent with wind resistance, where the\n", + "magnitude of the drag force is proportional the square of the\n", + "velocity. Rolling resistance does seem to be mainly proportional to\n", + "the velocity. However, the main motivation for considering damping\n", + "forces proportional to the velocity is that the math is more\n", + "friendly. This is because the differential equation is linear,\n", + "i.e. each term is of order $x$, $\\dot{x}$, $\\ddot{x}\\cdots$, or even\n", + "terms with no mention of $x$, and there are no terms such as $x^2$ or\n", + "$x\\ddot{x}$. The equations of motion for a spring with damping force\n", + "$-b\\dot{x}$ are" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "m\\ddot{x}+b\\dot{x}+kx=0.\n", + "\\label{_auto3} \\tag{3}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Just to make the solution a bit less messy, we rewrite this equation as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:dampeddiffyq} \\tag{4}\n", + "\\ddot{x}+2\\beta\\dot{x}+\\omega_0^2x=0,~~~~\\beta\\equiv b/2m,~\\omega_0\\equiv\\sqrt{k/m}.\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Both $\\beta$ and $\\omega$ have dimensions of inverse time. To find solutions (see appendix C in the text) you must make an educated guess at the form of the solution. To do this, first realize that the solution will need an arbitrary normalization $A$ because the equation is linear. Secondly, realize that if the form is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x=Ae^{rt}\n", + "\\label{_auto4} \\tag{5}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "that each derivative simply brings out an extra power of $r$. This\n", + "means that the $Ae^{rt}$ factors out and one can simply solve for an\n", + "equation for $r$. Plugging this form into Eq. ([4](#eq:dampeddiffyq))," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "r^2+2\\beta r+\\omega_0^2=0.\n", + "\\label{_auto5} \\tag{6}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Because this is a quadratic equation there will be two solutions," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "r=-\\beta\\pm\\sqrt{\\beta^2-\\omega_0^2}.\n", + "\\label{_auto6} \\tag{7}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We refer to the two solutions as $r_1$ and $r_2$ corresponding to the\n", + "$+$ and $-$ roots. As expected, there should be two arbitrary\n", + "constants involved in the solution," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x=A_1e^{r_1t}+A_2e^{r_2t},\n", + "\\label{_auto7} \\tag{8}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where the coefficients $A_1$ and $A_2$ are determined by initial\n", + "conditions.\n", + "\n", + "The roots listed above, $\\sqrt{\\omega_0^2-\\beta_0^2}$, will be\n", + "imaginary if the damping is small and $\\beta<\\omega_0$. In that case,\n", + "$r$ is complex and the factor $e{rt}$ will have some oscillatory\n", + "behavior. If the roots are real, there will only be exponentially\n", + "decaying solutions. There are three cases:\n", + "\n", + "\n", + "\n", + "### Underdamped: $\\beta<\\omega_0$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x&=&A_1e^{-\\beta t}e^{i\\omega't}+A_2e^{-\\beta t}e^{-i\\omega't},~~\\omega'\\equiv\\sqrt{\\omega_0^2-\\beta^2}\\\\\n", + "\\nonumber\n", + "&=&(A_1+A_2)e^{-\\beta t}\\cos\\omega't+i(A_1-A_2)e^{-\\beta t}\\sin\\omega't.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here we have made use of the identity\n", + "$e^{i\\omega't}=\\cos\\omega't+i\\sin\\omega't$. Because the constants are\n", + "arbitrary, and because the real and imaginary parts are both solutions\n", + "individually, we can simply consider the real part of the solution\n", + "alone:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:homogsolution} \\tag{9}\n", + "x&=&B_1e^{-\\beta t}\\cos\\omega't+B_2e^{-\\beta t}\\sin\\omega't,\\\\\n", + "\\nonumber \n", + "\\omega'&\\equiv&\\sqrt{\\omega_0^2-\\beta^2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Critical dampling: $\\beta=\\omega_0$\n", + "\n", + "In this case the two terms involving $r_1$ and $r_2$ are identical\n", + "because $\\omega'=0$. Because we need to arbitrary constants, there\n", + "needs to be another solution. This is found by simply guessing, or by\n", + "taking the limit of $\\omega'\\rightarrow 0$ from the underdamped\n", + "solution. The solution is then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:criticallydamped} \\tag{10}\n", + "x=Ae^{-\\beta t}+Bte^{-\\beta t}.\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The critically damped solution is interesting because the solution\n", + "approaches zero quickly, but does not oscillate. For a problem with\n", + "zero initial velocity, the solution never crosses zero. This is a good\n", + "choice for designing shock absorbers or swinging doors.\n", + "\n", + "### Overdamped: $\\beta>\\omega_0$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x&=&A_1\\exp{-(\\beta+\\sqrt{\\beta^2-\\omega_0^2})t}+A_2\\exp{-(\\beta-\\sqrt{\\beta^2-\\omega_0^2})t}\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This solution will also never pass the origin more than once, and then\n", + "only if the initial velocity is strong and initially toward zero.\n", + "\n", + "\n", + "\n", + "\n", + "Given $b$, $m$ and $\\omega_0$, find $x(t)$ for a particle whose\n", + "initial position is $x=0$ and has initial velocity $v_0$ (assuming an\n", + "underdamped solution).\n", + "\n", + "The solution is of the form," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "x&=&e^{-\\beta t}\\left[A_1\\cos(\\omega' t)+A_2\\sin\\omega't\\right],\\\\\n", + "\\dot{x}&=&-\\beta x+\\omega'e^{-\\beta t}\\left[-A_1\\sin\\omega't+A_2\\cos\\omega't\\right].\\\\\n", + "\\omega'&\\equiv&\\sqrt{\\omega_0^2-\\beta^2},~~~\\beta\\equiv b/2m.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "From the initial conditions, $A_1=0$ because $x(0)=0$ and $\\omega'A_2=v_0$. So" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "x=\\frac{v_0}{\\omega'}e^{-\\beta t}\\sin\\omega't.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Our Sliding Block Code\n", + "Here we study first the case without additional friction term and scale our equation\n", + "in terms of a dimensionless time $\\tau$.\n", + "\n", + "Let us remind ourselves about the differential equation we want to solve (the general case with damping due to friction)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\frac{d^2x}{dt^2} + b\\frac{dx}{dt}+kx(t) =0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We divide by $m$ and introduce $\\omega_0^2=\\sqrt{k/m}$ and obtain" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{dt^2} + \\frac{b}{m}\\frac{dx}{dt}+\\omega_0^2x(t) =0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thereafter we introduce a dimensionless time $\\tau = t\\omega_0$ (check\n", + "that the dimensionality is correct) and rewrite our equation as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{d\\tau^2} + \\frac{b}{m\\omega_0}\\frac{dx}{d\\tau}+x(\\tau) =0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which gives us" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{d\\tau^2} + \\frac{b}{m\\omega_0}\\frac{dx}{d\\tau}+x(\\tau) =0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We then define $\\gamma = b/(2m\\omega_0)$ and rewrite our equations as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{d\\tau^2} + 2\\gamma\\frac{dx}{d\\tau}+x(\\tau) =0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is the equation we will code below. The first version employs the Euler-Cromer method." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "\n", + "# Common imports\n", + "import numpy as np\n", + "import pandas as pd\n", + "from math import *\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "\n", + "# Where to save the figures and data files\n", + "PROJECT_ROOT_DIR = \"Results\"\n", + "FIGURE_ID = \"Results/FigureFiles\"\n", + "DATA_ID = \"DataFiles/\"\n", + "\n", + "if not os.path.exists(PROJECT_ROOT_DIR):\n", + " os.mkdir(PROJECT_ROOT_DIR)\n", + "\n", + "if not os.path.exists(FIGURE_ID):\n", + " os.makedirs(FIGURE_ID)\n", + "\n", + "if not os.path.exists(DATA_ID):\n", + " os.makedirs(DATA_ID)\n", + "\n", + "def image_path(fig_id):\n", + " return os.path.join(FIGURE_ID, fig_id)\n", + "\n", + "def data_path(dat_id):\n", + " return os.path.join(DATA_ID, dat_id)\n", + "\n", + "def save_fig(fig_id):\n", + " plt.savefig(image_path(fig_id) + \".png\", format='png')\n", + "\n", + "\n", + "from pylab import plt, mpl\n", + "plt.style.use('seaborn')\n", + "mpl.rcParams['font.family'] = 'serif'\n", + "\n", + "DeltaT = 0.001\n", + "#set up arrays \n", + "tfinal = 20 # in years\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, v, and x\n", + "t = np.zeros(n)\n", + "v = np.zeros(n)\n", + "x = np.zeros(n)\n", + "# Initial conditions as simple one-dimensional arrays of time\n", + "x0 = 1.0 \n", + "v0 = 0.0\n", + "x[0] = x0\n", + "v[0] = v0\n", + "gamma = 0.0\n", + "# Start integrating using Euler-Cromer's method\n", + "for i in range(n-1):\n", + " # Set up the acceleration\n", + " # Here you could have defined your own function for this\n", + " a = -2*gamma*v[i]-x[i]\n", + " # update velocity, time and position\n", + " v[i+1] = v[i] + DeltaT*a\n", + " x[i+1] = x[i] + DeltaT*v[i+1]\n", + " t[i+1] = t[i] + DeltaT\n", + "# Plot position as function of time \n", + "fig, ax = plt.subplots()\n", + "#ax.set_xlim(0, tfinal)\n", + "ax.set_ylabel('x[m]')\n", + "ax.set_xlabel('t[s]')\n", + "ax.plot(t, x)\n", + "fig.tight_layout()\n", + "save_fig(\"BlockEulerCromer\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When setting up the value of $\\gamma$ we see that for $\\gamma=0$ we get the simple oscillatory motion with no damping.\n", + "Choosing $\\gamma < 1$ leads to the classical underdamped case with oscillatory motion, but where the motion comes to an end.\n", + "\n", + "Choosing $\\gamma =1$ leads to what normally is called critical damping and $\\gamma> 1$ leads to critical overdamping.\n", + "Try it out and try also to change the initial position and velocity. Setting $\\gamma=1$\n", + "yields a situation, as discussed above, where the solution approaches quickly zero and does not oscillate. With zero initial velocity it will never cross zero. \n", + "\n", + "\n", + "## Sinusoidally Driven Oscillators\n", + "\n", + "Here, we consider the force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "F=-kx-b\\dot{x}+F_0\\cos\\omega t,\n", + "\\label{_auto8} \\tag{11}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which leads to the differential equation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:drivenosc} \\tag{12}\n", + "\\ddot{x}+2\\beta\\dot{x}+\\omega_0^2x=(F_0/m)\\cos\\omega t.\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Consider a single solution with no arbitrary constants, which we will\n", + "call a {\\it particular solution}, $x_p(t)$. It should be emphasized\n", + "that this is {\\bf A} particular solution, because there exists an\n", + "infinite number of such solutions because the general solution should\n", + "have two arbitrary constants. Now consider solutions to the same\n", + "equation without the driving term, which include two arbitrary\n", + "constants. These are called either {\\it homogenous solutions} or {\\it\n", + "complementary solutions}, and were given in the previous section,\n", + "e.g. Eq. ([9](#eq:homogsolution)) for the underdamped case. The\n", + "homogenous solution already incorporates the two arbitrary constants,\n", + "so any sum of a homogenous solution and a particular solution will\n", + "represent the {\\it general solution} of the equation. The general\n", + "solution incorporates the two arbitrary constants $A$ and $B$ to\n", + "accommodate the two initial conditions. One could have picked a\n", + "different particular solution, i.e. the original particular solution\n", + "plus any homogenous solution with the arbitrary constants $A_p$ and\n", + "$B_p$ chosen at will. When one adds in the homogenous solution, which\n", + "has adjustable constants with arbitrary constants $A'$ and $B'$, to\n", + "the new particular solution, one can get the same general solution by\n", + "simply adjusting the new constants such that $A'+A_p=A$ and\n", + "$B'+B_p=B$. Thus, the choice of $A_p$ and $B_p$ are irrelevant, and\n", + "when choosing the particular solution it is best to make the simplest\n", + "choice possible.\n", + "\n", + "To find a particular solution, one first guesses at the form," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:partform} \\tag{13}\n", + "x_p(t)=D\\cos(\\omega t-\\delta),\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and rewrite the differential equation as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "D\\left\\{-\\omega^2\\cos(\\omega t-\\delta)-2\\beta\\omega\\sin(\\omega t-\\delta)+\\omega_0^2\\cos(\\omega t-\\delta)\\right\\}=\\frac{F_0}{m}\\cos(\\omega t).\n", + "\\label{_auto9} \\tag{14}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One can now use angle addition formulas to get" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "D\\left\\{(-\\omega^2\\cos\\delta+2\\beta\\omega\\sin\\delta+\\omega_0^2\\cos\\delta)\\cos(\\omega t)\\right.&&\\\\\n", + "\\nonumber\n", + "\\left.+(-\\omega^2\\sin\\delta-2\\beta\\omega\\cos\\delta+\\omega_0^2\\sin\\delta)\\sin(\\omega t)\\right\\}\n", + "&=&\\frac{F_0}{m}\\cos(\\omega t).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Both the $\\cos$ and $\\sin$ terms need to equate if the expression is to hold at all times. Thus, this becomes two equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "D\\left\\{-\\omega^2\\cos\\delta+2\\beta\\omega\\sin\\delta+\\omega_0^2\\cos\\delta\\right\\}&=&\\frac{F_0}{m}\\\\\n", + "\\nonumber\n", + "-\\omega^2\\sin\\delta-2\\beta\\omega\\cos\\delta+\\omega_0^2\\sin\\delta&=&0.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "After dividing by $\\cos\\delta$, the lower expression leads to" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\tan\\delta=\\frac{2\\beta\\omega}{\\omega_0^2-\\omega^2}.\n", + "\\label{_auto10} \\tag{15}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using the identities $\\tan^2+1=\\csc^2$ and $\\sin^2+\\cos^2=1$, one can also express $\\sin\\delta$ and $\\cos\\delta$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\sin\\delta&=&\\frac{2\\beta\\omega}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}},\\\\\n", + "\\nonumber\n", + "\\cos\\delta&=&\\frac{(\\omega_0^2-\\omega^2)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}}\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Inserting the expressions for $\\cos\\delta$ and $\\sin\\delta$ into the expression for $D$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:Ddrive} \\tag{16}\n", + "D=\\frac{F_0/m}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}}.\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For a given initial condition, e.g. initial displacement and velocity,\n", + "one must add the homogenous solution then solve for the two arbitrary\n", + "constants. However, because the homogenous solutions decay with time\n", + "as $e^{-\\beta t}$, the particular solution is all that remains at\n", + "large times, and is therefore the steady state solution. Because the\n", + "arbitrary constants are all in the homogenous solution, all memory of\n", + "the initial conditions are lost at large times, $t>>1/\\beta$.\n", + "\n", + "The amplitude of the motion, $D$, is linearly proportional to the\n", + "driving force ($F_0/m$), but also depends on the driving frequency\n", + "$\\omega$. For small $\\beta$ the maximum will occur at\n", + "$\\omega=\\omega_0$. This is referred to as a resonance. In the limit\n", + "$\\beta\\rightarrow 0$ the amplitude at resonance approaches infinity.\n", + "\n", + "\n", + "## Alternative Derivation for Driven Oscillators\n", + "\n", + "Here, we derive the same expressions as in Equations ([13](#eq:partform)) and ([16](#eq:Ddrive)) but express the driving forces as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "F(t)&=&F_0e^{i\\omega t},\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "rather than as $F_0\\cos\\omega t$. The real part of $F$ is the same as before. For the differential equation," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:compdrive} \\tag{17}\n", + "\\ddot{x}+2\\beta\\dot{x}+\\omega_0^2x&=&\\frac{F_0}{m}e^{i\\omega t},\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "one can treat $x(t)$ as an imaginary function. Because the operations\n", + "$d^2/dt^2$ and $d/dt$ are real and thus do not mix the real and\n", + "imaginary parts of $x(t)$, Eq. ([17](#eq:compdrive)) is effectively 2\n", + "equations. Because $e^{\\omega t}=\\cos\\omega t+i\\sin\\omega t$, the real\n", + "part of the solution for $x(t)$ gives the solution for a driving force\n", + "$F_0\\cos\\omega t$, and the imaginary part of $x$ corresponds to the\n", + "case where the driving force is $F_0\\sin\\omega t$. It is rather easy\n", + "to solve for the complex $x$ in this case, and by taking the real part\n", + "of the solution, one finds the answer for the $\\cos\\omega t$ driving\n", + "force.\n", + "\n", + "We assume a simple form for the particular solution" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x_p=De^{i\\omega t},\n", + "\\label{_auto11} \\tag{18}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $D$ is a complex constant.\n", + "\n", + "From Eq. ([17](#eq:compdrive)) one inserts the form for $x_p$ above to get" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "D\\left\\{-\\omega^2+2i\\beta\\omega+\\omega_0^2\\right\\}e^{i\\omega t}=(F_0/m)e^{i\\omega t},\\\\\n", + "\\nonumber\n", + "D=\\frac{F_0/m}{(\\omega_0^2-\\omega^2)+2i\\beta\\omega}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The norm and phase for $D=|D|e^{-i\\delta}$ can be read by inspection," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "|D|=\\frac{F_0/m}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}},~~~~\\tan\\delta=\\frac{2\\beta\\omega}{\\omega_0^2-\\omega^2}.\n", + "\\label{_auto12} \\tag{19}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is the same expression for $\\delta$ as before. One then finds $x_p(t)$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:fastdriven1} \\tag{20}\n", + "x_p(t)&=&\\Re\\frac{(F_0/m)e^{i\\omega t-i\\delta}}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}\\\\\n", + "\\nonumber\n", + "&=&\\frac{(F_0/m)\\cos(\\omega t-\\delta)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is the same answer as before.\n", + "If one wished to solve for the case where $F(t)= F_0\\sin\\omega t$, the imaginary part of the solution would work" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:fastdriven2} \\tag{21}\n", + "x_p(t)&=&\\Im\\frac{(F_0/m)e^{i\\omega t-i\\delta}}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}\\\\\n", + "\\nonumber\n", + "&=&\\frac{(F_0/m)\\sin(\\omega t-\\delta)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Consider the damped and driven harmonic oscillator worked out above. Given $F_0, m,\\beta$ and $\\omega_0$, solve for the complete solution $x(t)$ for the case where $F=F_0\\sin\\omega t$ with initial conditions $x(t=0)=0$ and $v(t=0)=0$. Assume the underdamped case.\n", + "\n", + "The general solution including the arbitrary constants includes both the homogenous and particular solutions," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "x(t)&=&\\frac{F_0}{m}\\frac{\\sin(\\omega t-\\delta)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}\n", + "+A\\cos\\omega't e^{-\\beta t}+B\\sin\\omega't e^{-\\beta t}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The quantities $\\delta$ and $\\omega'$ are given earlier in the\n", + "section, $\\omega'=\\sqrt{\\omega_0^2-\\beta^2},\n", + "\\delta=\\tan^{-1}(2\\beta\\omega/(\\omega_0^2-\\omega^2)$. Here, solving\n", + "the problem means finding the arbitrary constants $A$ and\n", + "$B$. Satisfying the initial conditions for the initial position and\n", + "velocity:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "x(t=0)=0&=&-\\eta\\sin\\delta+A,\\\\\n", + "v(t=0)=0&=&\\omega\\eta\\cos\\delta-\\beta A+\\omega'B,\\\\\n", + "\\eta&\\equiv&\\frac{F_0}{m}\\frac{1}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The problem is now reduced to 2 equations and 2 unknowns, $A$ and $B$. The solution is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "A&=& \\eta\\sin\\delta ,~~~B=\\frac{-\\omega\\eta\\cos\\delta+\\beta\\eta\\sin\\delta}{\\omega'}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Resonance Widths; the $Q$ factor\n", + "\n", + "From the previous two sections, the particular solution for a driving force, $F=F_0\\cos\\omega t$, is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x_p(t)&=&\\frac{F_0/m}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}}\\cos(\\omega_t-\\delta),\\\\\n", + "\\nonumber\n", + "\\delta&=&\\tan^{-1}\\left(\\frac{2\\beta\\omega}{\\omega_0^2-\\omega^2}\\right).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If one fixes the driving frequency $\\omega$ and adjusts the\n", + "fundamental frequency $\\omega_0=\\sqrt{k/m}$, the maximum amplitude\n", + "occurs when $\\omega_0=\\omega$ because that is when the term from the\n", + "denominator $(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2$ is at a\n", + "minimum. This is akin to dialing into a radio station. However, if one\n", + "fixes $\\omega_0$ and adjusts the driving frequency one minimize with\n", + "respect to $\\omega$, e.g. set" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{d}{d\\omega}\\left[(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2\\right]=0,\n", + "\\label{_auto13} \\tag{22}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and one finds that the maximum amplitude occurs when\n", + "$\\omega=\\sqrt{\\omega_0^2-2\\beta^2}$. If $\\beta$ is small relative to\n", + "$\\omega_0$, one can simply state that the maximum amplitude is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x_{\\rm max}\\approx\\frac{F_0}{2m\\beta \\omega_0}.\n", + "\\label{_auto14} \\tag{23}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\frac{4\\omega^2\\beta^2}{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}=\\frac{1}{2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For small damping this occurs when $\\omega=\\omega_0\\pm \\beta$, so the $FWHM\\approx 2\\beta$. For the purposes of tuning to a specific frequency, one wants the width to be as small as possible. The ratio of $\\omega_0$ to $FWHM$ is known as the {\\it quality} factor, or $Q$ factor," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "Q\\equiv \\frac{\\omega_0}{2\\beta}.\n", + "\\label{_auto15} \\tag{24}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Numerical Studies of Driven Oscillations\n", + "\n", + "Solving the problem of driven oscillations numerically gives us much\n", + "more flexibility to study different types of driving forces. We can\n", + "reuse our earlier code by simply adding a driving force. If we stay in\n", + "the $x$-direction only this can be easily done by adding a term\n", + "$F_{\\mathrm{ext}}(x,t)$. Note that we have kept it rather general\n", + "here, allowing for both a spatial and a temporal dependence.\n", + "\n", + "Before we dive into the code, we need to briefly remind ourselves\n", + "about the equations we started with for the case with damping, namely" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\frac{d^2x}{dt^2} + b\\frac{dx}{dt}+kx(t) =0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with no external force applied to the system.\n", + "\n", + "Let us now for simplicty assume that our external force is given by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "F_{\\mathrm{ext}}(t) = F_0\\cos{(\\omega t)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $F_0$ is a constant (what is its dimension?) and $\\omega$ is the frequency of the applied external driving force.\n", + "**Small question:** would you expect energy to be conserved now?\n", + "\n", + "\n", + "Introducing the external force into our lovely differential equation\n", + "and dividing by $m$ and introducing $\\omega_0^2=\\sqrt{k/m}$ we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{dt^2} + \\frac{b}{m}\\frac{dx}{dt}+\\omega_0^2x(t) =\\frac{F_0}{m}\\cos{(\\omega t)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thereafter we introduce a dimensionless time $\\tau = t\\omega_0$\n", + "and a dimensionless frequency $\\tilde{\\omega}=\\omega/\\omega_0$. We have then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{d\\tau^2} + \\frac{b}{m\\omega_0}\\frac{dx}{d\\tau}+x(\\tau) =\\frac{F_0}{m\\omega_0^2}\\cos{(\\tilde{\\omega}\\tau)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Introducing a new amplitude $\\tilde{F} =F_0/(m\\omega_0^2)$ (check dimensionality again) we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{d\\tau^2} + \\frac{b}{m\\omega_0}\\frac{dx}{d\\tau}+x(\\tau) =\\tilde{F}\\cos{(\\tilde{\\omega}\\tau)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Our final step, as we did in the case of various types of damping, is\n", + "to define $\\gamma = b/(2m\\omega_0)$ and rewrite our equations as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2x}{d\\tau^2} + 2\\gamma\\frac{dx}{d\\tau}+x(\\tau) =\\tilde{F}\\cos{(\\tilde{\\omega}\\tau)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is the equation we will code below using the Euler-Cromer method." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "DeltaT = 0.001\n", + "#set up arrays \n", + "tfinal = 20 # in years\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, v, and x\n", + "t = np.zeros(n)\n", + "v = np.zeros(n)\n", + "x = np.zeros(n)\n", + "# Initial conditions as one-dimensional arrays of time\n", + "x0 = 1.0 \n", + "v0 = 0.0\n", + "x[0] = x0\n", + "v[0] = v0\n", + "gamma = 0.2\n", + "Omegatilde = 0.5\n", + "Ftilde = 1.0\n", + "# Start integrating using Euler-Cromer's method\n", + "for i in range(n-1):\n", + " # Set up the acceleration\n", + " # Here you could have defined your own function for this\n", + " a = -2*gamma*v[i]-x[i]+Ftilde*cos(t[i]*Omegatilde)\n", + " # update velocity, time and position\n", + " v[i+1] = v[i] + DeltaT*a\n", + " x[i+1] = x[i] + DeltaT*v[i+1]\n", + " t[i+1] = t[i] + DeltaT\n", + "# Plot position as function of time \n", + "fig, ax = plt.subplots()\n", + "ax.set_ylabel('x[m]')\n", + "ax.set_xlabel('t[s]')\n", + "ax.plot(t, x)\n", + "fig.tight_layout()\n", + "save_fig(\"ForcedBlockEulerCromer\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the above example we have focused on the Euler-Cromer method. This\n", + "method has a local truncation error which is proportional to $\\Delta t^2$\n", + "and thereby a global error which is proportional to $\\Delta t$.\n", + "We can improve this by using the Runge-Kutta family of\n", + "methods. The widely popular Runge-Kutta to fourth order or just **RK4**\n", + "has indeed a much better truncation error. The RK4 method has a global\n", + "error which is proportional to $\\Delta t$.\n", + "\n", + "Let us revisit this method and see how we can implement it for the above example.\n", + "\n", + "\n", + "\n", + "## Differential Equations, Runge-Kutta methods\n", + "\n", + "Runge-Kutta (RK) methods are based on Taylor expansion formulae, but yield\n", + "in general better algorithms for solutions of an ordinary differential equation.\n", + "The basic philosophy is that it provides an intermediate step in the computation of $y_{i+1}$.\n", + "\n", + "To see this, consider first the following definitions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{dy}{dt}=f(t,y), \n", + "\\label{_auto16} \\tag{25}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "y(t)=\\int f(t,y) dt, \n", + "\\label{_auto17} \\tag{26}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "y_{i+1}=y_i+ \\int_{t_i}^{t_{i+1}} f(t,y) dt.\n", + "\\label{_auto18} \\tag{27}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To demonstrate the philosophy behind RK methods, let us consider\n", + "the second-order RK method, RK2.\n", + "The first approximation consists in Taylor expanding $f(t,y)$\n", + "around the center of the integration interval $t_i$ to $t_{i+1}$,\n", + "that is, at $t_i+h/2$, $h$ being the step.\n", + "Using the midpoint formula for an integral, \n", + "defining $y(t_i+h/2) = y_{i+1/2}$ and \n", + "$t_i+h/2 = t_{i+1/2}$, we obtain" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\int_{t_i}^{t_{i+1}} f(t,y) dt \\approx hf(t_{i+1/2},y_{i+1/2}) +O(h^3).\n", + "\\label{_auto19} \\tag{28}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This means in turn that we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "y_{i+1}=y_i + hf(t_{i+1/2},y_{i+1/2}) +O(h^3).\n", + "\\label{_auto20} \\tag{29}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "However, we do not know the value of $y_{i+1/2}$. Here comes thus the next approximation, namely, we use Euler's\n", + "method to approximate $y_{i+1/2}$. We have then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "y_{(i+1/2)}=y_i + \\frac{h}{2}\\frac{dy}{dt}=y(t_i) + \\frac{h}{2}f(t_i,y_i).\n", + "\\label{_auto21} \\tag{30}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This means that we can define the following algorithm for \n", + "the second-order Runge-Kutta method, RK2." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6\n", + "0\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "k_2=hf(t_{i+1/2},y_i+k_1/2),\n", + "\\label{_auto23} \\tag{32}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with the final value" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation} \n", + "y_{i+i}\\approx y_i + k_2 +O(h^3). \n", + "\\label{_auto24} \\tag{33}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The difference between the previous one-step methods \n", + "is that we now need an intermediate step in our evaluation,\n", + "namely $t_i+h/2 = t_{(i+1/2)}$ where we evaluate the derivative $f$. \n", + "This involves more operations, but the gain is a better stability\n", + "in the solution.\n", + "\n", + "The fourth-order Runge-Kutta, RK4, has the following algorithm" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6\n", + "3\n", + " \n", + "<\n", + "<\n", + "<\n", + "!\n", + "!\n", + "M\n", + "A\n", + "T\n", + "H\n", + "_\n", + "B\n", + "L\n", + "O\n", + "C\n", + "K" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "k_3=hf(t_i+h/2,y_i+k_2/2)\\hspace{0.5cm} k_4=hf(t_i+h,y_i+k_3)\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with the final result" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "y_{i+1}=y_i +\\frac{1}{6}\\left( k_1 +2k_2+2k_3+k_4\\right).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Thus, the algorithm consists in first calculating $k_1$ \n", + "with $t_i$, $y_1$ and $f$ as inputs. Thereafter, we increase the step\n", + "size by $h/2$ and calculate $k_2$, then $k_3$ and finally $k_4$. The global error goes as $O(h^4)$.\n", + "\n", + "\n", + "However, at this stage, if we keep adding different methods in our\n", + "main program, the code will quickly become messy and ugly. Before we\n", + "proceed thus, we will now introduce functions that enbody the various\n", + "methods for solving differential equations. This means that we can\n", + "separate out these methods in own functions and files (and later as classes and more\n", + "generic functions) and simply call them when needed. Similarly, we\n", + "could easily encapsulate various forces or other quantities of\n", + "interest in terms of functions. To see this, let us bring up the code\n", + "we developed above for the simple sliding block, but now only with the simple forward Euler method. We introduce\n", + "two functions, one for the simple Euler method and one for the\n", + "force.\n", + "\n", + "Note that here the forward Euler method does not know the specific force function to be called.\n", + "It receives just an input the name. We can easily change the force by adding another function." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def ForwardEuler(v,x,t,n,Force):\n", + " for i in range(n-1):\n", + " v[i+1] = v[i] + DeltaT*Force(v[i],x[i],t[i])\n", + " x[i+1] = x[i] + DeltaT*v[i]\n", + " t[i+1] = t[i] + DeltaT" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def SpringForce(v,x,t):\n", + "# note here that we have divided by mass and we return the acceleration\n", + " return -2*gamma*v-x+Ftilde*cos(t*Omegatilde)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is easy to add a new method like the Euler-Cromer" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def ForwardEulerCromer(v,x,t,n,Force):\n", + " for i in range(n-1):\n", + " a = Force(v[i],x[i],t[i])\n", + " v[i+1] = v[i] + DeltaT*a\n", + " x[i+1] = x[i] + DeltaT*v[i+1]\n", + " t[i+1] = t[i] + DeltaT" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and the Velocity Verlet method (be careful with time-dependence here, it is not an ideal method for non-conservative forces))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def VelocityVerlet(v,x,t,n,Force):\n", + " for i in range(n-1):\n", + " a = Force(v[i],x[i],t[i])\n", + " x[i+1] = x[i] + DeltaT*v[i]+0.5*a\n", + " anew = Force(v[i],x[i+1],t[i+1])\n", + " v[i+1] = v[i] + 0.5*DeltaT*(a+anew)\n", + " t[i+1] = t[i] + DeltaT" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, we can now add the Runge-Kutta2 method via a new function" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def RK2(v,x,t,n,Force):\n", + " for i in range(n-1):\n", + "# Setting up k1\n", + " k1x = DeltaT*v[i]\n", + " k1v = DeltaT*Force(v[i],x[i],t[i])\n", + "# Setting up k2\n", + " vv = v[i]+k1v*0.5\n", + " xx = x[i]+k1x*0.5\n", + " k2x = DeltaT*vv\n", + " k2v = DeltaT*Force(vv,xx,t[i]+DeltaT*0.5)\n", + "# Final result\n", + " x[i+1] = x[i]+k2x\n", + " v[i+1] = v[i]+k2v\n", + "\tt[i+1] = t[i]+DeltaT" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, we can now add the Runge-Kutta2 method via a new function" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def RK4(v,x,t,n,Force):\n", + " for i in range(n-1):\n", + "# Setting up k1\n", + " k1x = DeltaT*v[i]\n", + " k1v = DeltaT*Force(v[i],x[i],t[i])\n", + "# Setting up k2\n", + " vv = v[i]+k1v*0.5\n", + " xx = x[i]+k1x*0.5\n", + " k2x = DeltaT*vv\n", + " k2v = DeltaT*Force(vv,xx,t[i]+DeltaT*0.5)\n", + "# Setting up k3\n", + " vv = v[i]+k2v*0.5\n", + " xx = x[i]+k2x*0.5\n", + " k3x = DeltaT*vv\n", + " k3v = DeltaT*Force(vv,xx,t[i]+DeltaT*0.5)\n", + "# Setting up k4\n", + " vv = v[i]+k3v\n", + " xx = x[i]+k3x\n", + " k4x = DeltaT*vv\n", + " k4v = DeltaT*Force(vv,xx,t[i]+DeltaT)\n", + "# Final result\n", + " x[i+1] = x[i]+(k1x+2*k2x+2*k3x+k4x)/6.\n", + " v[i+1] = v[i]+(k1v+2*k2v+2*k3v+k4v)/6.\n", + " t[i+1] = t[i] + DeltaT" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The Runge-Kutta family of methods are particularly useful when we have a time-dependent acceleration.\n", + "If we have forces which depend only the spatial degrees of freedom (no velocity and/or time-dependence), then energy conserving methods like the Velocity Verlet or the Euler-Cromer method are preferred. As soon as we introduce an explicit time-dependence and/or add dissipitave forces like friction or air resistance, then methods like the family of Runge-Kutta methods are well suited for this. \n", + "The code below uses the Runge-Kutta4 methods." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "DeltaT = 0.001\n", + "#set up arrays \n", + "tfinal = 20 # in years\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, v, and x\n", + "t = np.zeros(n)\n", + "v = np.zeros(n)\n", + "x = np.zeros(n)\n", + "# Initial conditions (can change to more than one dim)\n", + "x0 = 1.0 \n", + "v0 = 0.0\n", + "x[0] = x0\n", + "v[0] = v0\n", + "gamma = 0.2\n", + "Omegatilde = 0.5\n", + "Ftilde = 1.0\n", + "# Start integrating using Euler's method\n", + "# Note that we define the force function as a SpringForce\n", + "RK4(v,x,t,n,SpringForce)\n", + "\n", + "# Plot position as function of time \n", + "fig, ax = plt.subplots()\n", + "ax.set_ylabel('x[m]')\n", + "ax.set_xlabel('t[s]')\n", + "ax.plot(t, x)\n", + "fig.tight_layout()\n", + "save_fig(\"ForcedBlockRK4\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Principle of Superposition and Periodic Forces (Fourier Transforms)\n", + "\n", + "If one has several driving forces, $F(t)=\\sum_n F_n(t)$, one can find\n", + "the particular solution to each $F_n$, $x_{pn}(t)$, and the particular\n", + "solution for the entire driving force is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x_p(t)=\\sum_nx_{pn}(t).\n", + "\\label{_auto25} \\tag{34}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is known as the principal of superposition. It only applies when\n", + "the homogenous equation is linear. If there were an anharmonic term\n", + "such as $x^3$ in the homogenous equation, then when one summed various\n", + "solutions, $x=(\\sum_n x_n)^2$, one would get cross\n", + "terms. Superposition is especially useful when $F(t)$ can be written\n", + "as a sum of sinusoidal terms, because the solutions for each\n", + "sinusoidal (sine or cosine) term is analytic, as we saw above.\n", + "\n", + "Driving forces are often periodic, even when they are not\n", + "sinusoidal. Periodicity implies that for some time $\\tau$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "F(t+\\tau)=F(t). \n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One example of a non-sinusoidal periodic force is a square wave. Many\n", + "components in electric circuits are non-linear, e.g. diodes, which\n", + "makes many wave forms non-sinusoidal even when the circuits are being\n", + "driven by purely sinusoidal sources.\n", + "\n", + "The code here shows a typical example of such a square wave generated using the functionality included in the **scipy** Python package. We have used a period of $\\tau=0.2$." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import math\n", + "from scipy import signal\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# number of points \n", + "n = 500\n", + "# start and final times \n", + "t0 = 0.0\n", + "tn = 1.0\n", + "# Period \n", + "t = np.linspace(t0, tn, n, endpoint=False)\n", + "SqrSignal = np.zeros(n)\n", + "SqrSignal = 1.0+signal.square(2*np.pi*5*t)\n", + "plt.plot(t, SqrSignal)\n", + "plt.ylim(-0.5, 2.5)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For the sinusoidal example studied in the previous subsections the\n", + "period is $\\tau=2\\pi/\\omega$. However, higher harmonics can also\n", + "satisfy the periodicity requirement. In general, any force that\n", + "satisfies the periodicity requirement can be expressed as a sum over\n", + "harmonics," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "F(t)=\\frac{f_0}{2}+\\sum_{n>0} f_n\\cos(2n\\pi t/\\tau)+g_n\\sin(2n\\pi t/\\tau).\n", + "\\label{_auto26} \\tag{35}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "From the previous subsection, one can write down the answer for\n", + "$x_{pn}(t)$, by substituting $f_n/m$ or $g_n/m$ for $F_0/m$ into Eq.s\n", + "([20](#eq:fastdriven1)) or ([21](#eq:fastdriven2)) respectively. By\n", + "writing each factor $2n\\pi t/\\tau$ as $n\\omega t$, with $\\omega\\equiv\n", + "2\\pi/\\tau$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:fourierdef1} \\tag{36}\n", + "F(t)=\\frac{f_0}{2}+\\sum_{n>0}f_n\\cos(n\\omega t)+g_n\\sin(n\\omega t).\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The solutions for $x(t)$ then come from replacing $\\omega$ with\n", + "$n\\omega$ for each term in the particular solution in Equations\n", + "([13](#eq:partform)) and ([16](#eq:Ddrive))," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x_p(t)&=&\\frac{f_0}{2k}+\\sum_{n>0} \\alpha_n\\cos(n\\omega t-\\delta_n)+\\beta_n\\sin(n\\omega t-\\delta_n),\\\\\n", + "\\nonumber\n", + "\\alpha_n&=&\\frac{f_n/m}{\\sqrt{((n\\omega)^2-\\omega_0^2)+4\\beta^2n^2\\omega^2}},\\\\\n", + "\\nonumber\n", + "\\beta_n&=&\\frac{g_n/m}{\\sqrt{((n\\omega)^2-\\omega_0^2)+4\\beta^2n^2\\omega^2}},\\\\\n", + "\\nonumber\n", + "\\delta_n&=&\\tan^{-1}\\left(\\frac{2\\beta n\\omega}{\\omega_0^2-n^2\\omega^2}\\right).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Because the forces have been applied for a long time, any non-zero\n", + "damping eliminates the homogenous parts of the solution, so one need\n", + "only consider the particular solution for each $n$.\n", + "\n", + "The problem will considered solved if one can find expressions for the\n", + "coefficients $f_n$ and $g_n$, even though the solutions are expressed\n", + "as an infinite sum. The coefficients can be extracted from the\n", + "function $F(t)$ by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:fourierdef2} \\tag{37}\n", + "f_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~F(t)\\cos(2n\\pi t/\\tau),\\\\\n", + "\\nonumber\n", + "g_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~F(t)\\sin(2n\\pi t/\\tau).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To check the consistency of these expressions and to verify\n", + "Eq. ([37](#eq:fourierdef2)), one can insert the expansion of $F(t)$ in\n", + "Eq. ([36](#eq:fourierdef1)) into the expression for the coefficients in\n", + "Eq. ([37](#eq:fourierdef2)) and see whether" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "f_n&=?&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~\\left\\{\n", + "\\frac{f_0}{2}+\\sum_{m>0}f_m\\cos(m\\omega t)+g_m\\sin(m\\omega t)\n", + "\\right\\}\\cos(n\\omega t).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Immediately, one can throw away all the terms with $g_m$ because they\n", + "convolute an even and an odd function. The term with $f_0/2$\n", + "disappears because $\\cos(n\\omega t)$ is equally positive and negative\n", + "over the interval and will integrate to zero. For all the terms\n", + "$f_m\\cos(m\\omega t)$ appearing in the sum, one can use angle addition\n", + "formulas to see that $\\cos(m\\omega t)\\cos(n\\omega\n", + "t)=(1/2)(\\cos[(m+n)\\omega t]+\\cos[(m-n)\\omega t]$. This will integrate\n", + "to zero unless $m=n$. In that case the $m=n$ term gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\int_{-\\tau/2}^{\\tau/2}dt~\\cos^2(m\\omega t)=\\frac{\\tau}{2},\n", + "\\label{_auto27} \\tag{38}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "f_n&=?&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~f_n/2\\\\\n", + "\\nonumber\n", + "&=&f_n~\\checkmark.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The same method can be used to check for the consistency of $g_n$.\n", + "\n", + "\n", + "Consider the driving force:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "F(t)=At/\\tau,~~-\\tau/2\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:fouriersolution} \\tag{40}\n", + "g_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2}dt~\\sin(n\\omega t) \\frac{At}{\\tau}\\\\\n", + "\\nonumber\n", + "u&=&t,~dv=\\sin(n\\omega t)dt,~v=-\\cos(n\\omega t)/(n\\omega),\\\\\n", + "\\nonumber\n", + "g_n&=&\\frac{-2A}{n\\omega \\tau^2}\\int_{-\\tau/2}^{\\tau/2}dt~\\cos(n\\omega t)\n", + "+\\left.2A\\frac{-t\\cos(n\\omega t)}{n\\omega\\tau^2}\\right|_{-\\tau/2}^{\\tau/2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The first term is zero because $\\cos(n\\omega t)$ will be equally\n", + "positive and negative over the interval. Using the fact that\n", + "$\\omega\\tau=2\\pi$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "g_n&=&-\\frac{2A}{2n\\pi}\\cos(n\\omega\\tau/2)\\\\\n", + "\\nonumber\n", + "&=&-\\frac{A}{n\\pi}\\cos(n\\pi)\\\\\n", + "\\nonumber\n", + "&=&\\frac{A}{n\\pi}(-1)^{n+1}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Fourier Series\n", + "\n", + "More text will come here, chpater 5.7-5.8 of Taylor are discussed\n", + "during the lectures. The code here uses the Fourier series discussed\n", + "in chapter 5.7 for a square wave signal. The equations for the\n", + "coefficients are are discussed in Taylor section 5.7, see Example\n", + "5.4. The code here visualizes the various approximations given by\n", + "Fourier series compared with a square wave with period $T=0.2$, witth\n", + "$0.1$ and max value $F=2$. We see that when we increase the number of\n", + "components in the Fourier series, the Fourier series approximation gets closes and closes to the square wave signal." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import math\n", + "from scipy import signal\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# number of points \n", + "n = 500\n", + "# start and final times \n", + "t0 = 0.0\n", + "tn = 1.0\n", + "# Period \n", + "T =0.2\n", + "# Max value of square signal \n", + "Fmax= 2.0\n", + "# Width of signal \n", + "Width = 0.1\n", + "t = np.linspace(t0, tn, n, endpoint=False)\n", + "SqrSignal = np.zeros(n)\n", + "FourierSeriesSignal = np.zeros(n)\n", + "SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T)\n", + "a0 = Fmax*Width/T\n", + "FourierSeriesSignal = a0\n", + "Factor = 2.0*Fmax/np.pi\n", + "for i in range(1,500):\n", + " FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T)\n", + "plt.plot(t, SqrSignal)\n", + "plt.plot(t, FourierSeriesSignal)\n", + "plt.ylim(-0.5, 2.5)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Solving differential equations with Fouries series\n", + "\n", + "The material here was discussed during the lecture of February 19 and 21.\n", + "It is also covered by Taylor in section 5.8.\n", + "\n", + "\n", + "\n", + "## Response to Transient Force\n", + "\n", + "Consider a particle at rest in the bottom of an underdamped harmonic\n", + "oscillator, that then feels a sudden impulse, or change in momentum,\n", + "$I=F\\Delta t$ at $t=0$. This increases the velocity immediately by an\n", + "amount $v_0=I/m$ while not changing the position. One can then solve\n", + "the trajectory by solving Eq. ([9](#eq:homogsolution)) with initial\n", + "conditions $v_0=I/m$ and $x_0=0$. This gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x(t)=\\frac{I}{m\\omega'}e^{-\\beta t}\\sin\\omega't, ~~t>0.\n", + "\\label{_auto29} \\tag{41}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here, $\\omega'=\\sqrt{\\omega_0^2-\\beta^2}$. For an impulse $I_i$ that\n", + "occurs at time $t_i$ the trajectory would be" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x(t)=\\frac{I_i}{m\\omega'}e^{-\\beta (t-t_i)}\\sin[\\omega'(t-t_i)] \\Theta(t-t_i),\n", + "\\label{_auto30} \\tag{42}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\Theta(t-t_i)$ is a step function, i.e. $\\Theta(x)$ is zero for\n", + "$x<0$ and unity for $x>0$. If there were several impulses linear\n", + "superposition tells us that we can sum over each contribution," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "x(t)=\\sum_i\\frac{I_i}{m\\omega'}e^{-\\beta(t-t_i)}\\sin[\\omega'(t-t_i)]\\Theta(t-t_i)\n", + "\\label{_auto31} \\tag{43}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now one can consider a series of impulses at times separated by\n", + "$\\Delta t$, where each impulse is given by $F_i\\Delta t$. The sum\n", + "above now becomes an integral," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\\label{eq:Greeny} \\tag{44}\n", + "x(t)&=&\\int_{-\\infty}^\\infty dt'~F(t')\\frac{e^{-\\beta(t-t')}\\sin[\\omega'(t-t')]}{m\\omega'}\\Theta(t-t')\\\\\n", + "\\nonumber\n", + "&=&\\int_{-\\infty}^\\infty dt'~F(t')G(t-t'),\\\\\n", + "\\nonumber\n", + "G(\\Delta t)&=&\\frac{e^{-\\beta\\Delta t}\\sin[\\omega' \\Delta t]}{m\\omega'}\\Theta(\\Delta t)\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The quantity\n", + "$e^{-\\beta(t-t')}\\sin[\\omega'(t-t')]/m\\omega'\\Theta(t-t')$ is called a\n", + "Green's function, $G(t-t')$. It describes the response at $t$ due to a\n", + "force applied at a time $t'$, and is a function of $t-t'$. The step\n", + "function ensures that the response does not occur before the force is\n", + "applied. One should remember that the form for $G$ would change if the\n", + "oscillator were either critically- or over-damped.\n", + "\n", + "When performing the integral in Eq. ([44](#eq:Greeny)) one can use\n", + "angle addition formulas to factor out the part with the $t'$\n", + "dependence in the integrand," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:Greeny2} \\tag{45}\n", + "x(t)&=&\\frac{1}{m\\omega'}e^{-\\beta t}\\left[I_c(t)\\sin(\\omega't)-I_s(t)\\cos(\\omega't)\\right],\\\\\n", + "\\nonumber\n", + "I_c(t)&\\equiv&\\int_{-\\infty}^t dt'~F(t')e^{\\beta t'}\\cos(\\omega't'),\\\\\n", + "\\nonumber\n", + "I_s(t)&\\equiv&\\int_{-\\infty}^t dt'~F(t')e^{\\beta t'}\\sin(\\omega't').\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the time $t$ is beyond any time at which the force acts,\n", + "$F(t'>t)=0$, the coefficients $I_c$ and $I_s$ become independent of\n", + "$t$.\n", + "\n", + "\n", + "Consider an undamped oscillator ($\\beta\\rightarrow 0$), with\n", + "characteristic frequency $\\omega_0$ and mass $m$, that is at rest\n", + "until it feels a force described by a Gaussian form," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "F(t)&=&F_0 \\exp\\left\\{\\frac{-t^2}{2\\tau^2}\\right\\}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For large times ($t>>\\tau$), where the force has died off, find\n", + "$x(t)$.\\\\ Solve for the coefficients $I_c$ and $I_s$ in\n", + "Eq. ([45](#eq:Greeny2)). Because the Gaussian is an even function,\n", + "$I_s=0$, and one need only solve for $I_c$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "I_c&=&F_0\\int_{-\\infty}^\\infty dt'~e^{-t^{\\prime 2}/(2\\tau^2)}\\cos(\\omega_0 t')\\\\\n", + "&=&\\Re F_0 \\int_{-\\infty}^\\infty dt'~e^{-t^{\\prime 2}/(2\\tau^2)}e^{i\\omega_0 t'}\\\\\n", + "&=&\\Re F_0 \\int_{-\\infty}^\\infty dt'~e^{-(t'-i\\omega_0\\tau^2)^2/(2\\tau^2)}e^{-\\omega_0^2\\tau^2/2}\\\\\n", + "&=&F_0\\tau \\sqrt{2\\pi} e^{-\\omega_0^2\\tau^2/2}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The third step involved completing the square, and the final step used the fact that the integral" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\int_{-\\infty}^\\infty dx~e^{-x^2/2}&=&\\sqrt{2\\pi}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To see that this integral is true, consider the square of the integral, which you can change to polar coordinates," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "I&=&\\int_{-\\infty}^\\infty dx~e^{-x^2/2}\\\\\n", + "I^2&=&\\int_{-\\infty}^\\infty dxdy~e^{-(x^2+y^2)/2}\\\\\n", + "&=&2\\pi\\int_0^\\infty rdr~e^{-r^2/2}\\\\\n", + "&=&2\\pi.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, the expression for $x$ from Eq. ([45](#eq:Greeny2)) is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "x(t>>\\tau)&=&\\frac{F_0\\tau}{m\\omega_0} \\sqrt{2\\pi} e^{-\\omega_0^2\\tau^2/2}\\sin(\\omega_0t).\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The classical pendulum and scaling the equations\n", + "\n", + "Let us end our discussion of oscillations with another classical case, the pendulum.\n", + "\n", + "The angular equation of motion of the pendulum is given by\n", + "Newton's equation and with no external force it reads" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " ml\\frac{d^2\\theta}{dt^2}+mgsin(\\theta)=0,\n", + "\\label{_auto32} \\tag{46}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with an angular velocity and acceleration given by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " v=l\\frac{d\\theta}{dt},\n", + "\\label{_auto33} \\tag{47}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " a=l\\frac{d^2\\theta}{dt^2}.\n", + "\\label{_auto34} \\tag{48}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We do however expect that the motion will gradually come to an end due a viscous drag torque acting on the pendulum. \n", + "In the presence of the drag, the above equation becomes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " ml\\frac{d^2\\theta}{dt^2}+\\nu\\frac{d\\theta}{dt} +mgsin(\\theta)=0, \\label{eq:pend1} \\tag{49}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\nu$ is now a positive constant parameterizing the viscosity\n", + "of the medium in question. In order to maintain the motion against\n", + "viscosity, it is necessary to add some external driving force. \n", + "We choose here a periodic driving force. The last equation becomes then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + " ml\\frac{d^2\\theta}{dt^2}+\\nu\\frac{d\\theta}{dt} +mgsin(\\theta)=Asin(\\omega t), \\label{eq:pend2} \\tag{50}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with $A$ and $\\omega$ two constants representing the amplitude and \n", + "the angular frequency respectively. The latter is called the driving frequency.\n", + "\n", + "\n", + "\n", + "We define" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\omega_0=\\sqrt{g/l},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "the so-called natural frequency and the new dimensionless quantities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\hat{t}=\\omega_0t,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "with the dimensionless driving frequency" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\hat{\\omega}=\\frac{\\omega}{\\omega_0},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and introducing the quantity $Q$, called the *quality factor*," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "Q=\\frac{mg}{\\omega_0\\nu},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and the dimensionless amplitude" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\hat{A}=\\frac{A}{mg}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## More on the Pendulum\n", + "\n", + "We have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d^2\\theta}{d\\hat{t}^2}+\\frac{1}{Q}\\frac{d\\theta}{d\\hat{t}} \n", + " +sin(\\theta)=\\hat{A}cos(\\hat{\\omega}\\hat{t}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This equation can in turn be recast in terms of two coupled first-order differential equations as follows" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d\\theta}{d\\hat{t}}=\\hat{v},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{d\\hat{v}}{d\\hat{t}}=-\\frac{\\hat{v}}{Q}-sin(\\theta)+\\hat{A}cos(\\hat{\\omega}\\hat{t}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "These are the equations to be solved. The factor $Q$ represents the\n", + "number of oscillations of the undriven system that must occur before\n", + "its energy is significantly reduced due to the viscous drag. The\n", + "amplitude $\\hat{A}$ is measured in units of the maximum possible\n", + "gravitational torque while $\\hat{\\omega}$ is the angular frequency of\n", + "the external torque measured in units of the pendulum's natural\n", + "frequency." + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/chapter6.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter6.ipynb new file mode 100644 index 000000000..115823c8a --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/chapter6.ipynb @@ -0,0 +1,2290 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Two-body Problems\n", + "\n", + "\n", + "The gravitational potential energy and forces involving two masses $a$ and $b$ are" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "U_{ab}&=&-\\frac{Gm_am_b}{|\\boldsymbol{r}_a-\\boldsymbol{r}_b|},\\\\\n", + "\\nonumber\n", + "F_{ba}&=&-\\frac{Gm_am_b}{|\\boldsymbol{r}_a-\\boldsymbol{r}_b|^2}\\hat{r}_{ab},\\\\\n", + "\\nonumber\n", + "\\hat{r}_{ab}&=&\\frac{\\boldsymbol{r}_b-\\boldsymbol{r}_a}{|\\boldsymbol{r}_a-\\boldsymbol{r}_b|}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here $G=6.67\\times 10^{-11}$ Nm$^2$/kg$^2$, and $F_{ba}$ is the force\n", + "on $b$ due to $a$. By inspection, one can see that the force on $b$\n", + "due to $a$ and the force on $a$ due to $b$ are equal and opposite. The\n", + "net potential energy for a large number of masses would be" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "U=\\sum_{a\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:radialeqofmotion} \\tag{2}\n", + "\\frac{d}{dt}r^2&=&\\frac{d}{dt}(x^2+y^2)=2x\\dot{x}+2y\\dot{y}=2r\\dot{r},\\\\\n", + "\\nonumber\n", + "\\dot{r}&=&\\frac{x}{r}\\dot{x}+\\frac{y}{r}\\dot{y},\\\\\n", + "\\nonumber\n", + "\\ddot{r}&=&\\frac{x}{r}\\ddot{x}+\\frac{y}{r}\\ddot{y}\n", + "+\\frac{\\dot{x}^2+\\dot{y}^2}{r}\n", + "-\\frac{\\dot{r}^2}{r}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Recognizing that the numerator of the third term is the velocity squared, and that it can be written in polar coordinates," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "v^2=\\dot{x}^2+\\dot{y}^2=\\dot{r}^2+r^2\\dot{\\theta}^2,\n", + "\\label{_auto2} \\tag{3}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "one can write $\\ddot{r}$ as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:radialeqofmotion2} \\tag{4}\n", + "\\ddot{r}&=&\\frac{F_x\\cos\\theta+F_y\\sin\\theta}{m}+\\frac{\\dot{r}^2+r^2\\dot{\\theta}^2}{r}-\\frac{\\dot{r}^2}{r}\\\\\n", + "\\nonumber\n", + "&=&\\frac{F}{m}+\\frac{r^2\\dot{\\theta}^2}{r}\\\\\n", + "\\nonumber\n", + "m\\ddot{r}&=&F+\\frac{L^2}{mr^3}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This derivation used the fact that the force was radial,\n", + "$F=F_r=F_x\\cos\\theta+F_y\\sin\\theta$, and that angular momentum is\n", + "$L=mrv_{\\theta}=mr^2\\dot{\\theta}$. The term $L^2/mr^3=mv^2/r$ behaves\n", + "like an additional force. Sometimes this is referred to as a\n", + "centrifugal force, but it is not a force. Instead, it is the\n", + "consequence of considering the motion in a rotating (and therefore\n", + "accelerating) frame.\n", + "\n", + "Now, we switch to the particular case of an attractive inverse square\n", + "force, $F=-\\alpha/r^2$, and show that the trajectory, $r(\\theta)$, is\n", + "an ellipse. To do this we transform derivatives w.r.t. time to\n", + "derivatives w.r.t. $\\theta$ using the chain rule combined with angular\n", + "momentum conservation, $\\dot{\\theta}=L/mr^2$." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:rtotheta} \\tag{5}\n", + "\\dot{r}&=&\\frac{dr}{d\\theta}\\dot{\\theta}=\\frac{dr}{d\\theta}\\frac{L}{mr^2},\\\\\n", + "\\nonumber\n", + "\\ddot{r}&=&\\frac{d^2r}{d\\theta^2}\\dot{\\theta}^2\n", + "+\\frac{dr}{d\\theta}\\left(\\frac{d}{dr}\\frac{L}{mr^2}\\right)\\dot{r}\\\\\n", + "\\nonumber\n", + "&=&\\frac{d^2r}{d\\theta^2}\\left(\\frac{L}{mr^2}\\right)^2\n", + "-2\\frac{dr}{d\\theta}\\frac{L}{mr^3}\\dot{r}\\\\\n", + "\\nonumber\n", + "&=&\\frac{d^2r}{d\\theta^2}\\left(\\frac{L}{mr^2}\\right)^2\n", + "-\\frac{2}{r}\\left(\\frac{dr}{d\\theta}\\right)^2\\left(\\frac{L}{mr^2}\\right)^2\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Equating the two expressions for $\\ddot{r}$ in Eq.s ([4](#eq:radialeqofmotion2)) and ([5](#eq:rtotheta)) eliminates all the derivatives w.r.t. time, and provides a differential equation with only derivatives w.r.t. $\\theta$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:rdotdot} \\tag{6}\n", + "\\frac{d^2r}{d\\theta^2}\\left(\\frac{L}{mr^2}\\right)^2\n", + "-\\frac{2}{r}\\left(\\frac{dr}{d\\theta}\\right)^2\\left(\\frac{L}{mr^2}\\right)^2\n", + "=\\frac{F}{m}+\\frac{L^2}{m^2r^3},\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "that when solved yields the trajectory, i.e. $r(\\theta)$. Up to this\n", + "point the expressions work for any radial force, not just forces that\n", + "fall as $1/r^2$.\n", + "\n", + "The trick to simplifying this differential equation for the inverse\n", + "square problems is to make a substitution, $u\\equiv 1/r$, and rewrite\n", + "the differential equation for $u(\\theta)$." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "r&=&1/u,\\\\\n", + "\\nonumber\n", + "\\frac{dr}{d\\theta}&=&-\\frac{1}{u^2}\\frac{du}{d\\theta},\\\\\n", + "\\nonumber\n", + "\\frac{d^2r}{d\\theta^2}&=&\\frac{2}{u^3}\\left(\\frac{du}{d\\theta}\\right)^2-\\frac{1}{u^2}\\frac{d^2u}{d\\theta^2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plugging these expressions into Eq. ([6](#eq:rdotdot)) gives an\n", + "expression in terms of $u$, $du/d\\theta$, and $d^2u/d\\theta^2$. After\n", + "some tedious algebra," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{d^2u}{d\\theta^2}=-u-\\frac{F m}{L^2u^2}.\n", + "\\label{_auto3} \\tag{7}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For the attractive inverse square law force, $F=-\\alpha u^2$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{d^2u}{d\\theta^2}=-u+\\frac{m\\alpha}{L^2}.\n", + "\\label{_auto4} \\tag{8}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The solution has two arbitrary constants, $A$ and $\\theta_0$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:Ctrajectory} \\tag{9}\n", + "u&=&\\frac{m\\alpha}{L^2}+A\\cos(\\theta-\\theta_0),\\\\\n", + "\\nonumber\n", + "r&=&\\frac{1}{(m\\alpha/L^2)+A\\cos(\\theta-\\theta_0)}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The radius will be at a minimum when $\\theta=\\theta_0$ and at a\n", + "maximum when $\\theta=\\theta_0+\\pi$. The constant $A$ is related to the\n", + "eccentricity of the orbit. When $A=0$ the radius is a constant\n", + "$r=L^2/(m\\alpha)$, and the motion is circular. If one solved the\n", + "expression $mv^2/r=-\\alpha/r^2$ for a circular orbit, using the\n", + "substitution $v=L/(mr)$, one would reproduce the expression\n", + "$r=L^2/(m\\alpha)$.\n", + "\n", + "The form describing the elliptical trajectory in\n", + "Eq. ([9](#eq:Ctrajectory)) can be identified as an ellipse with one\n", + "focus being the center of the ellipse by considering the definition of\n", + "an ellipse as being the points such that the sum of the two distances\n", + "between the two foci are a constant. Making that distance $2D$, the\n", + "distance between the two foci as $2a$, and putting one focus at the\n", + "origin," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "2D&=&r+\\sqrt{(r\\cos\\theta-2a)^2+r^2\\sin^2\\theta},\\\\\n", + "\\nonumber\n", + "4D^2+r^2-4Dr&=&r^2+4a^2-4ar\\cos\\theta,\\\\\n", + "\\nonumber\n", + "r&=&\\frac{D^2-a^2}{D+a\\cos\\theta}=\\frac{1}{D/(D^2-a^2)-a\\cos\\theta/(D^2-a^2)}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "By inspection, this is the same form as Eq. ([9](#eq:Ctrajectory)) with $D/(D^2-a^2)=m\\alpha/L^2$ and $a/(D^2-a^2)=A$.\n", + "\n", + "\n", + "Let us remind ourselves about what an ellipse is before we proceed." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "\n", + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "from math import pi\n", + "\n", + "u=1. #x-position of the center\n", + "v=0.5 #y-position of the center\n", + "a=2. #radius on the x-axis\n", + "b=1.5 #radius on the y-axis\n", + "\n", + "t = np.linspace(0, 2*pi, 100)\n", + "plt.plot( u+a*np.cos(t) , v+b*np.sin(t) )\n", + "plt.grid(color='lightgray',linestyle='--')\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Effective or Centrifugal Potential\n", + "\n", + "The total energy of a particle is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "E&=&U(r)+\\frac{1}{2}mv_\\theta^2+\\frac{1}{2}m\\dot{r}^2\\\\\n", + "\\nonumber\n", + "&=&U(r)+\\frac{1}{2}mr^2\\dot{\\theta}^2+\\frac{1}{2}m\\dot{r}^2\\\\\n", + "\\nonumber\n", + "&=&U(r)+\\frac{L^2}{2mr^2}+\\frac{1}{2}m\\dot{r}^2.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The second term then contributes to the energy like an additional\n", + "repulsive potential. The term is sometimes referred to as the\n", + "\"centrifugal\" potential, even though it is actually the kinetic energy\n", + "of the angular motion. Combined with $U(r)$, it is sometimes referred\n", + "to as the \"effective\" potential," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "U_{\\rm eff}(r)&=&U(r)+\\frac{L^2}{2mr^2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that if one treats the effective potential like a real potential, one would expect to be able to generate an effective force," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "F_{\\rm eff}&=&-\\frac{d}{dr}U(r) -\\frac{d}{dr}\\frac{L^2}{2mr^2}\\\\\n", + "\\nonumber\n", + "&=&F(r)+\\frac{L^2}{mr^3}=F(r)+m\\frac{v_\\perp^2}{r},\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which is indeed matches the form for $m\\ddot{r}$ in Eq. ([4](#eq:radialeqofmotion2)), which included the **centrifugal** force.\n", + "\n", + "The following code plots this effective potential for a simple choice of parameters, with a standard gravitational potential $-\\alpha/r$. Here we have chosen $L=m=\\alpha=1$." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Common imports\n", + "import numpy as np\n", + "from math import *\n", + "import matplotlib.pyplot as plt\n", + "\n", + "Deltax = 0.01\n", + "#set up arrays\n", + "xinitial = 0.3\n", + "xfinal = 5.0\n", + "alpha = 1.0 # spring constant\n", + "m = 1.0 # mass, you can change these\n", + "AngMom = 1.0 # The angular momentum\n", + "n = ceil((xfinal-xinitial)/Deltax)\n", + "x = np.zeros(n)\n", + "for i in range(n):\n", + " x[i] = xinitial+i*Deltax\n", + "V = np.zeros(n)\n", + "V = -alpha/x+0.5*AngMom*AngMom/(m*x*x)\n", + "# Plot potential\n", + "fig, ax = plt.subplots()\n", + "ax.set_xlabel('r[m]')\n", + "ax.set_ylabel('V[J]')\n", + "ax.plot(x, V)\n", + "fig.tight_layout()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Gravitational force example\n", + "\n", + "Using the above parameters, we can now study the evolution of the system using for example the velocity Verlet method.\n", + "This is done in the code here for an initial radius equal to the minimum of the potential well. We seen then that the radius is always the same and corresponds to a circle (the radius is always constant)." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Common imports\n", + "import numpy as np\n", + "import pandas as pd\n", + "from math import *\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "\n", + "# Where to save the figures and data files\n", + "PROJECT_ROOT_DIR = \"Results\"\n", + "FIGURE_ID = \"Results/FigureFiles\"\n", + "DATA_ID = \"DataFiles/\"\n", + "\n", + "if not os.path.exists(PROJECT_ROOT_DIR):\n", + " os.mkdir(PROJECT_ROOT_DIR)\n", + "\n", + "if not os.path.exists(FIGURE_ID):\n", + " os.makedirs(FIGURE_ID)\n", + "\n", + "if not os.path.exists(DATA_ID):\n", + " os.makedirs(DATA_ID)\n", + "\n", + "def image_path(fig_id):\n", + " return os.path.join(FIGURE_ID, fig_id)\n", + "\n", + "def data_path(dat_id):\n", + " return os.path.join(DATA_ID, dat_id)\n", + "\n", + "def save_fig(fig_id):\n", + " plt.savefig(image_path(fig_id) + \".png\", format='png')\n", + "\n", + "\n", + "# Simple Gravitational Force -alpha/r\n", + " \n", + "DeltaT = 0.01\n", + "#set up arrays \n", + "tfinal = 100.0\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, v and r\n", + "t = np.zeros(n)\n", + "v = np.zeros(n)\n", + "r = np.zeros(n)\n", + "# Constants of the model, setting all variables to one for simplicity\n", + "alpha = 1.0\n", + "AngMom = 1.0 # The angular momentum\n", + "m = 1.0 # scale mass to one\n", + "c1 = AngMom*AngMom/(m*m)\n", + "c2 = AngMom*AngMom/m\n", + "rmin = (AngMom*AngMom/m/alpha)\n", + "# Initial conditions\n", + "r0 = rmin\n", + "v0 = 0.0\n", + "r[0] = r0\n", + "v[0] = v0\n", + "# Start integrating using the Velocity-Verlet method\n", + "for i in range(n-1):\n", + " # Set up acceleration\n", + " a = -alpha/(r[i]**2)+c1/(r[i]**3)\n", + " # update velocity, time and position using the Velocity-Verlet method\n", + " r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a\n", + " anew = -alpha/(r[i+1]**2)+c1/(r[i+1]**3)\n", + " v[i+1] = v[i] + 0.5*DeltaT*(a+anew)\n", + " t[i+1] = t[i] + DeltaT\n", + " # Plot position as function of time\n", + "fig, ax = plt.subplots(2,1)\n", + "ax[0].set_xlabel('time')\n", + "ax[0].set_ylabel('radius')\n", + "ax[0].plot(t,r)\n", + "ax[1].set_xlabel('time')\n", + "ax[1].set_ylabel('Velocity')\n", + "ax[1].plot(t,v)\n", + "save_fig(\"RadialGVV\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Changing the value of the initial position to a value where the energy is positive, leads to an increasing radius with time, a so-called unbound orbit. Choosing on the other hand an initial radius that corresponds to a negative energy and different from the minimum value leads to a radius that oscillates back and forth between two values. \n", + "\n", + "### Harmonic Oscillator in two dimensions\n", + "\n", + "Consider a particle of mass $m$ in a 2-dimensional harmonic oscillator with potential" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "U=\\frac{1}{2}kr^2=\\frac{1}{2}k(x^2+y^2).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the orbit has angular momentum $L$, we can find the radius and angular velocity of the circular orbit as well as the b) the angular frequency of small radial perturbations.\n", + "\n", + "We consider the effective potential. The radius of a circular orbit is at the minimum of the potential (where the effective force is zero).\n", + "The potential is plotted here with the parameters $k=m=0.1$ and $L=1.0$." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Common imports\n", + "import numpy as np\n", + "from math import *\n", + "import matplotlib.pyplot as plt\n", + "\n", + "Deltax = 0.01\n", + "#set up arrays\n", + "xinitial = 1.0\n", + "xfinal = 5.0\n", + "k = 0.1 # spring constant\n", + "m = 0.1 # mass, you can change these\n", + "AngMom = 1.0 # The angular momentum\n", + "n = ceil((xfinal-xinitial)/Deltax)\n", + "x = np.zeros(n)\n", + "for i in range(n):\n", + " x[i] = xinitial+i*Deltax\n", + "V = np.zeros(n)\n", + "V = 0.5*k*x*x+0.5*AngMom*AngMom/(m*x*x)\n", + "# Plot potential\n", + "fig, ax = plt.subplots()\n", + "ax.set_xlabel('r[m]')\n", + "ax.set_ylabel('V[J]')\n", + "ax.plot(x, V)\n", + "fig.tight_layout()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "U_{\\rm eff}&=&\\frac{1}{2}kr^2+\\frac{L^2}{2mr^2}\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The effective potential looks like that of a harmonic oscillator for\n", + "large $r$, but for small $r$, the centrifugal potential repels the\n", + "particle from the origin. The combination of the two potentials has a\n", + "minimum for at some radius $r_{\\rm min}$." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "0&=&kr_{\\rm min}-\\frac{L^2}{mr_{\\rm min}^3},\\\\\n", + "r_{\\rm min}&=&\\left(\\frac{L^2}{mk}\\right)^{1/4},\\\\\n", + "\\dot{\\theta}&=&\\frac{L}{mr_{\\rm min}^2}=\\sqrt{k/m}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For particles at $r_{\\rm min}$ with $\\dot{r}=0$, the particle does not\n", + "accelerate and $r$ stays constant, i.e. a circular orbit. The radius\n", + "of the circular orbit can be adjusted by changing the angular momentum\n", + "$L$.\n", + "\n", + "For the above parameters this minimum is at $r_{\\rm min}=1$.\n", + "\n", + " Now consider small vibrations about $r_{\\rm min}$. The effective spring constant is the curvature of the effective potential." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "k_{\\rm eff}&=&\\left.\\frac{d^2}{dr^2}U_{\\rm eff}(r)\\right|_{r=r_{\\rm min}}=k+\\frac{3L^2}{mr_{\\rm min}^4}\\\\\n", + "&=&4k,\\\\\n", + "\\omega&=&\\sqrt{k_{\\rm eff}/m}=2\\sqrt{k/m}=2\\dot{\\theta}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here, the second step used the result of the last step from part\n", + "(a). Because the radius oscillates with twice the angular frequency,\n", + "the orbit has two places where $r$ reaches a minimum in one\n", + "cycle. This differs from the inverse-square force where there is one\n", + "minimum in an orbit. One can show that the orbit for the harmonic\n", + "oscillator is also elliptical, but in this case the center of the\n", + "potential is at the center of the ellipse, not at one of the foci.\n", + "\n", + "The solution is also simple to write down exactly in Cartesian coordinates. The $x$ and $y$ equations of motion separate," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\ddot{x}&=&-kx,\\\\\n", + "\\ddot{y}&=&-ky.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So the general solution can be expressed as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "x&=&A\\cos\\omega_0 t+B\\sin\\omega_0 t,\\\\\n", + "y&=&C\\cos\\omega_0 t+D\\sin\\omega_0 t.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The code here finds the solution for $x$ and $y$ using the code we developed in homework 4." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "\n", + "DeltaT = 0.01\n", + "#set up arrays \n", + "tfinal = 10.0\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays\n", + "t = np.zeros(n)\n", + "v = np.zeros((n,2))\n", + "r = np.zeros((n,2))\n", + "radius = np.zeros(n)\n", + "# Constants of the model\n", + "k = 0.1 # spring constant\n", + "m = 0.1 # mass, you can change these\n", + "omega02 = sqrt(k/m) # Frequency\n", + "AngMom = 1.0 # The angular momentum\n", + "rmin = (AngMom*AngMom/k/m)**0.25\n", + "# Initial conditions as compact 2-dimensional arrays\n", + "#x0 =rmin*0.5; y0 = sqrt(rmin*rmin-x0*x0)\n", + "x0 = 1.0; y0= 1.0\n", + "r0 = np.array([x0,y0]) \n", + "v0 = np.array([0.0,0.0])\n", + "r[0] = r0\n", + "v[0] = v0\n", + "# Start integrating using the Velocity-Verlet method\n", + "for i in range(n-1):\n", + " # Set up the acceleration\n", + " a = -r[i]*omega02 \n", + " # update velocity, time and position using the Velocity-Verlet method\n", + " r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a\n", + " anew = -r[i+1]*omega02 \n", + " v[i+1] = v[i] + 0.5*DeltaT*(a+anew)\n", + " t[i+1] = t[i] + DeltaT\n", + "# Plot position as function of time\n", + "radius = np.sqrt(r[:,0]**2+r[:,1]**2)\n", + "fig, ax = plt.subplots(3,1)\n", + "ax[0].set_xlabel('time')\n", + "ax[0].set_ylabel('radius squared')\n", + "ax[0].plot(t,r[:,0]**2+r[:,1]**2)\n", + "ax[1].set_xlabel('time')\n", + "ax[1].set_ylabel('x position')\n", + "ax[1].plot(t,r[:,0])\n", + "ax[2].set_xlabel('time')\n", + "ax[2].set_ylabel('y position')\n", + "ax[2].plot(t,r[:,1])\n", + "\n", + "fig.tight_layout()\n", + "save_fig(\"2DimHOVV\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With some work using double angle formulas, one can calculate" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "r^2&=&x^2+y^2\\\\\n", + "\\nonumber\n", + "&=&(A^2+C^2)\\cos^2(\\omega_0t)+(B^2+D^2)\\sin^2\\omega_0t+(AB+CD)\\cos(\\omega_0t)\\sin(\\omega_0t)\\\\\n", + "\\nonumber\n", + "&=&\\alpha+\\beta\\cos 2\\omega_0 t+\\gamma\\sin 2\\omega_0 t,\\\\\n", + "\\alpha&=&\\frac{A^2+B^2+C^2+D^2}{2},~~\\beta=\\frac{A^2-B^2+C^2-D^2}{2},~~\\gamma=AB+CD,\\\\\n", + "r^2&=&\\alpha+(\\beta^2+\\gamma^2)^{1/2}\\cos(2\\omega_0 t-\\delta),~~~\\delta=\\arctan(\\gamma/\\beta),\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and see that radius oscillates with frequency $2\\omega_0$. The\n", + "factor of two comes because the oscillation $x=A\\cos\\omega_0t$ has two\n", + "maxima for $x^2$, one at $t=0$ and one a half period later.\n", + "\n", + "The following code shows first how we can solve this problem using the radial degrees of freedom only." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "DeltaT = 0.01\n", + "#set up arrays \n", + "tfinal = 10.0\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, v and r\n", + "t = np.zeros(n)\n", + "v = np.zeros(n)\n", + "r = np.zeros(n)\n", + "E = np.zeros(n)\n", + "# Constants of the model\n", + "AngMom = 1.0 # The angular momentum\n", + "m = 0.1\n", + "k = 0.1\n", + "omega02 = k/m\n", + "c1 = AngMom*AngMom/(m*m)\n", + "c2 = AngMom*AngMom/m\n", + "rmin = (AngMom*AngMom/k/m)**0.25\n", + "# Initial conditions\n", + "r0 = rmin\n", + "v0 = 0.0\n", + "r[0] = r0\n", + "v[0] = v0\n", + "E[0] = 0.5*m*v0*v0+0.5*k*r0*r0+0.5*c2/(r0*r0)\n", + "# Start integrating using the Velocity-Verlet method\n", + "for i in range(n-1):\n", + " # Set up acceleration\n", + " a = -r[i]*omega02+c1/(r[i]**3) \n", + " # update velocity, time and position using the Velocity-Verlet method\n", + " r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a\n", + " anew = -r[i+1]*omega02+c1/(r[i+1]**3)\n", + " v[i+1] = v[i] + 0.5*DeltaT*(a+anew)\n", + " t[i+1] = t[i] + DeltaT\n", + " E[i+1] = 0.5*m*v[i+1]*v[i+1]+0.5*k*r[i+1]*r[i+1]+0.5*c2/(r[i+1]*r[i+1])\n", + " # Plot position as function of time\n", + "fig, ax = plt.subplots(2,1)\n", + "ax[0].set_xlabel('time')\n", + "ax[0].set_ylabel('radius')\n", + "ax[0].plot(t,r)\n", + "ax[1].set_xlabel('time')\n", + "ax[1].set_ylabel('Energy')\n", + "ax[1].plot(t,E)\n", + "save_fig(\"RadialHOVV\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Stability of Orbits\n", + "\n", + "The effective force can be extracted from the effective potential, $U_{\\rm eff}$. Beginning from the equations of motion, Eq. ([2](#eq:radialeqofmotion)), for $r$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "m\\ddot{r}&=&F+\\frac{L^2}{mr^3}\\\\\n", + "\\nonumber\n", + "&=&F_{\\rm eff}\\\\\n", + "\\nonumber\n", + "&=&-\\partial_rU_{\\rm eff},\\\\\n", + "\\nonumber\n", + "F_{\\rm eff}&=&-\\partial_r\\left[U(r)+(L^2/2mr^2)\\right].\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For a circular orbit, the radius must be fixed as a function of time,\n", + "so one must be at a maximum or a minimum of the effective\n", + "potential. However, if one is at a maximum of the effective potential\n", + "the radius will be unstable. For the attractive Coulomb force the\n", + "effective potential will be dominated by the $-\\alpha/r$ term for\n", + "large $r$ because the centrifugal part falls off more quickly, $\\sim\n", + "1/r^2$. At low $r$ the centrifugal piece wins and the effective\n", + "potential is repulsive. Thus, the potential must have a minimum\n", + "somewhere with negative potential. The circular orbits are then stable\n", + "to perturbation.\n", + "\n", + "\n", + "The effective potential is sketched for two cases, a $1/r$ attractive\n", + "potential and a $1/r^3$ attractive potential. The $1/r$ case has a\n", + "stable minimum, whereas the circular orbit in the $1/r^3$ case is\n", + "unstable.\n", + "\n", + "\n", + "If one considers a potential that falls as $1/r^3$, the situation is\n", + "reversed and the point where $\\partial_rU$ disappears will be a local\n", + "maximum rather than a local minimum. **Fig to come here with code**\n", + "\n", + "The repulsive centrifugal piece dominates at large $r$ and the attractive\n", + "Coulomb piece wins out at small $r$. The circular orbit is then at a\n", + "maximum of the effective potential and the orbits are unstable. It is\n", + "the clear that for potentials that fall as $r^n$, that one must have\n", + "$n>-2$ for the orbits to be stable.\n", + "\n", + "\n", + "Consider a potential $U(r)=\\beta r$. For a particle of mass $m$ with\n", + "angular momentum $L$, find the angular frequency of a circular\n", + "orbit. Then find the angular frequency for small radial perturbations.\n", + "\n", + "\n", + "For the circular orbit you search for the position $r_{\\rm min}$ where the effective potential is minimized," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\partial_r\\left\\{\\beta r+\\frac{L^2}{2mr^2}\\right\\}&=&0,\\\\\n", + "\\beta&=&\\frac{L^2}{mr_{\\rm min}^3},\\\\\n", + "r_{\\rm min}&=&\\left(\\frac{L^2}{\\beta m}\\right)^{1/3},\\\\\n", + "\\dot{\\theta}&=&\\frac{L}{mr_{\\rm min}^2}=\\frac{\\beta^{2/3}}{(mL)^{1/3}}\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, we can find the angular frequency of small perturbations about the circular orbit. To do this we find the effective spring constant for the effective potential," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "k_{\\rm eff}&=&\\partial_r^2 \\left.U_{\\rm eff}\\right|_{r_{\\rm min}}\\\\\n", + "&=&\\frac{3L^2}{mr_{\\rm min}^4},\\\\\n", + "\\omega&=&\\sqrt{\\frac{k_{\\rm eff}}{m}}\\\\\n", + "&=&\\frac{\\beta^{2/3}}{(mL)^{1/3}}\\sqrt{3}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the two frequencies, $\\dot{\\theta}$ and $\\omega$, differ by an\n", + "integer factor, the orbit's trajectory will repeat itself each time\n", + "around. This is the case for the inverse-square force,\n", + "$\\omega=\\dot{\\theta}$, and for the harmonic oscillator,\n", + "$\\omega=2\\dot{\\theta}$. In this case, $\\omega=\\sqrt{3}\\dot{\\theta}$,\n", + "and the angles at which the maxima and minima occur change with each\n", + "orbit.\n", + "\n", + "\n", + "### Code example with gravitional force\n", + "\n", + "The code example here is meant to illustrate how we can make a plot of the final orbit. We solve the equations in polar coordinates (the example here uses the minimum of the potential as initial value) and then we transform back to cartesian coordinates and plot $x$ versus $y$. We see that we get a perfect circle when we place ourselves at the minimum of the potential energy, as expected." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "\n", + "# Simple Gravitational Force -alpha/r\n", + " \n", + "DeltaT = 0.01\n", + "#set up arrays \n", + "tfinal = 8.0\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays for t, v and r\n", + "t = np.zeros(n)\n", + "v = np.zeros(n)\n", + "r = np.zeros(n)\n", + "phi = np.zeros(n)\n", + "x = np.zeros(n)\n", + "y = np.zeros(n)\n", + "# Constants of the model, setting all variables to one for simplicity\n", + "alpha = 1.0\n", + "AngMom = 1.0 # The angular momentum\n", + "m = 1.0 # scale mass to one\n", + "c1 = AngMom*AngMom/(m*m)\n", + "c2 = AngMom*AngMom/m\n", + "rmin = (AngMom*AngMom/m/alpha)\n", + "# Initial conditions, place yourself at the potential min\n", + "r0 = rmin\n", + "v0 = 0.0 # starts at rest\n", + "r[0] = r0\n", + "v[0] = v0\n", + "phi[0] = 0.0\n", + "# Start integrating using the Velocity-Verlet method\n", + "for i in range(n-1):\n", + " # Set up acceleration\n", + " a = -alpha/(r[i]**2)+c1/(r[i]**3)\n", + " # update velocity, time and position using the Velocity-Verlet method\n", + " r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a\n", + " anew = -alpha/(r[i+1]**2)+c1/(r[i+1]**3)\n", + " v[i+1] = v[i] + 0.5*DeltaT*(a+anew)\n", + " t[i+1] = t[i] + DeltaT\n", + " phi[i+1] = t[i+1]*c2/(r0**2)\n", + "# Find cartesian coordinates for easy plot \n", + "x = r*np.cos(phi)\n", + "y = r*np.sin(phi)\n", + "fig, ax = plt.subplots(3,1)\n", + "ax[0].set_xlabel('time')\n", + "ax[0].set_ylabel('radius')\n", + "ax[0].plot(t,r)\n", + "ax[1].set_xlabel('time')\n", + "ax[1].set_ylabel('Angle $\\cos{\\phi}$')\n", + "ax[1].plot(t,np.cos(phi))\n", + "ax[2].set_ylabel('y')\n", + "ax[2].set_xlabel('x')\n", + "ax[2].plot(x,y)\n", + "\n", + "save_fig(\"Phasespace\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Try to change the initial value for $r$ and see what kind of orbits you get.\n", + "In order to test different energies, it can be useful to look at the plot of the effective potential discussed above.\n", + "\n", + "However, for orbits different from a circle the above code would need modifications in order to allow us to display say an ellipse. For the latter, it is much easier to run our code in cartesian coordinates, as done here. In this code we test also energy conservation and see that it is conserved to numerical precision. The code here is a simple extension of the code we developed for homework 4." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Common imports\n", + "import numpy as np\n", + "import pandas as pd\n", + "from math import *\n", + "import matplotlib.pyplot as plt\n", + "\n", + "DeltaT = 0.01\n", + "#set up arrays \n", + "tfinal = 10.0\n", + "n = ceil(tfinal/DeltaT)\n", + "# set up arrays\n", + "t = np.zeros(n)\n", + "v = np.zeros((n,2))\n", + "r = np.zeros((n,2))\n", + "E = np.zeros(n)\n", + "# Constants of the model\n", + "m = 1.0 # mass, you can change these\n", + "alpha = 1.0\n", + "# Initial conditions as compact 2-dimensional arrays\n", + "x0 = 0.5; y0= 0.\n", + "r0 = np.array([x0,y0]) \n", + "v0 = np.array([0.0,1.0])\n", + "r[0] = r0\n", + "v[0] = v0\n", + "rabs = sqrt(sum(r[0]*r[0]))\n", + "E[0] = 0.5*m*(v[0,0]**2+v[0,1]**2)-alpha/rabs\n", + "# Start integrating using the Velocity-Verlet method\n", + "for i in range(n-1):\n", + " # Set up the acceleration\n", + " rabs = sqrt(sum(r[i]*r[i]))\n", + " a = -alpha*r[i]/(rabs**3)\n", + " # update velocity, time and position using the Velocity-Verlet method\n", + " r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a\n", + " rabs = sqrt(sum(r[i+1]*r[i+1]))\n", + " anew = -alpha*r[i+1]/(rabs**3)\n", + " v[i+1] = v[i] + 0.5*DeltaT*(a+anew)\n", + " E[i+1] = 0.5*m*(v[i+1,0]**2+v[i+1,1]**2)-alpha/rabs\n", + " t[i+1] = t[i] + DeltaT\n", + "# Plot position as function of time\n", + "fig, ax = plt.subplots(3,1)\n", + "ax[0].set_ylabel('y')\n", + "ax[0].set_xlabel('x')\n", + "ax[0].plot(r[:,0],r[:,1])\n", + "ax[1].set_xlabel('time')\n", + "ax[1].set_ylabel('y position')\n", + "ax[1].plot(t,r[:,0])\n", + "ax[2].set_xlabel('time')\n", + "ax[2].set_ylabel('y position')\n", + "ax[2].plot(t,r[:,1])\n", + "\n", + "fig.tight_layout()\n", + "save_fig(\"2DimGravity\")\n", + "plt.show()\n", + "print(E)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Scattering and Cross Sections\n", + "\n", + "Scattering experiments don't measure entire trajectories. For elastic\n", + "collisions, they measure the distribution of final scattering angles\n", + "at best. Most experiments use targets thin enough so that the number\n", + "of scatterings is typically zero or one. The cross section, $\\sigma$,\n", + "describes the cross-sectional area for particles to scatter with an\n", + "individual target atom or nucleus. Cross section measurements form the\n", + "basis for MANY fields of physics. BThe cross section, and the\n", + "differential cross section, encapsulates everything measurable for a\n", + "collision where all that is measured is the final state, e.g. the\n", + "outgoing particle had momentum $\\boldsymbol{p}_f$. y studying cross sections,\n", + "one can infer information about the potential interaction between the\n", + "two particles. Inferring, or constraining, the potential from the\n", + "cross section is a classic {\\it inverse} problem. Collisions are\n", + "either elastic or inelastic. Elastic collisions are those for which\n", + "the two bodies are in the same internal state before and after the\n", + "collision. If the collision excites one of the participants into a\n", + "higher state, or transforms the particles into different species, or\n", + "creates additional particles, the collision is inelastic. Here, we\n", + "consider only elastic collisions.\n", + "\n", + "For Coulomb forces, the cross section is infinite because the range of\n", + "the Coulomb force is infinite, but for interactions such as the strong\n", + "interaction in nuclear or particle physics, there is no long-range\n", + "force and cross-sections are finite. Even for Coulomb forces, the part\n", + "of the cross section that corresponds to a specific scattering angle,\n", + "$d\\sigma/d\\Omega$, which is a function of the scattering angle\n", + "$\\theta_s$ is still finite.\n", + "\n", + "If a particle travels through a thin target, the chance the particle\n", + "scatters is $P_{\\rm scatt}=\\sigma dN/dA$, where $dN/dA$ is the number\n", + "of scattering centers per area the particle encounters. If the density\n", + "of the target is $\\rho$ particles per volume, and if the thickness of\n", + "the target is $t$, the areal density (number of target scatterers per\n", + "area) is $dN/dA=\\rho t$. Because one wishes to quantify the collisions\n", + "independently of the target, experimentalists measure scattering\n", + "probabilities, then divide by the areal density to obtain\n", + "cross-sections," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "\\sigma=\\frac{P_{\\rm scatt}}{dN/dA}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instead of merely stating that a particle collided, one can measure\n", + "the probability the particle scattered by a given angle. The\n", + "scattering angle $\\theta_s$ is defined so that at zero the particle is\n", + "unscattered and at $\\theta_s=\\pi$ the particle is scattered directly\n", + "backward. Scattering angles are often described in the center-of-mass\n", + "frame, but that is a detail we will neglect for this first discussion,\n", + "where we will consider the scattering of particles moving classically\n", + "under the influence of fixed potentials $U(\\boldsymbol{r})$. Because the\n", + "distribution of scattering angles can be measured, one expresses the\n", + "differential cross section," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{d^2\\sigma}{d\\cos\\theta_s~d\\phi}.\n", + "\\label{_auto5} \\tag{10}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Usually, the literature expresses differential cross sections as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "d\\sigma/d\\Omega=\\frac{d\\sigma}{d\\cos\\theta d\\phi}=\\frac{1}{2\\pi}\\frac{d\\sigma}{d\\cos\\theta},\n", + "\\label{_auto6} \\tag{11}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where the last equivalency is true when the scattering does not depend\n", + "on the azimuthal angle $\\phi$, as is the case for spherically\n", + "symmetric potentials.\n", + "\n", + "The differential solid angle $d\\Omega$ can be thought of as the area\n", + "subtended by a measurement, $dA_d$, divided by $r^2$, where $r$ is the\n", + "distance to the detector," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "dA_d=r^2 d\\Omega.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With this definition $d\\sigma/d\\Omega$ is independent of the distance\n", + "from which one places the detector, or the size of the detector (as\n", + "long as it is small).\n", + "\n", + "Differential scattering cross sections are calculated by assuming a\n", + "random distribution of impact parameters $b$. These represent the\n", + "distance in the $xy$ plane for particles moving in the $z$ direction\n", + "relative to the scattering center. An impact parameter $b=0$ refers to\n", + "being aimed directly at the target's center. The impact parameter\n", + "describes the transverse distance from the $z=0$ axis for the\n", + "trajectory when it is still far away from the scattering center and\n", + "has not yet passed it. The differential cross section can be expressed\n", + "in terms of the impact parameter," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "d\\sigma=2\\pi bdb,\n", + "\\label{_auto7} \\tag{12}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which is the area of a thin ring of radius $b$ and thickness $db$. In\n", + "classical physics, one can calculate the trajectory given the incoming\n", + "kinetic energy $E$ and the impact parameter if one knows the mass and\n", + "potential. From the trajectory, one then finds the scattering angle\n", + "$\\theta_s(b)$. The differential cross section is then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{d\\sigma}{d\\Omega}=\\frac{1}{2\\pi}\\frac{d\\sigma}{d\\cos\\theta_s}=b\\frac{db}{d\\cos\\theta_s}=\\frac{b}{(d/db)\\cos\\theta_s(b)}.\n", + "\\label{_auto8} \\tag{13}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Typically, one would calculate $\\cos\\theta_s$ and $(d/db)\\cos\\theta_s$\n", + "as functions of $b$. This is sufficient to plot the differential cross\n", + "section as a function of $\\theta_s$.\n", + "\n", + "The total cross section is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\sigma_{\\rm tot}=\\int d\\Omega\\frac{d\\sigma}{d\\Omega}=2\\pi\\int d\\cos\\theta_s~\\frac{d\\sigma}{d\\Omega}. \n", + "\\label{_auto9} \\tag{14}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Even if the total cross section is infinite, e.g. Coulomb forces, one\n", + "can still have a finite differential cross section as we will see\n", + "later on.\n", + "\n", + "\n", + "An asteroid of mass $m$ and kinetic energy $E$ approaches a planet of\n", + "radius $R$ and mass $M$. What is the cross section for the asteroid to\n", + "impact the planet?\n", + "\n", + "### Solution\n", + "\n", + "Calculate the maximum impact parameter, $b_{\\rm max}$, for which the asteroid will hit the planet. The total cross section for impact is $\\sigma_{\\rm impact}=\\pi b_{\\rm max}^2$. The maximum cross-section can be found with the help of angular momentum conservation. The asteroid's incoming momentum is $p_0=\\sqrt{2mE}$ and the angular momentum is $L=p_0b$. If the asteroid just grazes the planet, it is moving with zero radial kinetic energy at impact. Combining energy and angular momentum conservation and having $p_f$ refer to the momentum of the asteroid at a distance $R$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\frac{p_f^2}{2m}-\\frac{GMm}{R}&=&E,\\\\\n", + "p_fR&=&p_0b_{\\rm max},\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "allows one to solve for $b_{\\rm max}$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "b_{\\rm max}&=&R\\frac{p_f}{p_0}\\\\\n", + "&=&R\\frac{\\sqrt{2m(E+GMm/R)}}{\\sqrt{2mE}}\\\\\n", + "\\sigma_{\\rm impact}&=&\\pi R^2\\frac{E+GMm/R}{E}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Rutherford Scattering\n", + "\n", + "This refers to the calculation of $d\\sigma/d\\Omega$ due to an inverse\n", + "square force, $F_{12}=\\pm\\alpha/r^2$ for repulsive/attractive\n", + "interaction. Rutherford compared the scattering of $\\alpha$ particles\n", + "($^4$He nuclei) off of a nucleus and found the scattering angle at\n", + "which the formula began to fail. This corresponded to the impact\n", + "parameter for which the trajectories would strike the nucleus. This\n", + "provided the first measure of the size of the atomic nucleus. At the\n", + "time, the distribution of the positive charge (the protons) was\n", + "considered to be just as spread out amongst the atomic volume as the\n", + "electrons. After Rutherford's experiment, it was clear that the radius\n", + "of the nucleus tended to be roughly 4 orders of magnitude smaller than\n", + "that of the atom, which is less than the size of a football relative\n", + "to Spartan Stadium.\n", + "\n", + "\n", + "\n", + "The incoming and outgoing angles of the trajectory are at\n", + "$\\pm\\theta'$. They are related to the scattering angle by\n", + "$2\\theta'=\\pi+\\theta_s$.\n", + "\n", + "In order to calculate differential cross section, we must find how the\n", + "impact parameter is related to the scattering angle. This requires\n", + "analysis of the trajectory. We consider our previous expression for\n", + "the trajectory where we derived the elliptic form for the trajectory,\n", + "Eq. ([9](#eq:Ctrajectory)). For that case we considered an attractive\n", + "force with the particle's energy being negative, i.e. it was\n", + "bound. However, the same form will work for positive energy, and\n", + "repulsive forces can be considered by simple flipping the sign of\n", + "$\\alpha$. For positive energies, the trajectories will be hyperbolas,\n", + "rather than ellipses, with the asymptotes of the trajectories\n", + "representing the directions of the incoming and outgoing\n", + "tracks. Rewriting Eq. ([9](#eq:Ctrajectory))," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\\label{eq:ruthtraj} \\tag{15}\n", + "r=\\frac{1}{\\frac{m\\alpha}{L^2}+A\\cos\\theta}.\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once $A$ is large enough, which will happen when the energy is\n", + "positive, the denominator will become negative for a range of\n", + "$\\theta$. This is because the scattered particle will never reach\n", + "certain angles. The asymptotic angles $\\theta'$ are those for which\n", + "the denominator goes to zero," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\cos\\theta'=-\\frac{m\\alpha}{AL^2}.\n", + "\\label{_auto10} \\tag{16}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The trajectory's point of closest approach is at $\\theta=0$ and the\n", + "two angles $\\theta'$, which have this value of $\\cos\\theta'$, are the\n", + "angles of the incoming and outgoing particles. From\n", + "Fig (**to come**), one can see that the scattering angle\n", + "$\\theta_s$ is given by," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:sthetover2} \\tag{17}\n", + "2\\theta'-\\pi&=&\\theta_s,~~~\\theta'=\\frac{\\pi}{2}+\\frac{\\theta_s}{2},\\\\\n", + "\\nonumber\n", + "\\sin(\\theta_s/2)&=&-\\cos\\theta'\\\\\n", + "\\nonumber\n", + "&=&\\frac{m\\alpha}{AL^2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now that we have $\\theta_s$ in terms of $m,\\alpha,L$ and $A$, we wish\n", + "to re-express $L$ and $A$ in terms of the impact parameter $b$ and the\n", + "energy $E$. This will set us up to calculate the differential cross\n", + "section, which requires knowing $db/d\\theta_s$. It is easy to write\n", + "the angular momentum as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "L^2=p_0^2b^2=2mEb^2.\n", + "\\label{_auto11} \\tag{18}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finding $A$ is more complicated. To accomplish this we realize that\n", + "the point of closest approach occurs at $\\theta=0$, so from\n", + "Eq. ([15](#eq:ruthtraj))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:rminofA} \\tag{19}\n", + "\\frac{1}{r_{\\rm min}}&=&\\frac{m\\alpha}{L^2}+A,\\\\\n", + "\\nonumber\n", + "A&=&\\frac{1}{r_{\\rm min}}-\\frac{m\\alpha}{L^2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, $r_{\\rm min}$ can be found in terms of the energy because at the\n", + "point of closest approach the kinetic energy is due purely to the\n", + "motion perpendicular to $\\hat{r}$ and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "E=-\\frac{\\alpha}{r_{\\rm min}}+\\frac{L^2}{2mr_{\\rm min}^2}.\n", + "\\label{_auto12} \\tag{20}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One can solve the quadratic equation for $1/r_{\\rm min}$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\frac{1}{r_{\\rm min}}=\\frac{m\\alpha}{L^2}+\\sqrt{(m\\alpha/L^2)^2+2mE/L^2}.\n", + "\\label{_auto13} \\tag{21}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can plug the expression for $r_{\\rm min}$ into the expression for $A$, Eq. ([19](#eq:rminofA))," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "A=\\sqrt{(m\\alpha/L^2)^2+2mE/L^2}=\\sqrt{(\\alpha^2/(4E^2b^4)+1/b^2}\n", + "\\label{_auto14} \\tag{22}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, we insert the expression for $A$ into that for the scattering angle, Eq. ([17](#eq:sthetover2))," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:scattangle} \\tag{23}\n", + "\\sin(\\theta_s/2)&=&\\frac{m\\alpha}{AL^2}\\\\\n", + "\\nonumber\n", + "&=&\\frac{a}{\\sqrt{a^2+b^2}}, ~~a\\equiv \\frac{\\alpha}{2E}\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The differential cross section can now be found by differentiating the\n", + "expression for $\\theta_s$ with $b$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:rutherford} \\tag{24}\n", + "\\frac{1}{2}\\cos(\\theta_s/2)d\\theta_s&=&\\frac{ab~db}{(a^2+b^2)^{3/2}}=\\frac{bdb}{a^2}\\sin^3(\\theta_s/2),\\\\\n", + "\\nonumber\n", + "d\\sigma&=&2\\pi bdb=\\frac{\\pi a^2}{\\sin^3(\\theta_s/2)}\\cos(\\theta_s/2)d\\theta_s\\\\\n", + "\\nonumber\n", + "&=&\\frac{\\pi a^2}{2\\sin^4(\\theta_s/2)}\\sin\\theta_s d\\theta_s\\\\\n", + "\\nonumber\n", + "\\frac{d\\sigma}{d\\cos\\theta_s}&=&\\frac{\\pi a^2}{2\\sin^4(\\theta_s/2)},\\\\\n", + "\\nonumber\n", + "\\frac{d\\sigma}{d\\Omega}&=&\\frac{a^2}{4\\sin^4(\\theta_s/2)}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $a= \\alpha/2E$. This the Rutherford formula for the differential\n", + "cross section. It diverges as $\\theta_s\\rightarrow 0$ because\n", + "scatterings with arbitrarily large impact parameters still scatter to\n", + "arbitrarily small scattering angles. The expression for\n", + "$d\\sigma/d\\Omega$ is the same whether the interaction is positive or\n", + "negative.\n", + "\n", + "\n", + "Consider a particle of mass $m$ and charge $z$ with kinetic energy $E$\n", + "(Let it be the center-of-mass energy) incident on a heavy nucleus of\n", + "mass $M$ and charge $Z$ and radius $R$. Find the angle at which the\n", + "Rutherford scattering formula breaks down.\n", + "\n", + "### Solution\n", + "\n", + "Let $\\alpha=Zze^2/(4\\pi\\epsilon_0)$. The scattering angle in Eq. ([23](#eq:scattangle)) is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\sin(\\theta_s/2)=\\frac{a}{\\sqrt{a^2+b^2}}, ~~a\\equiv \\frac{\\alpha}{2E}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The impact parameter $b$ for which the point of closest approach\n", + "equals $R$ can be found by using angular momentum conservation," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "p_0b&=&b\\sqrt{2mE}=Rp_f=R\\sqrt{2m(E-\\alpha/R)},\\\\\n", + "b&=&R\\frac{\\sqrt{2m(E-\\alpha/R)}}{\\sqrt{2mE}}\\\\\n", + "&=&R\\sqrt{1-\\frac{\\alpha}{ER}}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Putting these together" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\theta_s=2\\sin^{-1}\\left\\{\n", + "\\frac{a}{\\sqrt{a^2+R^2(1-\\alpha/(RE))}}\n", + "\\right\\},~~~a=\\frac{\\alpha}{2E}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It was from this departure of the experimentally measured\n", + "$d\\sigma/d\\Omega$ from the Rutherford formula that allowed Rutherford\n", + "to infer the radius of the gold nucleus, $R$.\n", + "\n", + "\n", + "\n", + "Just like electrodynamics, one can define \"fields\", which for a small\n", + "additional mass $m$ are the force per mass and the additional\n", + "potential energy per mass. The {\\it gravitational field} related to\n", + "the force has dimensions of force per mass, or acceleration, and can\n", + "be labeled $\\boldsymbol{g}(\\boldsymbol{r})$. The potential energy per mass has\n", + "dimensions of energy per mass. This is analogous to the\n", + "electromagnetic potential, which is the potential energy per charge,\n", + "and the electric field which is the force per charge.\n", + "\n", + "Because the field $\\boldsymbol{g}$ obeys the same inverse square law for a\n", + "point mass as the electric field does for a point charge, the\n", + "gravitational field also satisfies a version of Gauss's law," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\label{eq:GravGauss} \\tag{25}\n", + "\\oint d\\boldsymbol{A}\\cdot\\boldsymbol{g}=-4\\pi GM_{\\rm inside}.\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here, $M_{\\rm inside}$ is the net mass inside a closed area.\n", + "\n", + "Gauss's law can be understood by considering a nozzle that sprays\n", + "paint in all directions uniformly from a point source. Let $B$ be the\n", + "number of gallons per minute of paint leaving the nozzle. If the\n", + "nozzle is at the center of a sphere of radius $r$, the paint per\n", + "square meter per minute that is deposited on some part of the sphere\n", + "is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "F(r)&=&\\frac{B}{4\\pi r^2}.\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, let $F$ also be assigned a direction, so that it becomes a vector\n", + "pointing along the direction of the flying paint. For any surface that\n", + "surrounds the nozzle, not necessarily a sphere, one can state that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray}\n", + "\\label{eq:paint} \\tag{26}\n", + "\\oint \\boldsymbol{dA}\\cdot\\boldsymbol{F}&=&B,\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "regardless of the shape of the surface. This follows because the rate\n", + "at which paint is deposited on the surface should equal the rate at\n", + "which it leaves the nozzle. The dot product ensures that only the\n", + "component of $\\boldsymbol{F}$ into the surface contributes to the deposition\n", + "of paint. Similarly, if $\\boldsymbol{F}$ is any radial inverse-square forces,\n", + "that falls as $B/(4\\pi r^2)$, then one can apply\n", + "Eq. ([26](#eq:paint)). For gravitational fields, $B/(4\\pi)$ is replaced\n", + "by $GM$, and one quickly \"derives\" Gauss's law for gravity,\n", + "Eq. ([25](#eq:GravGauss)).\n", + "\n", + "\n", + "Consider Earth to have its mass $M$ uniformly distributed in a sphere\n", + "of radius $R$. Find the magnitude of the gravitational acceleration as\n", + "a function of the radius $r$ in terms of the acceleration of gravity\n", + "at the surface $g(R)$. Assume $r\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "F=-\\frac{GM\\delta m}{D^2}+2\\frac{GM\\delta m}{D^3}\\Delta D+\\cdots\n", + "\\label{_auto15} \\tag{27}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the $z$ direction points toward the large object, $\\Delta D$ can be\n", + "referred to as $z$. In the accelerating frame of an observer at the\n", + "center of the planet," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\delta m\\frac{d^2 z}{dt^2}=F-\\delta ma'+{\\rm other~forces~acting~on~} \\delta m,\n", + "\\label{_auto16} \\tag{28}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $a'$ is the acceleration of the observer. Because $\\delta ma'$\n", + "equals the gravitational force on $\\delta m$ if it were located at the\n", + "planet's center, one can write" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "m\\frac{d^2z}{dt^2}=2\\frac{GM\\delta m}{D^3}z+{\\rm other~forces~acting~on~}\\delta m.\n", + "\\label{_auto17} \\tag{29}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here the other forces could represent the forces acting on $\\delta m$\n", + "from the spherical planet such as the gravitational force or the\n", + "contact force with the surface. If $\\theta$ is the angle w.r.t. the\n", + "$z$ axis, the effective force acting on $\\delta m$ is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "F_{\\rm eff}\\approx 2\\frac{GM\\delta m}{D^3}r\\cos\\theta\\hat{z}+{\\rm other~forces~acting~on~}\\delta m.\n", + "\\label{_auto18} \\tag{30}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This first force is the \"tidal\" force. It pulls objects outward from the center of the object. If the object were covered with water, it would distort the objects shape so that the shape would be elliptical, stretched out along the axis pointing toward the large mass $M$. The force is always along (either parallel or antiparallel to) the $\\hat{z}$ direction.\n", + "\n", + "\n", + "Consider the Earth to be a sphere of radius $R$ covered with water,\n", + "with the gravitational acceleration at the surface noted by $g$. Now\n", + "assume that a distant body provides an additional constant\n", + "gravitational acceleration $\\boldsymbol{a}$ pointed along the $z$ axis. Find\n", + "the distortion of the radius as a function of $\\theta$. Ignore\n", + "planetary rotation and assume $a<\n", + "\n", + "\n", + "

\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "shows the relation between the two\n", + "frames. The position of an object in frame $S$ relative to $S_0$ is\n", + "labeled as $\\boldsymbol{r}_{S_0}$. Seen from this inertial frame, an object in\n", + "the accelerating frame obeys Newton's second law" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "m\\frac{d^2\\boldsymbol{r}_{S_0}}{dt^2}=\\boldsymbol{F}.\n", + "\\label{_auto1} \\tag{1}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here $\\boldsymbol{F}$ is the net force on an object in the accelerating frame\n", + "seen from the inertial frame.\n", + "\n", + "If we on the other hand wish to study the motion of this object (say a\n", + "ball in an accelerating car) relative to the accelerating frame, we\n", + "need to define its position relative to this frame. We label this\n", + "position as $\\boldsymbol{r}_{S}$.\n", + "\n", + "Using the definition of velocity as the time derivative of position\n", + "and the standard vector addition of velocities, we can define the\n", + "velocity relative to $S_0$ as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{r}}_{S_0}=\\dot{\\boldsymbol{r}}_{S}+\\boldsymbol{v}_{S_0}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The left hand side in the last equation defines the object's velocity\n", + "relative to the inertial frame. The right hand side says this is the\n", + "object's velocity relative to the accelerating frame plus the velocity\n", + "of the accelerating frame with respect to the inertial frame. If we\n", + "now take the second derivative of the above equation,\n", + "we have the corresponding accelerations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\ddot{\\boldsymbol{r}}_{S_0}=\\ddot{\\boldsymbol{r}}_{S}+\\boldsymbol{a}_{S_0}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Multiplying with the mass of a given object, we can rewrite Newton's\n", + "law in the accelerating frame as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\ddot{\\boldsymbol{r}}_{S}=\\boldsymbol{F}-\\boldsymbol{a}_{S_0}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We see that we have again Newton's second law except that we added a\n", + "correction which defines an effective acceleration compared to the\n", + "equation seen in the inertial frame. We can thus continue to use\n", + "Newton's law in the accelerating frame provided we correct the\n", + "equation of motion with what is often called a fictitious force. This\n", + "often also called an inertial force or an effective force.\n", + "\n", + "**Add example about pendulum in train car**\n", + "\n", + "## Rotating Frames\n", + "\n", + "\n", + "If you are on Earth's surface and if your reference frame is fixed\n", + "with the surface, this is an example of an accelerating frame, where\n", + "the acceleration, as we will show below, is $\\Omega^2 r$, where\n", + "$r\\equiv\\sqrt{x^2+y^2}$, and $\\Omega$ is the angular velocity\n", + "of Earth's rotation. The acceleration is inward toward the axis of\n", + "rotation, so the additional contribution to the apparent acceleration\n", + "of gravity is outward in the $x-y$ plane. In contrast the usual\n", + "acceleration $\\boldsymbol{g}$ is radially inward pointing toward the origin.\n", + "\n", + "We will now deal with motion in a rotating frame and relate this to an\n", + "inertial frame. The outcome of our derivations will be effective\n", + "forces (or inertial forces) like the abovementioned acceleration (from\n", + "the centrifugal force) and the Coriolis force term.\n", + "\n", + "For a reference frame that rotates with respect to an inertial frame,\n", + "**Euler's theorem** is central here. It states that the most general\n", + "displacement (motion) of a rigid body with a one point fixed (we\n", + "normally approximate a rigid body with a mass center) is a rotation\n", + "about some fixed axis. In different words, the most general motion of\n", + "any body relative to a fixed point $O$ is a rotation abotu some axis\n", + "through the same point $O$. This means that for a specific rotation\n", + "about a given point $O$ we only to specify the direction of the axis\n", + "about which the rotation occurs with the corresponding angle of\n", + "rotation. As we will see below, the direction of the angle of rotation\n", + "can be specified by a unit vector $\\boldsymbol{e}$ in the rotating frame and\n", + "the rate of rotation per unit time. The latter defines the angular\n", + "velocity $\\Omega$. We will define these quantities more rigorously below.\n", + "At the end of this section we will also prove Euler's theorem.\n", + "\n", + "What we will show here is that Newton's laws for an object in the rotating frame is given by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\ddot{\\boldsymbol{r}}_{S}=\\boldsymbol{F}+m\\boldsymbol{r}\\times\\dot{\\boldsymbol{\\Omega}}+2m\\boldsymbol{v}_S\\times\\boldsymbol{\\Omega}+m\\left(\\boldsymbol{\\Omega}\\times\\boldsymbol{r}\\right)\\times\\boldsymbol{\\Omega}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The first term to the right is the force we defined in the inertial\n", + "system, that is $m\\ddot{\\boldsymbol{r}}_{S_0}=\\boldsymbol{F}$. The second term is the\n", + "angular acceleration of the rotating reference frame, a quantity which\n", + "in many cases is set to zero since we assume that the angular velocity\n", + "is constant as function of time. The third terms is the Coriolis force, that\n", + "is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Coriolis}}=2m\\boldsymbol{v}_S\\times\\boldsymbol{\\Omega},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "while the last term is going to give us the standard centrifugal force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Centrifugal}}=m\\left(\\boldsymbol{\\Omega}\\times\\boldsymbol{r}\\right)\\times\\boldsymbol{\\Omega}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let us derive these terms, following much of the same procedure as we\n", + "did for an accelerating reference frame. The figure here (to come)\n", + "shows the two reference systems $S$ and $S_0$.\n", + "\n", + "\n", + "We define a general vector $\\boldsymbol{A}$. It could represent the position,\n", + "a given force, the velocity and other quantities of interest for\n", + "studies of the equations of motion.\n", + "\n", + "We let this vector to be defined by three orthogonal (we assume motion\n", + "in three dimensions) unit vectors $\\boldsymbol{e}_i$, that is we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{A}=A_1\\boldsymbol{e}_1+A_2\\boldsymbol{e}_2+A_3\\boldsymbol{e}_3=\\sum_iA_i\\boldsymbol{e}_i.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "These unit vectors are fixed in the rotating frame, that is their time\n", + "derivatives are zero. However, for an observer in the inertial frame\n", + "$S_0$, however these unit vectors are rotating and may thus have an\n", + "explicit time dependence.\n", + "\n", + "Since we want to find an expression for the equations of motion in the\n", + "inertial frame and the rotating frame, we need expressions for the\n", + "time derivative of a vector $\\boldsymbol{A}$ in these two frames. Since the\n", + "unit vectors are assumed to be fixed in $S$, we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{A}}_S=\\sum_i\\frac{dA_i}{dt}\\boldsymbol{e}_i=\\sum_i\\dot{dA_i}\\boldsymbol{e}_i.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the inertial frame $S_0$ we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{A}}_{S_0}=\\sum_i\\dot{dA_i}\\boldsymbol{e}_i+\\sum_i A_i\\left(\\dot{\\boldsymbol{e}}_i\\right)_{S_0}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will show below that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\left(\\dot{\\boldsymbol{e}}_i\\right)_{S_0}=\\Omega\\times\\boldsymbol{e}_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\Omega$ is the angular velocity (to be derived below). This\n", + "means we can write the derivative of an arbitrary vector $\\boldsymbol{A}$ in\n", + "the inertial frame $S_0$ as (the vector is defined in the rotating\n", + "frame)," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{A}}_{S_0}=\\sum_i\\dot{dA_i}\\boldsymbol{e}_i+\\sum_i A_i\\left(\\dot{\\boldsymbol{e}}_i\\right)_{S_0}=\\dot{\\boldsymbol{A}}_S+\\sum_i A_i(\\Omega\\times\\boldsymbol{e}_i)=\\dot{\\boldsymbol{A}}_S+\\boldsymbol{\\Omega}\\times\\boldsymbol{A}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is a very useful relation which relates the derivative of any\n", + "vector $\\boldsymbol{A}$ measured in the inertial frame $S_0$ to the\n", + "correspoding derivative in a rotating frame $S$.\n", + "\n", + "If we now let $\\boldsymbol{A}$ be the position and the velocity vectors, we\n", + "can derive the equations of motion in the rotating frame in terms of\n", + "the same equations of motion in the inertial frame $S_0$.\n", + "\n", + "Let us start with the position $\\boldsymbol{r}$. \n", + "\n", + "We have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{r}}_{S_0}=\\dot{\\boldsymbol{r}}_S+\\boldsymbol{\\Omega}\\times\\boldsymbol{r}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If we define the velocities in the two frames as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{v}_{S_0}=\\dot{\\boldsymbol{r}}_{S_0},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{v}_{S}=\\dot{\\boldsymbol{r}}_{S},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "we have then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{r}}_{S_0}=\\boldsymbol{v}_{S_0}=\\boldsymbol{v}_{S}+\\boldsymbol{\\Omega}\\times\\boldsymbol{r}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In order to find the equations of motion, we need the acceleration and\n", + "thereby the time derivative of the last equation. The derivative of\n", + "the angular velocity $\\Omega$ will turn in handy in these derivations\n", + "(repeated applications of the chain rule again).\n", + "The latter derivative is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{\\Omega}}_{S_0}=\\dot{\\boldsymbol{\\Omega}}_S+\\boldsymbol{\\Omega}\\times\\boldsymbol{\\Omega},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which leads to (an expected result, why?)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\dot{\\boldsymbol{\\Omega}}_{S_0}=\\dot{\\boldsymbol{\\Omega}}_S,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "since $\\boldsymbol{\\Omega}\\times\\boldsymbol{\\Omega}=0$. \n", + "\n", + "Let us now take the second derivative with respect to time.\n", + "\n", + "Using" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\left[\\frac{d^2\\boldsymbol{r}}{dt^2}\\right]_{S_0}=\\ddot{\\boldsymbol{r}}_{S_0}=\\left[\\frac{d}{dt}\\right]_{S_0}\\left[\\frac{d\\boldsymbol{r}}{dt}\\right]_{S_0},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\ddot{\\boldsymbol{r}}_{S_0}=\\left[\\frac{d}{dt}\\right]_{S_0}\\left[\\boldsymbol{v}_{S}+\\boldsymbol{\\Omega}\\times\\boldsymbol{r}\\right]=\\left[\\frac{d}{dt}\\right]_{S_0}\\boldsymbol{v}_{S_0},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\ddot{\\boldsymbol{r}}_{S_0}=\\left[\\frac{d\\boldsymbol{v}_S}{dt}\\right]_{S}+\\dot{\\boldsymbol{\\Omega}}\\times \\boldsymbol{r}+2\\boldsymbol{\\Omega}\\times\\boldsymbol{v}_S+\\boldsymbol{\\Omega}\\times(\\boldsymbol{\\Omega}\\times\\boldsymbol{r}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Defining the accelerations $\\boldsymbol{a}_{S_0}=\\ddot{\\boldsymbol{r}}_{S_0}=\\dot{\\boldsymbol{v}}_{S_0}$ and $\\boldsymbol{a}_{S}=\\dot{\\boldsymbol{v}}_{S}$, we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{a}_{S_0}=\\boldsymbol{a}_{S}+\\dot{\\boldsymbol{\\Omega}}\\times \\boldsymbol{r}+2\\boldsymbol{\\Omega}\\times\\boldsymbol{v}_S+\\boldsymbol{\\Omega}\\times(\\boldsymbol{\\Omega}\\times\\boldsymbol{r}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If we now use Newton's law in the inertial frame $\\boldsymbol{F}=m\\boldsymbol{a}_{S_0}$, we get the effective force in the rotating frame (multiplying by the mass $m$)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\boldsymbol{a}_{S}=\\boldsymbol{F}+m\\dot{\\boldsymbol{r}\\times\\boldsymbol{\\Omega}}+2m\\boldsymbol{v}_S\\times\\boldsymbol{\\Omega}+m(\\boldsymbol{\\Omega}\\times\\boldsymbol{r})\\times\\boldsymbol{\\Omega},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which is what we wanted to demostrate. We have the Coriolis force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Coriolis}}=2m\\boldsymbol{v}_S\\times\\boldsymbol{\\Omega},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "while the last term is the standard centrifugal force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Centrifugal}}=m\\left(\\boldsymbol{\\Omega}\\times\\boldsymbol{r}\\right)\\times\\boldsymbol{\\Omega}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In our discussions below we will assume that the angular acceleration of the rotating frame is zero and focus only on the Coriolis force and the centrifugal force.\n", + "\n", + "\n", + "\n", + "### Effective potential and Centrifugal force\n", + "\n", + "Suppose we can ignore the Coriolis force. If we focus only on the\n", + "centrifugal force we have an additional force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Centrifugal}}=m\\left(\\boldsymbol{\\Omega}\\times\\boldsymbol{r}\\right)\\times\\boldsymbol{\\Omega},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where the term $\\boldsymbol{\\Omega}\\times\\boldsymbol{r}$ is the radial velocity.\n", + "\n", + "Consider now an object with position $\\boldsymbol{r}$ according to an observer in a frame\n", + "rotating about the $z$ axis with angular velocity\n", + "$\\boldsymbol{\\Omega}=\\Omega\\hat{z}$. To an observer in the inertial frame\n", + "the vector will change even if the vector appears\n", + "fixed to the rotating observer.\n", + "\n", + "\n", + "If $\\boldsymbol{\\Omega}$ is in the $z$ direction,\n", + "the centrifugal force becomes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\boldsymbol{F}_{\\mathrm{Centrifugal}}=m\\Omega^2(x\\hat{x}+y\\hat{y}).\n", + "\\label{_auto2} \\tag{2}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The centrifugal force points outward in the $x-y$ plane, and its\n", + "magnitude is $m\\Omega^2r$, where\n", + "$r=\\sqrt{x^2+y^2}$.\n", + "\n", + "Continuing along these lines, \n", + "if we define a rotating frame which makes an angle $\\theta$ with the inertial frame and define the distance to an object in this frame from the origin as $\\boldsymbol{r}$, then the centrifugal force (which points outward) has as magnitude $\\Omega^2r\\sin{\\theta}$. Defining $\\rho=r\\sin{\\theta}$ and the unit vector $\\hat{\\boldsymbol{\\rho}}$ (see figure here)\n", + "\n", + "\n", + "\n", + "

\n", + "\n", + "\n", + "\n", + "\n", + "we have the well-known expression for the centrifugal force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Centrifugal}}=m\\Omega^2\\rho\\hat{\\boldsymbol{\\rho}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and with the velocity given by its magnitude $v=\\Omega\\rho$ we obtain the well-known expression for the centrifugal force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Centrifugal}}=m\\frac{v^2}{\\rho}{\\boldsymbol{\\rho}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If we now go back again to our falling object discussed in the\n", + "beginning of these lectures, we need to modify for the fact that the Earth\n", + "is rotating with respect to the falling object.\n", + "\n", + "Seen from a rotating coordinate system we have now that the forces acting on the falling object are" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\ddot{\\boldsymbol{r}}=\\boldsymbol{F}_{\\mathrm{gravity}}+\\boldsymbol{F}_{\\mathrm{Centrifugal}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If we define the mass of Earth as $M$ and its radius as $R$ and assuming that the object is close to the Earth, the gravitational force takes then well-known expression" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{gravity}}=-\\frac{GMm}{R^2}\\hat{\\boldsymbol{r}}=m\\boldsymbol{g}_0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Inserting the expression for the centrifugal force, we can then define an effective force" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{eff}}=\\boldsymbol{F}_{\\mathrm{gravity}}+\\boldsymbol{F}_{\\mathrm{Centrifugal}}=m\\boldsymbol{g}_0-m\\Omega^2R\\sin{(\\theta)}\\hat{\\boldsymbol{\\rho}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and with" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{g}_{\\mathrm{eff}}=\\boldsymbol{g}_0-\\Omega^2R\\sin{(\\theta)}\\hat{\\boldsymbol{\\rho}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{eff}}=m\\boldsymbol{g}_{\\mathrm{eff}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the rotating coordinate system (not an inertial frame), motion is\n", + "thus determined by an apparent force and one can define effective\n", + "potentials. In addition to the normal gravitational potential energy,\n", + "there is a contribution to the effective potential," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\\delta V_{\\rm eff}(r)=-\\frac{m}{2}\\Omega^2r^2=-\\frac{m}{2}r^2\\Omega^2\\sin^2\\theta,\n", + "\\label{_auto3} \\tag{3}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\theta$ is the polar angle, measured from say the north\n", + "pole. If the true gravitational force can be considered as originating\n", + "from a point in Earth's center, the net effective potential for a mass\n", + "$m$ near Earth's surface could be (a distance $h$)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "V_{\\rm eff}=mgh-m\\frac{1}{2}\\Omega^2(R+h)^2\\sin^2\\theta.\n", + "\\label{_auto4} \\tag{4}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As an example, let us ask ourselves how much wider is Earth at the\n", + "equator than the north-south distance between the poles assuming that\n", + "the gravitational field above the surface can be approximated by that\n", + "of a point mass at Earth's center.\n", + "\n", + "\n", + "The surface of the ocean must be at constant effective potential for a\n", + "sample mass $m$. This means that if $h$ now refers to the height of\n", + "the water" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m g[h(\\theta=\\pi/2)-h(\\theta=0)]=\\frac{m}{2}\\Omega^2(R+h)^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Because $R>>h$, one can approximate $R+h\\rightarrow R$ on the right-hand side, thus" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "h(\\theta=\\pi)-h(\\theta=0)=\\frac{\\Omega^2R^2}{2g}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This come out a bit less than 11 km, or a difference of near 22 km for\n", + "the diameter of the Earth in the equatorial plane compared to a\n", + "diameter between the poles. In reality, the difference is\n", + "approximately 41 km. The discrepancy comes from the assumption that\n", + "the true gravitational force can be treated as if it came from a point\n", + "at Earth's center. This would be true if the distribution of mass was\n", + "radially symmetric. However, Earth's center is molten and the rotation\n", + "distorts the mass distribution. Remarkably this effect nearly doubles\n", + "the elliptic distortion of Earth's shape. Due to this distortion, the\n", + "top of Mount Everest is not the furthest point from the center of the\n", + "Earth. That belongs to the top of a volcano, Chimborazo, in Equador,\n", + "which is one degree in latitude below the Equator. Chimborazo is about\n", + "8500 ft lower than Everest when measured relative to sea level, but is\n", + "7700 feet further from the center of the Earth.\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "## Coriolis Force and Falling Objects\n", + "\n", + "The Coriolis force is given by" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{F}_{\\mathrm{Coriolis}}=2m\\boldsymbol{v}_S\\times\\boldsymbol{\\Omega},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It does not enter problems like the shape of the Earth\n", + "above because in that case the water was not moving relative to the\n", + "rotating frame. \n", + "\n", + "The Coriolis force is non-zero only if $\\boldsymbol{v}_S\\ne 0$ and is directed\n", + "perpendicular to both $\\boldsymbol{v}_S$ and $\\Omega$. Viewed along the\n", + "direction of $\\boldsymbol{v}_S$, the Coriolis force associated with\n", + "counter-clockwise rotational motion produces a deflection to the\n", + "right. For clockwise rotational motion, it produces a deflection to\n", + "the left.\n", + "\n", + "The Coriolis force associated with Earth’s rotational motion is\n", + "responsible for the circulating or cyclonic weather patterns\n", + "associated with hurricanes and cyclones, as illustrated in the figure\n", + "here. Basically, a pressure gradient gives rise to air currents that\n", + "tend to flow from high pressure to low pressure regions. But as the\n", + "air flows toward the low pressure region, the Coriolis force deflects\n", + "the air currents away from their straight line paths. Since the\n", + "projection of $\\Omega$ perpendicular to the local tangent plane\n", + "changes sign as one crosses the equator, the direction of the cyclonic\n", + "motion (either counter-clockwise or clockwise) is different in the\n", + "Northern and Southern hemispheres.\n", + "\n", + "\n", + "\n", + "

\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "As an example, assume a ball is dropped from a height $h=500$m above Minneapolis. Due to the\n", + "Coriolis force, it is deflected by an amount $\\delta x$ and $\\delta\n", + "y$. We want to find the deflection due to the Coriolis force. Here we ignore the centrifugal terms.\n", + "\n", + "The equations of motion are:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\frac{dv_x}{dt}&=&-2(\\Omega_yv_z-\\Omega_zv_y),\\\\\n", + "\\frac{dv_y}{dt}&=&-2(\\Omega_zv_x-\\Omega_xv_z),\\\\\n", + "\\frac{dv_z}{dt}&=&-g-2(\\Omega_xv_y-\\Omega_yv_x),\\\\\n", + "\\Omega_z&=&\\Omega\\cos\\theta,~~~\\Omega_y=\\Omega\\sin\\theta,~~~\\Omega_x=0.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here the coordinate system is $\\hat{x}$ and points east, $\\hat{y}$ points\n", + "north and $\\hat{z}$ points upward.\n", + "\n", + "One can now ignore all the Coriolis terms on the right-hand sides\n", + "except for those with $v_z$. The other terms will all be doubly\n", + "small. One can also throw out terms with $\\Omega_x$. This gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\frac{dv_x}{dt}&\\approx& -2\\Omega v_z\\sin\\theta,\\\\\n", + "\\frac{dv_y}{dt}&\\approx& 0,\\\\\n", + "\\frac{dv_z}{dt}&\\approx& -g.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There will be no significant deflection in the $y$ direction, $\\delta\n", + "y=0$, but in the $x$ direction one can substitute $v_z=-gt$ above," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "v_x&\\approx&\\int_0^t dt'~2\\Omega gt'\\sin\\theta=\\Omega gt^2\\sin\\theta,\\\\\n", + "\\delta x&\\approx& \\int_0^t dt'~v_x(t')=\\frac{g\\Omega\\sin\\theta t^3}{3}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One can find the deflections by using $h=\\frac{1}{2}gt^2$, to find the\n", + "time, and using the all-knowing internet to see that the latitude of\n", + "Minneapolis is $44.6^\\circ$ or $\\theta=45.4^\\circ$." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "t&=&\\sqrt{2h/g}=10.1~{\\rm s},\\\\\n", + "\\Omega&=&\\frac{2\\pi}{3600\\cdot 24~{\\rm s}}=7.27\\times 10^{-5}~{\\rm s}^{-1},\\\\\n", + "\\delta x&=&17.4~{\\rm cm}~~{\\rm(east)}.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Accelerating and Rotating Frames\n", + "\n", + "It is now simple to bring together the equations for an accelerating and rotating frame. Using our results we have the equations of motion for an object in an accelerating and rotating frame with respect to an inertial frame" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "m\\ddot{\\boldsymbol{r}}_{S}=\\boldsymbol{F}+m\\boldsymbol{r}\\times\\dot{\\boldsymbol{\\Omega}}+2m\\boldsymbol{v}_S\\times\\boldsymbol{\\Omega}+m\\left(\\boldsymbol{\\Omega}\\times\\boldsymbol{r}\\right)\\times\\boldsymbol{\\Omega}-\\boldsymbol{a}_{S_0},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where the last term is the acceleration of the accelerating frame seen from the inertial frame.\n", + "\n", + "\n", + "## The Foucault Pendulum\n", + "\n", + "\n", + "\n", + "The [Foucault\n", + "Pendulum](https://en.wikipedia.org/wiki/Foucault_pendulum) is simply\n", + "a regular pendulum moving in both horizontal directions, and with the\n", + "Coriolis force included. It is explained at its simplest if we\n", + "consider a pendulum positioned at the North pole. Foucault's\n", + "experiment was actually the first laboratory demonstration that the\n", + "Earth is rotating. The experiment is rather simple and many physics\n", + "department worldwide have their own pendulum.\n", + "\n", + "In the original experiment done in Paris in 1851, Foucault used a\n", + "massive pendulum of 28kg and 67m long.\n", + "\n", + "If use an inertial frame with the North pole as its origin, the Earth\n", + "below the pendulum rotates with a period of 24h (actually 23h and\n", + "56min). Seen with respect to the surface of the Earth, the plane of\n", + "the pendulum moves in the opposite direction of the rotation of the Earth.\n", + "\n", + "If we were to perform the experiment in other places, the setup is slightly more complicated since the pendulum will then rotate with the Earth. The net effect is a slower rotation compared to North pole.\n", + "\n", + "\n", + "\n", + "\n", + "

\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Let us look at the equations we need to solve." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "m\\ddot{\\boldsymbol{r}}&=&\\boldsymbol{T}+m\\boldsymbol{g}-2m\\boldsymbol{\\Omega}\\times\\boldsymbol{v},\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "as the centrifugal force term is absorbed into the definition of\n", + "$\\boldsymbol{g}$. The magnitude of the tension, $\\boldsymbol{T}$, is considered\n", + "constant because we consider only small oscillations. Then $T\\approx mg$, and the components, using $\\hat{x},\\hat{y}$ to correspond to east\n", + "and north respectively, are" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "T_x=-mgx/L,~~~T_y=-mgy/L. \n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If $\\Omega$ is the rotation of the earth, and if $\\theta$ is the polar angle, $\\pi$-latitude," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\ddot{x}&=&-gx/L+2\\dot{y}\\Omega_z,\\\\\n", + "\\ddot{y}&=&-gy/L-2\\dot{x}\\Omega_z.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here we have used the fact that the oscillations are sufficiently\n", + "small so we can ignore $v_z$. Using $\\Omega_0\\equiv\\sqrt{k/m}$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\ddot{x}-2\\Omega_z\\dot{y}+\\Omega_0^2x&=&0\\\\\n", + "\\ddot{y}+2\\Omega_z\\dot{x}+\\Omega_0^2y&=&0,\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "where $\\Omega_z=|\\boldsymbol{\\Omega}|\\cos\\theta$, with $\\theta$ being the\n", + "polar angle (zero at the north pole). The terms linear in time\n", + "derivatives are what make life difficult. This will be solved with a\n", + "trick. We will incorporate both differential equations into a single\n", + "complex equation where the first/second are the real/imaginary parts." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\eta\\equiv x+iy,\\\\\n", + "\\ddot{\\eta}+2i\\Omega_z\\dot{\\eta}+\\Omega_0^2\\eta&=&0. \n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, we guess at a form for the solutions, $\\eta(t)=e^{-i\\alpha t}$,\n", + "which turns the differential equation into" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "-\\alpha^2+2\\Omega_z\\alpha+\\Omega_0^2&=&0,\\\\\n", + "\\alpha&=&\\Omega_z\\pm \\sqrt{\\Omega_z^2+\\Omega_0^2},\\\\\n", + "&\\approx&\\Omega_z\\pm \\Omega_0.\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The solution with two arbitrary constants is then" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\eta&=&e^{-i\\Omega_zt}\\left[C_1e^{i\\Omega_0t}+C_2e^{-i\\Omega_0t}\\right].\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here, $C_1$ and $C_2$ are complex, so they actually represent four\n", + "arbitrary numbers. These four numbers should be fixed by the four\n", + "initial conditions, i.e. $x(t=0), \\dot{x}(t=0), y(t=0)$ and\n", + "$\\dot{y}(t=0)$. With some lengthy algebra, one can rewrite the\n", + "expression as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{eqnarray*}\n", + "\\label{eq:precmess} \\tag{5}\n", + "\\eta&=&e^{-i\\Omega_zt}\\left[A\\cos(\\Omega_0t+\\phi_A)+iB\\cos(\\Omega_0t+\\phi_B)\\right].\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here, the four coefficients are represented by the two real arbitrary\n", + "real amplitudes, $A$ and $B$, and two arbitrary phases, $\\phi_A$ and\n", + "$\\phi_B$. For an initial condition where $y=0$ at $t=0$, one can see\n", + "that $B=0$. This then gives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray*}\n", + "\\eta(t)&=&Ae^{-i\\Omega_zt}\\cos(\\Omega_0t+\\gamma)\\\\\n", + "\\nonumber\n", + "&=&A\\cos\\Omega_zt\\cos(\\Omega_0t+\\gamma)+iA\\sin\\Omega_zt\\cos(\\Omega_0t+\\gamma).\n", + "\\end{eqnarray*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Translating into $x$ and $y$," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{eqnarray}\n", + "x&=&A\\cos\\Omega_zt\\cos(\\Omega_0t+\\gamma),\\\\\n", + "\\nonumber\n", + "y&=&A\\sin\\Omega_zt\\cos(\\Omega_0t+\\gamma).\n", + "\\end{eqnarray}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Assuming the pendulum's frequency is much higher than Earth's\n", + "rotational frequency, $\\Omega_0>>\\Omega_z$, one can see that the plane\n", + "of the pendulum simply precesses with angular velocity\n", + "$\\Omega_z$. This means that in this limit the pendulum oscillates only\n", + "in the $x$-direction with frequency many times before the phase\n", + "$\\Omega_zt$ becomes noticeable. Eventually, when $\\Omega_zt=\\pi/2$,\n", + "the motion is along the $y$-direction. If you were at the north pole,\n", + "the motion would switch from the $x$-direction to the $y$ direction\n", + "every 6 hours. Away from the north pole, $\\Omega_z\\ne|\\boldsymbol{\\Omega}|$\n", + "and the precession frequency is less. At the equator it does not\n", + "precess at all. If one were to repeat for the solutions where $A=0$\n", + "and $B\\ne 0$, one would look at motions\n", + "that started in the $y$-direction, then precessed toward the $-x$\n", + "direction. Linear combinations of the two sets of solutions give\n", + "pendulum motions that resemble ellipses rather than simple\n", + "back-and-forth motion.\n", + "\n", + "## Euler's Theorem from a Linear Algebra Perspective\n", + "\n", + "**this material will be added soon**" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/content.md b/doc/src/LectureNotes/testbook/_build/html/_sources/content.md new file mode 100644 index 000000000..0f6aca77a --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/content.md @@ -0,0 +1,5 @@ +Content in Jupyter Book +======================= + +There are many ways to write content in Jupyter Book. This short section +covers a few tips for how to do so. diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/intro.md b/doc/src/LectureNotes/testbook/_build/html/_sources/intro.md new file mode 100644 index 000000000..f601a11cd --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/intro.md @@ -0,0 +1,180 @@ +# PHY321, Classical Mechanics I, Michigan State University, Spring 2021 + +Here you will find a general overview of the course, with learning outcomes, teaching schedule etc. + +## Teaching team, grading and other practicalities + +| Lectures | | | Location | +|---------|----|----|----| +| Monday 3:00-3:50pm| Wednesday 3:00-3:50pm | Friday 3:00-3:50pm | Room 1420 BPS | + + +| Instructor | Email | Office | Office phone/cellphone | +|--------------|------|-----|----| +| _Morten Hjorth-Jensen_ https://github.com/mhjensen | hjensen@msu.edu | Office: NSCL/FRIB 2131 | 5179087290/5172491375/+47-48257387 | + + + +| Office Hours| | +|----------|----------| +| Monday/Wednesday 4-5:00pm, Room 2131 NSCL/FRIB | or immediately after class | + +| Homework Grader | Email | +|--------------|------| +| _Julie Butler_ | butler@frib.msu.edu | + +| Office Hours Julie Butler | +|------------------| +| TBA | | + +| Learning Assistant | Email | +|--------------|------| +| _Jeremy Rebenstock_ | | + +| Office Hours TBA | | +|----------|----------| +| | | + + +| Additional Class | Location | +|---|----| +| Wednesday 5:00-6pm | Room 1400 BPS | + + + +### Grading and dates + +| Activity | Percentage of total score | +|------|-----| +|Homeworks, 9 in total and due Mondays the week after | 20% | +| First Midterm Project, due Wednesday March 11 | 25% | +| Second Midterm Project, due Friday April 17| 25% | +| Final Exam project, due May 1 | 30% | +| Extra Credit Assignment, hw10, (Due Friday April 24)| 10% | + +| Grading scale | | | | | | | +|-----|-----|-------|------|--------|--------|--------| +| 4.0(90%)| 3.5(80%)| 3.0(70%)| 2.5(60%)| 2.0(50%)| 1.5(40%)| 1.0(30%)| + +## Possible textbooks and lecture notes + +_Recommended textbook_: +- JRT: John R. Taylor, Classical Mechanics (Univ. Sci. Books 2005), https://www.uscibooks.com/taylor2.htm, see also https://github.com/mhjensen/Physics321/tree/master/doc/Literature +_Additional textbooks_: +- AMS: Anders Malthe-Sørenssen, Elementary Mechanics using Python (Springer 2015), https://www.springer.com/gp/book/9783319195957 and https://github.com/mhjensen/Physics321/tree/master/doc/Literature +- _Lecture notes_: Posted lecture notes are in the doc/pub folder here or at https://mhjensen.github.io/Physics321/doc/web/course.html for easier viewing. They are not meant to be a replacement for textbook. These notes are updated on a weekly basis and a _git pull_ should thus always give you the latest update. + +## Teaching schedule with links to material (This will be updated asap) +Weekly mails (Wednesdays or Thursdays) with updates, plans for lectures etc will sent to everybody. We use also Piazza as a discussion forum. Please use this sign-up link piazza.com/msu/spring2020/phy321. The class link is piazza.com/msu/spring2020/phy321/home +### Week 2, January 6-10, 2020 +- Monday: Introduction to the course and start discussion of vectors, space, time and motion, JRT chapter 1.2 and lecture notes (https://mhjensen.github.io/Physics321/doc/pub/Introduction/html/Introduction.html) +- Wednesday: More on time,space, vectors and motion, JRT 1.2 and 1.3, AMS chapters 2 and 4 and lecture notes (https://mhjensen.github.io/Physics321/doc/pub/Introduction/html/Introduction.html), first homework available +- Friday: Forces and Newton's laws of motion. JRT chapter 1.4 and lecture notes (https://mhjensen.github.io/Physics321/doc/pub/Introduction/html/Introduction.html). Introduction to Git and GitHub and getting started with numerical exercises. Installing software (anaconda) and first homework due January 17. For solving exercise 7 in the first homework, AMS chapters 2 and 4 are very useful +- Solution to homeworks are in https://d2l.msu.edu/ +### Week 3, January 13-17, 2020 +- Monday: Motion and forces, Newton's laws, examples +- Wednesday: Motion and forces, Newton's laws, examples +- Friday: Motion and forces, Newton's laws, examples,2nd homework, due January 24 +- Solution to homeworks are in https://d2l.msu.edu/ +- Good reads are Taylor chapters 1.4, 1.5, 1.6, 2.1-2.4 and AMS chapters 4.2 and 5 +### Week 4, January 20-24, 2020 +- Monday: MLK day, no lectures +- Wednesday: Work and energy conservation +- Friday: Example of conservation laws and single-particle motion, 3rd homework, due January 31 +- Good reads are Taylor chapters 4.1-.4.3 and AMS chapters 10-12. +### Week 5, January 27-31, 2020 +- Monday: More on Conservation laws, momentum conservation +- Wednesday: Examples of applications of conservation laws, angular momentum conservation +- Friday: Conservation aws and further examples, 4th homework, due February 10 +- Good reads are Taylor chapter 4 and AMS chapters 10-14. +### Week 6, February 3-7, 2020 +- Monday: Conservation laws and discussion of 4th homework (exercises 6 and 7). Introducing the Velocity Verlet algorithm and the Earth Sun problem +- Wednesday: Examples of application of conservations laws (see chapter 4 of Taylor). +- Friday: Begin discussion of oscillations, and 5th homework, due February 17, paper and pencil can be handed in Friday the 21st at latest. +- Good reads are Taylor chapter 4 and AMS chapters 10-14 for the conservation laws and the first sections of chapter 5 of Taylor on oscillations. +### Week 7, February 10-14, 2020 +- Monday: Oscillations, mathematical detials, the sliding block and energy conservation +- Wednesday: Oscillations, damped motion and more mathematical details +- Friday: Oscillations, resonances and more on damped motion, 6th homework, due February 24 +- Good reads are chapter 5 of Taylor on oscillations. +### Week 8, February 17-21, 2020 +- Monday: Oscillations, driven oscillations and resonances +- Wednesday: Oscillation examples and numerical integration +- Friday: Fourier series and end of oscillation chapter _First midterm project, available Friday Feb 21 and due March 11, 2020_ +- Good reads are sections 5.5-5.8 of Taylor on oscillations. +### Week 9, February 24-28, 2020 +- Monday: Fourier series and oscillations +- Wednesday: Discussiom of first midterm and wrap up of oscillations part +- Friday: No lecture! +- Good reads are chapter 8 of Taylor and Lecture notes +### Week 10, March 2-6, 2020, Spring break +- Monday: No lectures, spring break +- Wednesday: No lectures, spring break +- Friday: No lectures, spring break +### Week 11, March 9-13, 2020 +- Monday: Gravity and central force problems, center of mass coordinates. Lecture notes and Taylor chapter 8. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch9.pdf +- Wednesday: Discussion of first midterm. First midterm due Friday 13 +- Friday: Gravity and central force problems, centrifugal barriers. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch13.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_wk9trq9k +### Week 12, March 16-20, 2020 +- Monday: Gravity and central force problems, elliptical orbits and Kepler's laws, 7th homework, due March 23. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch16.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_t1pocrww +- Wednesday: Gravity and central force problems, elliptical orbits and two-body scattering examples. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch18.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_i9hczn21 +- Friday: Elliptical orbits, examples and two-body scattering problems. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch20.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_w9xc8az7 +### Week 13, March 23-27, 2020 +- Monday: Central force problems, summary and discussion of two-body scattering problems. 8th homework, due March 30. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch23.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_t2l86862 +- Wednesday: Two-body scattering. Taylor chapter 14 covers parts of the material. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch25.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_d70czgce +- Friday: Two-body scattering (Taylor chapter 14). PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch27.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_e1cs5784 +### Week 14, March 30-April 3, 2020 +- Monday: Wrapping up two-body scattering and begin non-inertial frames. 9th homework, due April 6. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesMarch30.pdf and video of lecture https://mediaspace.msu.edu/media/t/0_tlsccwai +- Wednesday: Non-inertial frames, accelerating frames (Taylor sections 9.1-9.2). PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril1.pdf and video of lecture https://mediaspace.msu.edu/media/t/0_utc9il9y +- Friday: Rotating non-inertial frames and Coriolis force (Taylor sections 9.3-9.6). PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril3.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_2v439nza +### Week 15, April 6-10, 2020 +- Monday: Rotating non-inertial frames, Coriolis force and Foucalt's pendulum (Taylor sections 9.7-9.9). Second midterm available, due Fryday April 17. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril6.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_utivxb87 +- Wednesday: Variational calculus and the Euler-Lagrange equations, chapter 6 of Taylor and lecture notes. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril8.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_rz8vr2ht +- Friday: Euler-Lagrange equations and Lagrangian formalism. Taylor chapter 6 and lecture notes. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril10.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_j5ugthfg +### Week 16, April 13-17, 2020 +- Monday: Langrangian formalism, discussion of examples. Taylor chapters 6 and 7. 10th homework and extra assignments, due April 24. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril13.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_hxxec3uc +- Wednesday: Lagrangian formalism, constraints and Lagrangian multipliers and examples. These topics are covered by Taylor's sections 7.1,7.2, 7.3, 7.4. Sections 7.5-7.7 contain several nice examples while section 7.8 goes through conservation laws. The lecture notes cover many of these topics as well. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril15.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_2v2se359 +- Friday: Lagrangian Formalism, conservation laws and examples, from the classical pendulum to Foucault's pendulum. Taylor chapter 7 and lecture notes. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril17.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_ftgzt035 +### Week 17, April 20-24, 2020 +- Monday: Lagrangian formalism, conservation laws. Examples. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril20.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_b81t0tta +- Wednesday: Lagrangian formalim, examples such as the linear chain and double pendulum. PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril22.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_sp7p28vk +- Friday: Summary and discussions of final exam project. _Final exam project project, due May 1_ PDF file for notes https://github.com/mhjensen/Physics321/blob/master/doc/HandWrittenNotes/NotesApril24.pdf and video of lecture https://mediaspace.msu.edu/media/t/1_azwo1s2r +### Week 18, April 27- May 1, 2020, Finals week +- Final Exam: Due to the Corona virus the final exam will be a project similar to the two midterm projects. Deadline May 1. We will have questions sessions Monday 27 and Wednesday 29 at 2.30pm to 4pm. Other sessions can always be arranged. Just send Morten an email or a text. + + +## Learning outcomes + +After the course you should: + +- be able to analyze forces that act on objects, apply Newton’s laws to determine the equations of motion, and solve these analytically and numerically, +- Know about inertial frames and their relation to accelerating and rotating frames (non-inertial frames) +- Know about forces, work, energy, angular momentum, linear momentum and conservation laws +- Know about various types of motions, falling objects, objects moving in various fields +- Know how to analyze energy diagrams and defining effective potential +- Have knowledge about small oscillations, Harmonic oscillator potential and equations of motion +- Have knowledge about transformation of variables that allow for analytical solutions, example two-body problems +- Have knowledge about central forces and two-body problems, center-of-mass and relative coordinates as reference frame +- Have knowledge about two-body scattering problems, classical scattering cross section +- Have knowledge about Variational calculus and Lagrangian formalism +- Know how to derive the equations of motion from the Lagrangian formalism with and without constraints (Lagrangian multipliers) + +To solve many of these problems, we have through different projects and weekly exercises studied many systems numerically, from falling objects with and without friction/air resistance, small oscillations (harmonic oscillator), gravitational problems and other central force problems, rotations and the classical pendulum. To solve these systems, we have applied different algorithms for solving differential equations. These are +- Euler-Cromer and Velocity-Verlet as energy conserving algorithms (time-independent forces) +- Runge-Kutta family of algorithms for time-dependent forces +We have also, in connection with for example the work-energy theorem studied methods for evaluating integrals. These are +- Numerical integration using the Trapezoidal, midpoint and Simpson's rule. + +You should also have acquired skills in structuring a numerical project, as well as having developed a critical understanding of the pros and cons of the methods and an understanding of their limits and what can go wrong. Computing means solving scientific problems using computers. It covers numerical as well as symbolic computing. Computing is also about developing an understanding of the scientific process by enhancing algorithmic thinking when solving problems. Computing competence has +always been a central part of the science and engineering education. +In particular, some of the competences that are important in the development of your own understanding of +computations, we would like to emphasize +- derivation, verification, and implementation of algorithms +- understanding what can go wrong with algorithms +- overview of important, known algorithms for solving mechanics problems (To a extent large differential equations and integration) +- understanding how algorithms are used to solve mathematical problems +- Making science (your results) reproducible +- algorithmic thinking for gaining deeper insights about scientific problems + + + diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/CONDUCT.md b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/CONDUCT.md new file mode 100644 index 000000000..3f5562bc9 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/CONDUCT.md @@ -0,0 +1,44 @@ + +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant, version 1.4](http://contributor-covenant.org/version/1/4). diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/CONTRIBUTING.md b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/CONTRIBUTING.md new file mode 100644 index 000000000..aad4a6adc --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/CONTRIBUTING.md @@ -0,0 +1,56 @@ +# Contributing + +Contributions are welcome, and they are greatly appreciated! Every little bit +helps, and credit will always be given. You can contribute in the ways listed below. + +## Report Bugs + +Report bugs using GitHub issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your local setup that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. + +## Fix Bugs + +Look through the GitHub issues for bugs. Anything tagged with "bug" and "help +wanted" is open to whoever wants to implement it. + +## Implement Features + +Look through the GitHub issues for features. Anything tagged with "enhancement" +and "help wanted" is open to whoever wants to implement it. + +## Write Documentation + +LectureNotes could always use more documentation, whether as part of the +official LectureNotes docs, in docstrings, or even on the web in blog posts, +articles, and such. + +## Submit Feedback + +The best way to send feedback is to file an issue on GitHub. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that contributions + are welcome :) + +## Get Started + +Ready to contribute? Here's how to set up `LectureNotes` for local development. + +1. Fork the repo on GitHub. +2. Clone your fork locally. +3. Install your local copy into a virtualenv, e.g., using `conda`. +4. Create a branch for local development and make changes locally. +5. Commit your changes and push your branch to GitHub. +6. Submit a pull request through the GitHub website. + +## Code of Conduct + +Please note that the LectureNotes project is released with a [Contributor Code of Conduct](CONDUCT.md). By contributing to this project you agree to abide by its terms. diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/README.md b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/README.md new file mode 100644 index 000000000..63c66f58f --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/README.md @@ -0,0 +1,35 @@ +# LectureNotes + +Test book + +## Usage + +### Building the book + +If you'd like to develop on and build the LectureNotes book, you should: + +- Clone this repository and run +- Run `pip install -r requirements.txt` (it is recommended you do this within a virtual environment) +- (Recommended) Remove the existing `LectureNotes/_build/` directory +- Run `jupyter-book build LectureNotes/` + +A fully-rendered HTML version of the book will be built in `LectureNotes/_build/html/`. + +### Hosting the book + +The html version of the book is hosted on the `gh-pages` branch of this repo. A GitHub actions workflow has been created that automatically builds and pushes the book to this branch on a push or pull request to main. + +If you wish to disable this automation, you may remove the GitHub actions workflow and build the book manually by: + +- Navigating to your local build; and running, +- `ghp-import -n -p -f LectureNotes/_build/html` + +This will automatically push your build to the `gh-pages` branch. More information on this hosting process can be found [here](https://jupyterbook.org/publish/gh-pages.html#manually-host-your-book-with-github-pages). + +## Contributors + +We welcome and recognize all contributions. You can see a list of current contributors in the [contributors tab](https://github.com/mhjensen/lecturenotes/graphs/contributors). + +## Credits + +This project is created using the excellent open source [Jupyter Book project](https://jupyterbook.org/) and the [executablebooks/cookiecutter-jupyter-book template](https://github.com/executablebooks/cookiecutter-jupyter-book). diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/content.md b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/content.md new file mode 100644 index 000000000..0f6aca77a --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/content.md @@ -0,0 +1,5 @@ +Content in Jupyter Book +======================= + +There are many ways to write content in Jupyter Book. This short section +covers a few tips for how to do so. diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/intro.md b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/intro.md new file mode 100644 index 000000000..19ce5e005 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/intro.md @@ -0,0 +1,7 @@ +Welcome to your Jupyter Book +============================ + +This is a small sample book to give you a feel for how book content is +structured. + +Check out the content pages bundled with this sample book to get started. diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/markdown.md b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/markdown.md new file mode 100644 index 000000000..785cabc7b --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/markdown.md @@ -0,0 +1,125 @@ +# Markdown Files + +Whether you write your book's content in Jupyter Notebooks (`.ipynb`) or +in regular markdown files (`.md`), you'll write in the same flavor of markdown +called **MyST Markdown**. + +## What is MyST? + +MyST stands for "Markedly Structured Text". It +is a slight variation on a flavor of markdown called "CommonMark" markdown, +with small syntax extensions to allow you to write **roles** and **directives** +in the Sphinx ecosystem. + +## What are roles and directives? + +Roles and directives are two of the most powerful tools in Jupyter Book. They +are kind of like functions, but written in a markup language. They both +serve a similar purpose, but **roles are written in one line**, whereas +**directives span many lines**. They both accept different kinds of inputs, +and what they do with those inputs depends on the specific role or directive +that is being called. + +### Using a directive + +At its simplest, you can insert a directive into your book's content like so: + +```` +```{mydirectivename} +My directive content +``` +```` + +This will only work if a directive with name `mydirectivename` already exists +(which it doesn't). There are many pre-defined directives associated with +Jupyter Book. For example, to insert a note box into your content, you can +use the following directive: + +```` +```{note} +Here is a note +``` +```` + +This results in: + +```{note} +Here is a note +``` + +In your built book. + +For more information on writing directives, see the +[MyST documentation](https://myst-parser.readthedocs.io/). + + +### Using a role + +Roles are very similar to directives, but they are less-complex and written +entirely on one line. You can insert a role into your book's content with +this pattern: + +``` +Some content {rolename}`and here is my role's content!` +``` + +Again, roles will only work if `rolename` is a valid role's name. For example, +the `doc` role can be used to refer to another page in your book. You can +refer directly to another page by its relative path. For example, the +role syntax `` {doc}`intro` `` will result in: {doc}`intro`. + +For more information on writing roles, see the +[MyST documentation](https://myst-parser.readthedocs.io/). + + +### Adding a citation + +You can also cite references that are stored in a `bibtex` file. For example, +the following syntax: `` {cite}`holdgraf_evidence_2014` `` will render like +this: {cite}`holdgraf_evidence_2014`. + +Moreover, you can insert a bibliography into your page with this syntax. +The `{bibliography}` directive must be used for all the `{cite}` roles to +render properly. +For example, if the references for your book are stored in `references.bib`, +then the bibliography is inserted with: + +```` +```{bibliography} references.bib +``` +```` + +Resulting in a rendered bibliography that looks like: + +```{bibliography} references.bib +``` + + +### Executing code in your markdown files + +If you'd like to include computational content inside these markdown files, +you can use MyST Markdown to define cells that will be executed when your +book is built. Jupyter Book uses *jupytext* to do this. + +First, add Jupytext metadata to the file. For example, to add Jupytext metadata +to this markdown page, run this command: + +``` +jupyter-book myst init markdown.md +``` + +Once a markdown file has Jupytext metadata in it, you can add the following +directive to run the code at build time: + +```` +```{code-cell} +print("Here is some code to execute") +``` +```` + +When your book is built, the contents of any `{code-cell}` blocks will be +executed with your default Jupyter kernel, and their outputs will be displayed +in-line with the rest of your content. + +For more information about executing computational content with Jupyter Book, +see [The MyST-NB documentation](https://myst-nb.readthedocs.io/). diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/notebooks.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/notebooks.ipynb new file mode 100644 index 000000000..4b8552023 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/lecturenotes/lecturenotes/notebooks.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Content with notebooks\n", + "\n", + "You can also create content with Jupyter Notebooks. This means that you can include\n", + "code blocks and their outputs in your book.\n", + "\n", + "## Markdown + notebooks\n", + "\n", + "As it is markdown, you can embed images, HTML, etc into your posts!\n", + "\n", + "![](https://myst-parser.readthedocs.io/en/latest/_static/logo.png)\n", + "\n", + "You an also $add_{math}$ and\n", + "\n", + "$$\n", + "math^{blocks}\n", + "$$\n", + "\n", + "or\n", + "\n", + "$$\n", + "\\begin{aligned}\n", + "\\mbox{mean} la_{tex} \\\\ \\\\\n", + "math blocks\n", + "\\end{aligned}\n", + "$$\n", + "\n", + "But make sure you \\$Escape \\$your \\$dollar signs \\$you want to keep!\n", + "\n", + "## MyST markdown\n", + "\n", + "MyST markdown works in Jupyter Notebooks as well. For more information about MyST markdown, check\n", + "out [the MyST guide in Jupyter Book](https://jupyterbook.org/content/myst.html),\n", + "or see [the MyST markdown documentation](https://myst-parser.readthedocs.io/en/latest/).\n", + "\n", + "## Code blocks and outputs\n", + "\n", + "Jupyter Book will also embed your code blocks and output in your book.\n", + "For example, here's some sample Matplotlib code:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import rcParams, cycler\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "plt.ion()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Fixing random state for reproducibility\n", + "np.random.seed(19680801)\n", + "\n", + "N = 10\n", + "data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]\n", + "data = np.array(data).T\n", + "cmap = plt.cm.coolwarm\n", + "rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n", + "\n", + "\n", + "from matplotlib.lines import Line2D\n", + "custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n", + " Line2D([0], [0], color=cmap(.5), lw=4),\n", + " Line2D([0], [0], color=cmap(1.), lw=4)]\n", + "\n", + "fig, ax = plt.subplots(figsize=(10, 5))\n", + "lines = ax.plot(data)\n", + "ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is a lot more that you can do with outputs (such as including interactive outputs)\n", + "with your book. For more information about this, see [the Jupyter Book documentation](https://jupyterbook.org)." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/markdown.md b/doc/src/LectureNotes/testbook/_build/html/_sources/markdown.md new file mode 100644 index 000000000..c186497d2 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/markdown.md @@ -0,0 +1,125 @@ +# Markdown Files + +Whether you write your book's content in Jupyter Notebooks (`.ipynb`) or +in regular markdown files (`.md`), you'll write in the same flavor of markdown +called **MyST Markdown**. + +## What is MyST? + +MyST stands for "Markedly Structured Text". It +is a slight variation on a flavor of markdown called "CommonMark" markdown, +with small syntax extensions to allow you to write **roles** and **directives** +in the Sphinx ecosystem. + +## What are roles and directives? + +Roles and directives are two of the most powerful tools in Jupyter Book. They +are kind of like functions, but written in a markup language. They both +serve a similar purpose, but **roles are written in one line**, whereas +**directives span many lines**. They both accept different kinds of inputs, +and what they do with those inputs depends on the specific role or directive +that is being called. + +### Using a directive + +At its simplest, you can insert a directive into your book's content like so: + +```` +```{mydirectivename} +My directive content +``` +```` + +This will only work if a directive with name `mydirectivename` already exists +(which it doesn't). There are many pre-defined directives associated with +Jupyter Book. For example, to insert a note box into your content, you can +use the following directive: + +```` +```{note} +Here is a note +``` +```` + +This results in: + +```{note} +Here is a note +``` + +In your built book. + +For more information on writing directives, see the +[MyST documentation](https://myst-parser.readthedocs.io/). + + +### Using a role + +Roles are very similar to directives, but they are less-complex and written +entirely on one line. You can insert a role into your book's content with +this pattern: + +``` +Some content {rolename}`and here is my role's content!` +``` + +Again, roles will only work if `rolename` is a valid role's name. For example, +the `doc` role can be used to refer to another page in your book. You can +refer directly to another page by its relative path. For example, the +role syntax `` {doc}`intro` `` will result in: {doc}`intro`. + +For more information on writing roles, see the +[MyST documentation](https://myst-parser.readthedocs.io/). + + +### Adding a citation + +You can also cite references that are stored in a `bibtex` file. For example, +the following syntax: `` {cite}`holdgraf_evidence_2014` `` will render like +this: {cite}`holdgraf_evidence_2014`. + +Moreoever, you can insert a bibliography into your page with this syntax: +The `{bibliography}` directive must be used for all the `{cite}` roles to +render properly. +For example, if the references for your book are stored in `references.bib`, +then the bibliography is inserted with: + +```` +```{bibliography} references.bib +``` +```` + +Resulting in a rendered bibliography that looks like: + +```{bibliography} references.bib +``` + + +### Executing code in your markdown files + +If you'd like to include computational content inside these markdown files, +you can use MyST Markdown to define cells that will be executed when your +book is built. Jupyter Book uses *jupytext* to do this. + +First, add Jupytext metadata to the file. For example, to add Jupytext metadata +to this markdown page, run this command: + +``` +jupyter-book myst init markdown.md +``` + +Once a markdown file has Jupytext metadata in it, you can add the following +directive to run the code at build time: + +```` +```{code-cell} +print("Here is some code to execute") +``` +```` + +When your book is built, the contents of any `{code-cell}` blocks will be +executed with your default Jupyter kernel, and their outputs will be displayed +in-line with the rest of your content. + +For more information about executing computational content with Jupyter Book, +see [The MyST-NB documentation](https://myst-nb.readthedocs.io/). diff --git a/doc/src/LectureNotes/testbook/_build/html/_sources/notebooks.ipynb b/doc/src/LectureNotes/testbook/_build/html/_sources/notebooks.ipynb new file mode 100644 index 000000000..b33ee373d --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_sources/notebooks.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Content with notebooks\n", + "\n", + "You can also create content with Jupyter Notebooks. This means that you can include\n", + "code blocks and their outputs in your book.\n", + "\n", + "## Markdown + notebooks\n", + "\n", + "As it is markdown, you can embed images, HTML, etc into your posts!\n", + "\n", + "![](https://myst-parser.readthedocs.io/en/latest/_static/logo.png)\n", + "\n", + "You an also $add_{math}$ and\n", + "\n", + "$$\n", + "math^{blocks}\n", + "$$\n", + "\n", + "or\n", + "\n", + "$$\n", + "\\begin{aligned}\n", + "\\mbox{mean} la_{tex} \\\\ \\\\\n", + "math blocks\n", + "\\end{aligned}\n", + "$$\n", + "\n", + "But make sure you \\$Escape \\$your \\$dollar signs \\$you want to keep!\n", + "\n", + "## MyST markdown\n", + "\n", + "MyST markdown works in Jupyter Notebooks as well. For more information about MyST markdown, check\n", + "out [the MyST guide in Jupyter Book](https://jupyterbook.org/content/myst.html),\n", + "or see [the MyST markdown documentation](https://myst-parser.readthedocs.io/en/latest/).\n", + "\n", + "## Code blocks and outputs\n", + "\n", + "Jupyter Book will also embed your code blocks and output in your book.\n", + "For example, here's some sample Matplotlib code:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import rcParams, cycler\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "plt.ion()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Fixing random state for reproducibility\n", + "np.random.seed(19680801)\n", + "\n", + "N = 10\n", + "data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]\n", + "data = np.array(data).T\n", + "cmap = plt.cm.coolwarm\n", + "rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n", + "\n", + "\n", + "from matplotlib.lines import Line2D\n", + "custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n", + " Line2D([0], [0], color=cmap(.5), lw=4),\n", + " Line2D([0], [0], color=cmap(1.), lw=4)]\n", + "\n", + "fig, ax = plt.subplots(figsize=(10, 5))\n", + "lines = ax.plot(data)\n", + "ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is a lot more that you can do with outputs (such as including interactive outputs)\n", + "with your book. For more information about this, see [the Jupyter Book documentation](https://jupyterbook.org)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/doc/src/LectureNotes/testbook/_build/html/_static/basic.css b/doc/src/LectureNotes/testbook/_build/html/_static/basic.css new file mode 100644 index 000000000..0c5300c2c --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_static/basic.css @@ -0,0 +1,855 @@ +/* + * basic.css + * ~~~~~~~~~ + * + * Sphinx stylesheet -- basic theme. + * + * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. + * :license: BSD, see LICENSE for details. + * + */ + +/* -- main layout ----------------------------------------------------------- */ + +div.clearer { + clear: both; +} + +div.section::after { + display: block; + content: ''; + clear: left; +} + +/* -- relbar ---------------------------------------------------------------- */ + +div.related { + width: 100%; + font-size: 90%; +} + +div.related h3 { + display: none; +} + +div.related ul { + margin: 0; + padding: 0 0 0 10px; + list-style: none; +} + +div.related li { + display: inline; +} + +div.related li.right { + float: right; + margin-right: 5px; +} + +/* -- sidebar --------------------------------------------------------------- */ + +div.sphinxsidebarwrapper { + padding: 10px 5px 0 10px; +} + +div.sphinxsidebar { + float: left; + width: 270px; + margin-left: -100%; + font-size: 90%; + word-wrap: break-word; + overflow-wrap : break-word; +} + +div.sphinxsidebar ul { + list-style: none; +} + +div.sphinxsidebar ul ul, +div.sphinxsidebar ul.want-points { + margin-left: 20px; + list-style: square; +} + +div.sphinxsidebar ul ul { + margin-top: 0; + margin-bottom: 0; +} + +div.sphinxsidebar form { + margin-top: 10px; +} + +div.sphinxsidebar input { + border: 1px solid #98dbcc; + font-family: sans-serif; + font-size: 1em; +} + +div.sphinxsidebar #searchbox form.search { + overflow: hidden; +} + +div.sphinxsidebar #searchbox input[type="text"] { + float: left; + width: 80%; + padding: 0.25em; + box-sizing: border-box; +} + +div.sphinxsidebar #searchbox input[type="submit"] { + float: left; + width: 20%; + border-left: none; + padding: 0.25em; + box-sizing: border-box; +} + + +img { + border: 0; + max-width: 100%; +} + +/* -- search page ----------------------------------------------------------- */ + +ul.search { + margin: 10px 0 0 20px; + padding: 0; +} + +ul.search li { + padding: 5px 0 5px 20px; + background-image: url(file.png); + background-repeat: no-repeat; + background-position: 0 7px; +} + +ul.search li a { + font-weight: bold; +} + +ul.search li div.context { + color: #888; + margin: 2px 0 0 30px; + text-align: left; +} + +ul.keywordmatches li.goodmatch a { + font-weight: bold; +} + +/* -- index page ------------------------------------------------------------ */ + +table.contentstable { + width: 90%; + margin-left: auto; + margin-right: auto; +} + +table.contentstable p.biglink { + line-height: 150%; +} + +a.biglink { + font-size: 1.3em; +} + +span.linkdescr { + font-style: italic; + padding-top: 5px; + font-size: 90%; +} + +/* -- general index --------------------------------------------------------- */ + +table.indextable { + width: 100%; +} + +table.indextable td { + text-align: left; + vertical-align: top; +} + +table.indextable ul { + margin-top: 0; + margin-bottom: 0; + list-style-type: none; +} + +table.indextable > tbody > tr > td > ul { + padding-left: 0em; +} + +table.indextable tr.pcap { + height: 10px; +} + +table.indextable tr.cap { + margin-top: 10px; + background-color: #f2f2f2; +} + +img.toggler { + margin-right: 3px; + margin-top: 3px; + cursor: pointer; +} + +div.modindex-jumpbox { + border-top: 1px solid #ddd; + border-bottom: 1px solid #ddd; + margin: 1em 0 1em 0; + padding: 0.4em; +} + +div.genindex-jumpbox { + border-top: 1px solid #ddd; + border-bottom: 1px solid #ddd; + margin: 1em 0 1em 0; + padding: 0.4em; +} + +/* -- domain module index --------------------------------------------------- */ + +table.modindextable td { + padding: 2px; + border-collapse: collapse; +} + +/* -- general body styles --------------------------------------------------- */ + +div.body { + min-width: 450px; + max-width: 800px; +} + +div.body p, div.body dd, div.body li, div.body blockquote { + -moz-hyphens: auto; + -ms-hyphens: auto; + -webkit-hyphens: auto; + hyphens: auto; +} + +a.headerlink { + visibility: hidden; +} + +a.brackets:before, +span.brackets > a:before{ + content: "["; +} + +a.brackets:after, +span.brackets > a:after { + content: "]"; +} + +h1:hover > a.headerlink, +h2:hover > a.headerlink, +h3:hover > a.headerlink, +h4:hover > a.headerlink, +h5:hover > a.headerlink, +h6:hover > a.headerlink, +dt:hover > a.headerlink, +caption:hover > a.headerlink, +p.caption:hover > a.headerlink, +div.code-block-caption:hover > a.headerlink { + visibility: visible; +} + +div.body p.caption { + text-align: inherit; +} + +div.body td { + text-align: left; +} + +.first { + margin-top: 0 !important; +} + +p.rubric { + margin-top: 30px; + font-weight: bold; +} + +img.align-left, .figure.align-left, object.align-left { + clear: left; + float: left; + margin-right: 1em; +} + +img.align-right, .figure.align-right, object.align-right { + clear: right; + float: right; + margin-left: 1em; +} + +img.align-center, .figure.align-center, object.align-center { + display: block; + margin-left: auto; + margin-right: auto; +} + +img.align-default, .figure.align-default { + display: block; + margin-left: auto; + margin-right: auto; +} + +.align-left { + text-align: left; +} + +.align-center { + text-align: center; +} + +.align-default { + text-align: center; +} + +.align-right { + text-align: right; +} + +/* -- sidebars -------------------------------------------------------------- */ + +div.sidebar { + margin: 0 0 0.5em 1em; + border: 1px solid #ddb; + padding: 7px; + background-color: #ffe; + width: 40%; + float: right; + clear: right; + overflow-x: auto; +} + +p.sidebar-title { + font-weight: bold; +} + +div.admonition, div.topic, blockquote { + clear: left; +} + +/* -- topics ---------------------------------------------------------------- */ + +div.topic { + border: 1px solid #ccc; + padding: 7px; + margin: 10px 0 10px 0; +} + +p.topic-title { + font-size: 1.1em; + font-weight: bold; + margin-top: 10px; +} + +/* -- admonitions ----------------------------------------------------------- */ + +div.admonition { + margin-top: 10px; + margin-bottom: 10px; + padding: 7px; +} + +div.admonition dt { + font-weight: bold; +} + +p.admonition-title { + margin: 0px 10px 5px 0px; + font-weight: bold; +} + +div.body p.centered { + text-align: center; + margin-top: 25px; +} + +/* -- content of sidebars/topics/admonitions -------------------------------- */ + +div.sidebar > :last-child, +div.topic > :last-child, +div.admonition > :last-child { + margin-bottom: 0; +} + +div.sidebar::after, +div.topic::after, +div.admonition::after, +blockquote::after { + display: block; + content: ''; + clear: both; +} + +/* -- tables ---------------------------------------------------------------- */ + +table.docutils { + margin-top: 10px; + margin-bottom: 10px; + border: 0; + border-collapse: collapse; +} + +table.align-center { + margin-left: auto; + margin-right: auto; +} + +table.align-default { + margin-left: auto; + margin-right: auto; +} + +table caption span.caption-number { + font-style: italic; +} + +table caption span.caption-text { +} + +table.docutils td, table.docutils th { + padding: 1px 8px 1px 5px; + border-top: 0; + border-left: 0; + border-right: 0; + border-bottom: 1px solid #aaa; +} + +table.footnote td, table.footnote th { + border: 0 !important; +} + +th { + text-align: left; + padding-right: 5px; +} + +table.citation { + border-left: solid 1px gray; + margin-left: 1px; +} + +table.citation td { + border-bottom: none; +} + +th > :first-child, +td > :first-child { + margin-top: 0px; +} + +th > :last-child, +td > :last-child { + margin-bottom: 0px; +} + +/* -- figures --------------------------------------------------------------- */ + +div.figure { + margin: 0.5em; + padding: 0.5em; +} + +div.figure p.caption { + padding: 0.3em; +} + +div.figure p.caption span.caption-number { + font-style: italic; +} + +div.figure p.caption span.caption-text { +} + +/* -- field list styles ----------------------------------------------------- */ + +table.field-list td, table.field-list th { + border: 0 !important; +} + +.field-list ul { + margin: 0; + padding-left: 1em; +} + +.field-list p { + margin: 0; +} + +.field-name { + -moz-hyphens: manual; + -ms-hyphens: manual; + -webkit-hyphens: manual; + hyphens: manual; +} + +/* -- hlist styles ---------------------------------------------------------- */ + +table.hlist { + margin: 1em 0; +} + +table.hlist td { + vertical-align: top; +} + + +/* -- other body styles ----------------------------------------------------- */ + +ol.arabic { + list-style: decimal; +} + +ol.loweralpha { + list-style: lower-alpha; +} + +ol.upperalpha { + list-style: upper-alpha; +} + +ol.lowerroman { + list-style: lower-roman; +} + +ol.upperroman { + list-style: upper-roman; +} + +:not(li) > ol > li:first-child > :first-child, +:not(li) > ul > li:first-child > :first-child { + margin-top: 0px; +} + +:not(li) > ol > li:last-child > :last-child, +:not(li) > ul > li:last-child > :last-child { + margin-bottom: 0px; +} + +ol.simple ol p, +ol.simple ul p, +ul.simple ol p, +ul.simple ul p { + margin-top: 0; +} + +ol.simple > li:not(:first-child) > p, +ul.simple > li:not(:first-child) > p { + margin-top: 0; +} + +ol.simple p, +ul.simple p { + margin-bottom: 0; +} + +dl.footnote > dt, +dl.citation > dt { + float: left; + margin-right: 0.5em; +} + +dl.footnote > dd, +dl.citation > dd { + margin-bottom: 0em; +} + +dl.footnote > dd:after, +dl.citation > dd:after { + content: ""; + clear: both; +} + +dl.field-list { + display: grid; + grid-template-columns: fit-content(30%) auto; +} + +dl.field-list > dt { + font-weight: bold; + word-break: break-word; + padding-left: 0.5em; + padding-right: 5px; +} + +dl.field-list > dt:after { + content: ":"; +} + +dl.field-list > dd { + padding-left: 0.5em; + margin-top: 0em; + margin-left: 0em; + margin-bottom: 0em; +} + +dl { + margin-bottom: 15px; +} + +dd > :first-child { + margin-top: 0px; +} + +dd ul, dd table { + margin-bottom: 10px; +} + +dd { + margin-top: 3px; + margin-bottom: 10px; + margin-left: 30px; +} + +dl > dd:last-child, +dl > dd:last-child > :last-child { + margin-bottom: 0; +} + +dt:target, span.highlighted { + background-color: #fbe54e; +} + +rect.highlighted { + fill: #fbe54e; +} + +dl.glossary dt { + font-weight: bold; + font-size: 1.1em; +} + +.optional { + font-size: 1.3em; +} + +.sig-paren { + font-size: larger; +} + +.versionmodified { + font-style: italic; +} + +.system-message { + background-color: #fda; + padding: 5px; + border: 3px solid red; +} + +.footnote:target { + background-color: #ffa; +} + +.line-block { + display: block; + margin-top: 1em; + margin-bottom: 1em; +} + +.line-block .line-block { + margin-top: 0; + margin-bottom: 0; + margin-left: 1.5em; +} + +.guilabel, .menuselection { + font-family: sans-serif; +} + +.accelerator { + text-decoration: underline; +} + +.classifier { + font-style: oblique; +} + +.classifier:before { + font-style: normal; + margin: 0.5em; + content: ":"; +} + +abbr, acronym { + border-bottom: dotted 1px; + cursor: help; +} + +/* -- code displays --------------------------------------------------------- */ + +pre { + overflow: auto; + overflow-y: hidden; /* fixes display issues on Chrome browsers */ +} + +pre, div[class|="highlight"] { + clear: both; +} + +span.pre { + -moz-hyphens: none; + -ms-hyphens: none; + -webkit-hyphens: none; + hyphens: none; +} + +div[class^="highlight-"] { + margin: 1em 0; +} + +td.linenos pre { + border: 0; + background-color: transparent; + color: #aaa; +} + +table.highlighttable { + display: block; +} + +table.highlighttable tbody { + display: block; +} + +table.highlighttable tr { + display: flex; +} + +table.highlighttable td { + margin: 0; + padding: 0; +} + +table.highlighttable td.linenos { + padding-right: 0.5em; +} + +table.highlighttable td.code { + flex: 1; + overflow: hidden; +} + +.highlight .hll { + display: block; +} + +div.highlight pre, +table.highlighttable pre { + margin: 0; +} + +div.code-block-caption + div { + margin-top: 0; +} + +div.code-block-caption { + margin-top: 1em; + padding: 2px 5px; + font-size: small; +} + +div.code-block-caption code { + background-color: transparent; +} + +table.highlighttable td.linenos, +div.doctest > div.highlight span.gp { /* gp: Generic.Prompt */ + user-select: none; +} + +div.code-block-caption span.caption-number { + padding: 0.1em 0.3em; + font-style: italic; +} + +div.code-block-caption span.caption-text { +} + +div.literal-block-wrapper { + margin: 1em 0; +} + +code.descname { + background-color: transparent; + font-weight: bold; + font-size: 1.2em; +} + +code.descclassname { + background-color: transparent; +} + +code.xref, a code { + background-color: transparent; + font-weight: bold; +} + +h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { + background-color: transparent; +} + +.viewcode-link { + float: right; +} + +.viewcode-back { + float: right; + font-family: sans-serif; +} + +div.viewcode-block:target { + margin: -1px -10px; + padding: 0 10px; +} + +/* -- math display ---------------------------------------------------------- */ + +img.math { + vertical-align: middle; +} + +div.body div.math p { + text-align: center; +} + +span.eqno { + float: right; +} + +span.eqno a.headerlink { + position: absolute; + z-index: 1; +} + +div.math:hover a.headerlink { + visibility: visible; +} + +/* -- printout stylesheet --------------------------------------------------- */ + +@media print { + div.document, + div.documentwrapper, + div.bodywrapper { + margin: 0 !important; + width: 100%; + } + + div.sphinxsidebar, + div.related, + div.footer, + #top-link { + display: none; + } +} \ No newline at end of file diff --git a/doc/src/LectureNotes/testbook/_build/html/_static/clipboard.min.js b/doc/src/LectureNotes/testbook/_build/html/_static/clipboard.min.js new file mode 100644 index 000000000..02c549e35 --- /dev/null +++ b/doc/src/LectureNotes/testbook/_build/html/_static/clipboard.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.4 + * https://zenorocha.github.io/clipboard.js + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return function(n){var o={};function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function o(t,e){for(var n=0;n