├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── PLAN.org ├── PUBLISHING.md ├── README.md ├── WORKFLOW.md ├── WRITING.org ├── bin ├── github-mathjax.crx ├── mechanics └── mit-scheme ├── ch1 ├── ex1-11.scm ├── ex1-12.scm ├── ex1-13.scm ├── ex1-14.scm ├── ex1-15.scm ├── ex1-16.scm ├── ex1-21.scm ├── ex1-22.scm ├── ex1-23.scm ├── ex1-24.scm ├── ex1-25.scm ├── ex1-26.scm ├── ex1-27.scm ├── ex1-28.scm ├── ex1-29.scm ├── ex1-3.scm ├── ex1-30.scm ├── ex1-31.scm ├── ex1-32.scm ├── ex1-33.scm ├── ex1-34.scm ├── ex1-35.scm ├── ex1-36.scm ├── ex1-37.scm ├── ex1-38.scm ├── ex1-39.scm ├── ex1-40.scm ├── ex1-41.scm ├── ex1-42.scm ├── ex1-43.scm ├── ex1-44.scm ├── ex1-5.scm ├── ex1-6.scm ├── ex1-8.scm ├── exdisplay.scm ├── min-action-paths.scm ├── orbital-motion.scm ├── scratch.scm ├── sec1-4.scm └── utils.scm ├── ch9 ├── ex9-1.scm └── ex9-2.scm ├── images └── Lagrangian_Mechanics │ ├── 2020-05-29_10-12-19_AJBpDgU.gif │ ├── 2020-05-29_10-14-10_screenshot.png │ ├── 2020-06-08_11-47-37_imgs%2Fapp%2Fsritchie%2FVqfQv6wgb-.png.png │ ├── 2020-06-10_10-31-24_screenshot.png │ ├── 2020-06-10_10-36-53_screenshot.png │ ├── 2020-06-10_12-03-11_screenshot.png │ ├── 2020-06-10_14-24-14_screenshot.png │ ├── 2020-06-10_15-10-46_ex1_6_nooffset.gif │ ├── 2020-06-10_15-10-53_ex1_6_02offset.gif │ ├── 2020-06-10_15-11-10_ex1_6_05offset.gif │ ├── 2020-06-10_15-11-27_ex1_6_neg5offset.gif │ ├── 2020-06-23_14-48-36_screenshot.png │ ├── 2020-06-25_11-03-55_screenshot.png │ ├── 2020-06-29_05-39-01_Art_P146.jpg │ ├── 2020-06-29_05-39-33_Art_P147.jpg │ └── 2020-06-29_05-40-00_Art_P166.jpg ├── md ├── 1_lagrangian_mechanics.md ├── 2_rigid_bodies.md ├── 3_hamiltonian_mechanics.md ├── 4_phase_space_structure.md ├── 5_canonical_transformations.md ├── 6_canonical_evolution.md ├── 7_canonical_perturbation_theory.md ├── 8_our_notation.md ├── 9_org-mode_demo.md └── preface.md ├── sicm.md └── sicm.org /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: sritchie 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.com 3 | *.bci 4 | 5 | ltximg 6 | 7 | *.tex 8 | sicm.pdf 9 | 10 | # For output from auctex. 11 | auto -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /PLAN.org: -------------------------------------------------------------------------------- 1 | # -*- eval: (org-num-mode 1); -*- 2 | #+startup: indent num 3 | #+date: 2020-05-26 4 | 5 | * The Plan for Better Publishing 6 | 7 | How do we make this setup much better? 8 | 9 | ** ox-gfm 10 | 11 | We need to publish a fork, at least, of the ox-gfm backend, and make it easy to 12 | use. It would be nice if folks could use this whole bundle of code outside of 13 | spacemacs, but we also want to provide a nice spacemacs layer. 14 | 15 | Here's a nice guide on how to publish to melpa, once I get this working: https://spin.atomicobject.com/2016/05/27/write-emacs-package/ 16 | -------------------------------------------------------------------------------- /PUBLISHING.md: -------------------------------------------------------------------------------- 1 | # Modifications for Org-Mode 2 | 3 | The repository has exercises in an org-mode file at the repo root. That file 4 | gets published regularly as a PDF and a Markdown file that lives in the git 5 | root. 6 | 7 | Any of the exercises that require code are tangled out of that org-file. 8 | 9 | ## Modifying Emacs for Publishing 10 | 11 | I had to do some seriously annoying legwork to get the org-mode publish working. 12 | I'm going to log it here, and tidy it up if anyone's interested in making this 13 | happen. 14 | 15 | We want to use `xscheme` for org-mode code evaluation, but `cmuscheme` for the 16 | actual interaction with the repl. This is annoying to make happen. 17 | 18 | - Go into `xscheme` and erase these two lines: 19 | 20 | ```emacs-lisp 21 | (xscheme-evaluation-commands scheme-mode-map) 22 | (xscheme-interrupt-commands scheme-mode-map) 23 | ``` 24 | 25 | That will prevent xscheme from stomping all the repl and scheme keyboard 26 | bindings. 27 | 28 | Next, go into `cmuscheme` and change `run-scheme` to `run-cmu-scheme`. This will 29 | give us a NEW name 30 | 31 | These changes will not follow you around as you move machines, and don't live in 32 | your init file. So don't forget that you'll have to do this again if you 33 | upgrade! 34 | 35 | ### Custom Publishing 36 | 37 | To get the custom publishing going, you'll need to install my [custom org mode 38 | evaluator](https://github.com/sritchie/spacemacs.d/blob/sritchie/google/ob-mit-scheme.el). 39 | Place that in your `~/.spacemacs.d`, or `~/.emacs.d` folder if you're not using 40 | spacemacs. 41 | 42 | Go get it downloaded at [this 43 | location](https://github.com/sritchie/spacemacs.d/blob/sritchie/google/ob-mit-scheme.el), 44 | then add these two lines to your emacs init: 45 | 46 | ```emacs-lisp 47 | (load "~/.spacemacs.d/ob-mit-scheme.el") 48 | (require 'ob-mit-scheme) 49 | ``` 50 | 51 | This, in combination with the modifications to xscheme and cmuscheme above, will let you: 52 | 53 | - run `mechanics` to start up an inferior scheme process with cmuscheme 54 | - let `xscheme` handle actually executing code for org-mode in its own buffer. 55 | 56 | I tried making it work with Geiser, but it was a total nightmare. Geiser tries 57 | to `read` the results of the execution block, which apparently blows up 58 | `mit-scheme`. 59 | 60 | ### Init Modifications 61 | 62 | You'll have to modify your `mechanics` function to call the new `cmuscheme` 63 | start function. The new functions in your init block will look like this: 64 | 65 | ```emacs-lisp 66 | (require 'cmuscheme) 67 | 68 | (defun mechanics-local () 69 | (interactive) 70 | (run-cmu-scheme "mechanics")) 71 | 72 | ;; And finally, the goods for SICM. 73 | (defun mechanics () 74 | (interactive) 75 | (let ((default-directory (or (projectile-project-root) 76 | default-directory))) 77 | (call-interactively #'mechanics-local))) 78 | 79 | ;; Here's an older version that does NOT use my docker stuff. 80 | (defun mechanics-osx () 81 | (interactive) 82 | (run-cmu-scheme "mechanics-osx")) 83 | ``` 84 | 85 | ## Nice Equation Rendering 86 | 87 | You can render LaTeX inline in org mode! 88 | 89 | To get nice equation rendering on OS X, make sure you have `dvisvgm` installed, 90 | and add this to your init file: 91 | 92 | ```emacs-lisp 93 | (setq org-latex-create-formula-image-program 'dvisvgm) 94 | ``` 95 | 96 | If you're on a Mac, you'll notice that the previews don't actually display. To get that 97 | 98 | ## How to Export 99 | 100 | To generate the markdown file, go to `sicm.org` and run `C-c C-e g g` to 101 | regenerate the markdown file. 102 | 103 | [ox-gfm](https://github.com/larstvei/ox-gfm) is what makes it possible to export 104 | in github-flavored markdown. For this to work in Spacemacs, you'll need to make 105 | sure that your `org` setup looks like this: 106 | 107 | ```emacs-lisp 108 | (org :variables 109 | org-enable-github-support t 110 | org-enable-hugo-support t 111 | org-enable-org-journal-support t 112 | org-want-todo-bindings t) 113 | ``` 114 | 115 | Run `C-c C-e l p` to generate PDF. 116 | 117 | ## Tangling Code 118 | 119 | Once I get some exercises transferred over, I'll update this page with 120 | instructions on how to tangle the exercise code out of the org-mode file. 121 | 122 | ## Seeing Equations 123 | 124 | I've forked this [nice Mathjax plugin for 125 | Github](https://chrome.google.com/webstore/detail/mathjax-plugin-for-github/ioemnmodlmafdkllaclgeombjnmnbima?hl=en) 126 | to make it work with a more modern MathJax. I've also modified the config to 127 | work with the LaTeX syntax that org-mode emits. 128 | 129 | The plugin lives 130 | [here](https://chrome.google.com/webstore/detail/mathjax-3-plugin-for-gith/peoghobgdhejhcmgoppjpjcidngdfkod). 131 | Install it in Chrome and you should see nicely LaTeX for all math on the 132 | markdown files in this repository. 133 | 134 | ## Creating Github Markdown with LaTeX 135 | 136 | The Github-flavored markdown that `ox-gfm` emits turns all LaTeX fragments into 137 | the standard `\( equation surrounded by parens \)` or `\[ square braces \]`. 138 | Github renders markdown by treating those as escapes for the parens or braces... 139 | and because the backslash is missing, Mathjax won't render equations. 140 | 141 | We can add some customization to org-mode to get it to add an extra backslash 142 | escape, which will force Github's renderer to show the equations properly. 143 | 144 | Here's what I had to do to get this working: 145 | 146 | ```emacs-lisp 147 | (defmacro ->> (&rest body) 148 | (let ((result (pop body))) 149 | (dolist (form body result) 150 | (setq result (append form (list result)))))) 151 | 152 | (defun replace-in-string (what with in) 153 | (replace-regexp-in-string (regexp-quote what) with in nil 'literal)) 154 | 155 | (defun escape-gfm-latex-characters (text) 156 | (->> text 157 | (replace-in-string "\\(" "\\\\(") 158 | (replace-in-string "\\)" "\\\\)") 159 | (replace-in-string "\\[" "\\\\[") 160 | (replace-in-string "\\]" "\\\\]") 161 | (replace-in-string "_" "\\_"))) 162 | 163 | (defun org-gfm-latex-filter (text backend info) 164 | "Properly escape code so it gets rendered." 165 | (when (org-export-derived-backend-p backend 'gfm) 166 | (escape-gfm-latex-characters text))) 167 | 168 | (require 'ox) 169 | 170 | ;; These are required to get proper escaping in github-flavored markdown for 171 | ;; latex snippets and embedded equations and environments. 172 | (add-to-list 'org-export-filter-latex-fragment-functions 'gfm-latex-filter) 173 | (add-to-list 'org-export-filter-latex-environment-functions 'gfm-latex-filter) 174 | 175 | ;; Override the built-in stuff in org-md-export-block, since I don't want to 176 | ;; declare my own backend and 177 | (defun org-md-export-block (export-block contents info) 178 | "Transcode a EXPORT-BLOCK element from Org to Markdown. 179 | CONTENTS is nil. INFO is a plist holding contextual information." 180 | (let ((prop-type (org-element-property :type export-block))) 181 | (message contents) 182 | (cond ((string= prop-type "LATEX") 183 | (escape-gfm-latex-characters 184 | (org-remove-indentation (org-element-property :value export-block)))) 185 | 186 | ;; this is the default markdown behavior. 187 | ((member prop-type '("MARKDOWN" "MD")) 188 | (org-remove-indentation (org-element-property :value export-block))) 189 | 190 | ;; Also include the default for HTML export blocks. 191 | (t (org-export-with-backend 'html export-block contents info))))) 192 | ``` 193 | 194 | If you add that to your emacs initialization code, you'll find that `ox-gfm` 195 | Does the Right Thing when you try to export to Github-flavored markdown, and 196 | equations show up looking great. 197 | 198 | I also had to override the default markdown processing, so that it would emit latex blocks: 199 | 200 | 201 | 202 | ## Custom LaTeX Processing 203 | 204 | I modified `exdisplay.scm` to use proper LaTeX environment style, like 205 | `\begin{pmatrix}\end{pmatrix}` instead of `\matrix{}`. 206 | 207 | This led to a bug discovery! I've included the modified file in 208 | `ch1/exdisplay.scm`. This has the bugfix, and the upgraded `matrix` printing for 209 | up and down tuples. (Without this change, MathJax and XDVI will be able to 210 | handle rendering no problem, but LaTeX itself will choke.) 211 | 212 | ## Embedding Gifs 213 | 214 | ### Giphy 215 | 216 | This should be super easy. Upload, then drop in the image. Make sure to use 217 | `.gif`, not `.gifv`. 218 | 219 | ### Dropbox 220 | 221 | This does NOT work now, since Dropbox seems to grab the gif and rewrite it. But 222 | here's what I've learned. If you do this on Dropbox, you need to: 223 | 224 | - Get the link! 225 | - add `?dl=1` to the end of the URL 226 | 227 | Then the image will embed properly. You'll also have to add this to your emacs config: 228 | 229 | ```emacs-lisp 230 | ;; This adds support for embedding dropbox images 231 | (add-to-list 'org-html-inline-image-rules 232 | `("https" . ,(format "\\.%s\\'" 233 | (regexp-opt 234 | '("gif?dl=1") 235 | t)))) 236 | ``` 237 | 238 | ## Debugging 239 | 240 | If you use `org-journal`, you may have to modify `org-journal-is-journal` to be 241 | this: 242 | 243 | ```emacs-lisp 244 | (defun org-journal-is-journal () 245 | "Determine if file is a journal file." 246 | (when (buffer-file-name) 247 | (string-match (org-journal-dir-and-file-format->pattern) 248 | (buffer-file-name)))) 249 | ``` 250 | 251 | You'll know if you see that error. So annoying! 252 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Structure and Interpretation of Classical Mechanics 2 | 3 | Welcome to my solution and notes repository for Sussman and Wisdom's [The 4 | Structure and Interpretation of Classical Mechanics](https://amzn.to/2LUx62M). 5 | You can get a copy of the book on [Amazon](https://amzn.to/2LUx62M), or follow 6 | along using this beautiful [HTML version](https://tgvaughan.github.io/sicm/). 7 | 8 |

9 | SICM Cover 10 |

11 | 12 | 13 | I'm working through the exercises for each chapter using [MIT 14 | Scheme](https://www.gnu.org/software/mit-scheme/), and the `scmutils` library 15 | (also called `mechanics` by the authors and me) that Sussman and Wisdom 16 | developed for the textbook. 17 | 18 | Each chapter gets its own folder, named `ch1`, `ch2`, etc. Inside each folder 19 | I've included a file for each exercise that required code or benefited from 20 | exploration in Scheme. 21 | 22 | I've also worked hard to make sure that it's easy for *you* to run any of this 23 | code, and recreate my work in any of the exercises. I've provided a working copy 24 | of the `mechanics` library in this repository in `bin/mechanics`. There's a 25 | small amount of work you'll have to do to make the script run, but I've covered 26 | that below under ["Running the Code"](#running-the-code). 27 | 28 | ## The Road to Reality 29 | 30 | If you like this sort of thing, you might also consider subscribing to ["The 31 | Road to Reality"](https://roadtoreality.substack.com/), a newsletter where I 32 | post primers and lessons on interesting topics in math, physics, machine 33 | learning or artificial intelligence, with a heavy emphasis on locking down the 34 | intuition behind the ideas over mere symbol shuffling. 35 | 36 | Check it out here: https://roadtoreality.substack.com 37 | 38 | ## Other SICM Resources 39 | 40 | - The [course website](https://groups.csail.mit.edu/mac/users/gjs/6946/) for 41 | MIT's 6.946, ["Classical Mechanics: A Computational 42 | Approach"](https://groups.csail.mit.edu/mac/users/gjs/6946/). This is a 43 | graduate level course in classical mechanics that uses this textbook. The 44 | course page has excellent materials, links to errata, all the goods. 45 | - [Errata for the 2nd edition of 46 | SICM](http://groups.csail.mit.edu/mac/users/gjs/6946/errata.pdf). I've found 47 | some more, which I'll add to this page as I go. 48 | - [The SICM Textbook on Amazon](https://amzn.to/2LUx62M) 49 | - [Beautiful HTML version of the SICM 50 | Textbook](https://tgvaughan.github.io/sicm/). You have to read this! 51 | - [MIT OpenCourseware page for the Fall 2008 version of the 52 | course](https://ocw.mit.edu/courses/earth-atmospheric-and-planetary-sciences/12-620j-classical-mechanics-a-computational-approach-fall-2008/index.htm). 53 | This uses the first edition of the textbook. I haven't gone through this page 54 | in any detail. 55 | - [Documentation for `scmutils`, aka 56 | `mechanics`](https://github.com/Tipoca/scmutils/blob/master/manual/refman.txt) 57 | - [SICMUtils](https://github.com/littleredcomputer/sicmutils) a Clojure 58 | implementation of the `scmutils` / `mechanics` library. Clojure is brilliant. 59 | I may include some examples of code using this library as I go. 60 | - My Dockerhub pages for the 61 | [`mit-scheme`](https://hub.docker.com/r/sritchie/mit-scheme) 62 | and [`mechanics`](https://hub.docker.com/r/sritchie/mechanics) 63 | Docker images. 64 | 65 | ## Running Mechanics 66 | 67 | You can interact with any of the utilities or solutions I've written using the 68 | `bin/mechanics` program in this repository. `bin/mechanics` holds a full, 69 | working installation of `mechanics` and MIT Scheme, packaged up inside of a 70 | Docker container. To make this work, you'll need, at minimum, a working 71 | installation of [Docker](https://www.docker.com/). 72 | 73 | If you want to see graphics (which of course you do!), you'll need an X11 window 74 | system installed. For LaTeX rendering, you'll need the `xdvi` program, which 75 | comes with installations of [LaTeX](https://www.latex-project.org/get/). 76 | 77 | ### OS X Prerequisites 78 | 79 | If you're on a Mac, install [Docker Desktop for 80 | Mac](https://hub.docker.com/editions/community/docker-ce-desktop-mac/) by 81 | clicking the "Get Docker" button on the right side of that page. 82 | 83 | [XQuartz](https://www.xquartz.org/) will cover the X11 requirement. Download the 84 | file [here](https://www.xquartz.org/) and install it in the usual way. 85 | 86 | Finally, install [MacTeX](https://tug.org/mactex/mactex-download.html) and 87 | afterward make sure that typing `xdvi` at the terminal makes something happen. 88 | 89 | Once you have XQuartz and MacTeX installed, you'll need to configure it to let 90 | `bin/mechanics` make graphics on your computer from inside the Docker container 91 | where it runs. To set this up, 92 | 93 | - launch XQuartz from `/Applications/Utilities/Xquartz`, 94 | - go into the Preferences menu and navigate to the Security tab 95 | - make sure that both "Authenticate Connections" and "Allow connections from 96 | network clients** is checked 97 | 98 | ### Linux Prerequisites 99 | 100 | [This page](https://docs.docker.com/engine/install/ubuntu/) has a nice guide on 101 | how to get Docker installed on Linux. I think the X11 requirement might just 102 | work? If you try this, please let me know, or send a PR updating this README. 103 | 104 | The [LaTeX Project](https://www.latex-project.org/get/) main page describes how 105 | to get LaTeX on Linux. They recommend installing the [TeX 106 | Live](https://www.tug.org/texlive/) distribution. 107 | 108 | ### Starting a REPL 109 | 110 | Once you have Docker installed and running, clone this repository onto your machine, 111 | navigate into the folder and run `bin/mechanics`: 112 | 113 | ``` 114 | git clone https://github.com/sritchie/sicm.git && cd sicm 115 | bin/mechanics 116 | ``` 117 | 118 | The first time you run this it should take a while, as you'll have to download 119 | all of the Docker image requirements. Eventually you'll see an MIT Scheme REPL 120 | with the whole `mechanics` library loaded: 121 | 122 | ``` 123 | 127.0.0.1 being added to access control list 124 | MIT/GNU Scheme running under GNU/Linux 125 | Type `^C' (control-C) followed by `H' to obtain information about interrupts. 126 | 127 | Copyright (C) 2019 Massachusetts Institute of Technology 128 | This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 129 | 130 | Image saved on Friday August 30, 2019 at 11:20:36 PM 131 | Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || SOS 1.8 || XML 1.0 || Edwin 3.117 || X11 1.3 || X11-Screen 1.0 || ScmUtils Mechanics.Summer 2019 132 | 133 | 1 ]=> 134 | ``` 135 | 136 | Go ahead and try evaluating some Lisp, using functions from the `mechanics` library: 137 | 138 | ```scheme 139 | 1 ]=> (square (up 'x 'y 'z)) 140 | #| 141 | (+ (expt x 2) (expt y 2) (expt z 2)) 142 | |# 143 | ``` 144 | 145 | You're all set! 146 | 147 | ### Testing Graphics via X11 148 | 149 | If you set up XQuartz / X11, you should be able to get LaTeX expressions printing. 150 | 151 | To test this out, run the `bin/mechanics` script and try entering an expression 152 | like `(show-expression (+ 'alpha 't))` at the REPL. 153 | 154 | ``` 155 | $ bin/mechanics 156 | 127.0.0.1 being added to access control list 157 | MIT/GNU Scheme running under GNU/Linux 158 | Type `^C' (control-C) followed by `H' to obtain information about interrupts. 159 | 160 | Copyright (C) 2019 Massachusetts Institute of Technology 161 | This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 162 | 163 | Image saved on Friday August 30, 2019 at 11:20:36 PM 164 | Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || SOS 1.8 || XML 1.0 || Edwin 3.117 || X11 1.3 || X11-Screen 1.0 || ScmUtils Mechanics.Summer 2019 165 | 166 | 1 ]=> (show-expression (+ 'alpha 't)) 167 | (+ alpha t) 168 | ``` 169 | 170 | You should see a window pop up in XQuartz with a nicely rendered LaTeX 171 | expression: 172 | 173 | ![](https://user-images.githubusercontent.com/69635/82736715-05646500-9ce9-11ea-9227-4db5fee32eb6.png) 174 | 175 | 176 | The REPL will hang until you close the XQuartz window, so go ahead and do that 177 | now. 178 | 179 | ## Running the Exercises 180 | 181 | The exercises for each chapter live in their own folder, named `ch1`, `ch2`, 182 | etc. Inside each folder I've included a file for each exercise that required 183 | code or benefited from exploration in Scheme. 184 | 185 | You can run any code in these folders by starting the REPL `bin/mechanics` from 186 | the repository root folder, and calling, for example: 187 | 188 | ```scheme 189 | (load "ch1/ex1-29.scm") 190 | ``` 191 | 192 | This will execute all code in the file located at `ch1/ex1-29.scm`, including 193 | all side effects and graphics that the file generated. If you see LaTeX 194 | expressions pop up, you'll have to close each one to move to the next one. 195 | 196 | ## Emacs Integration 197 | 198 | If you want to interact more heavily with the code, add more exercises and work 199 | on it yourself, I suggest you switch to a proper text editor with nice support 200 | for Scheme. I use [Emacs](https://emacsformacosx.com/), specifically 201 | [Spacemacs](https://samritchie.io/moving-to-spacemacs-for-scala-and-python/), 202 | these days. (Here's my [Spacemacs 203 | configuration](https://github.com/sritchie/spacemacs.d/tree/sritchie/google), if 204 | that phrase means anything to you.) 205 | 206 | I won't go into a whole spiel about how to set up Emacs, but I will note a 207 | configuration options that I've found very helpful when working on these 208 | exercises. (If you have guides you like, let me know and I'll link them here.) 209 | 210 | ### Run Mechanics Inside Emacs 211 | 212 | Emacs has amazing built-in support for working with Scheme. I've added a 213 | `mechanics` function to my Emacs config: 214 | 215 | ```elisp 216 | (defun mechanics () 217 | (interactive) 218 | (run-scheme "mechanics")) 219 | ``` 220 | 221 | (This works because I've added the `sicm/bin` directory to my path. You'll need 222 | to do that too, or give this command the full path to the `bin/mechanics` 223 | program.) 224 | 225 | When I'm in a file in the project, I can type `M-x mechanics`, and Emacs will 226 | start up a REPL running the `mechanics` code, with X11 support and everything. 227 | Then, when I'm working on a file, `C-c C-z` will switch to the repl. 228 | 229 | MAKE SURE you run this from the root of the project!! Go to `README.md` or 230 | something and run it there. All of the `load` statements in all of the code 231 | assume your main directory is the project root, so you'll run into problems if 232 | you don't do this. 233 | 234 | ### Mechanics and Projectile 235 | 236 | I actually use a slightly better version of the function above. If you use the 237 | incredible [Projectile](https://docs.projectile.mx/en/latest/) library for Emacs 238 | project navigation (and why wouldn't you??) you can make `mechanics` start 239 | Scheme from the project root every time. 240 | 241 | Here's the better version: 242 | 243 | ```elisp 244 | (defun mechanics-local () 245 | (interactive) 246 | (run-scheme "mechanics")) 247 | 248 | (defun mechanics () 249 | (interactive) 250 | (let ((default-directory (or (projectile-project-root) 251 | default-directory))) 252 | (call-interactively #'mechanics-local))) 253 | ``` 254 | 255 | This will attempt to use Projectile to launch Scheme in the root of your 256 | project, and fall back to the current folder if you're not in a project when you 257 | run `M-x mechanics`. Total gold! 258 | 259 | ## Other Emacs Customizations 260 | 261 | There are a few other customizations that I've found helpful working with 262 | MIT-Scheme and mechanics. I'll detail them here. 263 | 264 | ### Prettify Symbols / Lambdas 265 | 266 | This block of configuration code that, in Scheme, changes "lambda" appearances 267 | into nice, pretty greek symbols. This is called 268 | [prettify-symbols-mode](https://emacsredux.com/blog/2014/08/25/a-peek-at-emacs-24-dot-4-prettify-symbols-mode/), 269 | and looks great. 270 | 271 | ```elisp 272 | ;; This enables nice greek-letter lambdas whenever you type "lambda" 273 | ;; anywhere in a Scheme file. 274 | (global-prettify-symbols-mode 1) 275 | 276 | ;; Some bonus code to get this working in other language modes: 277 | (defun enable-pretty-lambdas () 278 | "Make them beautiful!" 279 | (setq prettify-symbols-alist '(("lambda" . 955)))) 280 | 281 | ;; I'm using Racket for a different project, so I wanted the good there too. 282 | (add-hook 'racket-mode-hook 'enable-pretty-lambdas) 283 | (add-hook 'racket-repl-mode-hook 'enable-pretty-lambdas) 284 | ``` 285 | 286 | ### Smartparens 287 | 288 | I use [smartparens](https://github.com/Fuco1/smartparens) to make sure that my 289 | parentheses never get out of balance. This is absolutely essential when working 290 | with Lisp. 291 | 292 | I'm used to the 293 | [Paredit](http://danmidwood.com/content/2014/11/21/animated-paredit.html) 294 | keybindings from years back, so I run this setting to make sure that all of the 295 | chords burned into my fingers don't have to change: 296 | 297 | ```elisp 298 | (sp-use-paredit-bindings) 299 | ``` 300 | 301 | To learn how to use these bindings, and what this library can do for you, check 302 | out Dan Midwood's amazing [Animated Guide to 303 | Paredit](http://danmidwood.com/content/2014/11/21/animated-paredit.html). 304 | 305 | Here's a [guide comparing Paredit and 306 | Smartparens](https://github.com/Fuco1/smartparens/wiki/Paredit-and-smartparens), 307 | so you don't get caught out by the differences. 308 | 309 | 310 | ## Native SCMUtils Installation on OS X 311 | 312 | This method of installation is a little more involved, but if you decide that 313 | you want to skip the Docker route and install `mechanics` and MIT Scheme 314 | natively on OS X, these are the steps. 315 | 316 | The instructions are 317 | [here](http://groups.csail.mit.edu/mac/users/gjs/6946/installation.html), but 318 | let's get through them more carefully. 319 | 320 | - Install MIT Scheme: https://www.gnu.org/software/mit-scheme/ 321 | - Rename the ``MIT-Scheme` application in the Applications folder to 322 | `MIT-Scheme`, so we don't have to worry about escaping spaces in the terminal. 323 | - Create a `~/bin` folder and get it on your `$PATH`. 324 | 325 | Run the following command to make the `mit-scheme` binary available: 326 | 327 | ```bash 328 | ln -s /Applications/MIT-Scheme.app/Contents/Resources/mit-scheme ~/bin/mit-scheme 329 | ``` 330 | 331 | Add this line to your `~/.bashrc` or `~/.bash_profile`, so that Scheme can see its libraries: 332 | 333 | ```bash 334 | export MITSCHEME_LIBRARY_PATH=/Applications/MIT-Scheme.app/Contents/Resources 335 | ``` 336 | 337 | Test that this all worked by running `mit-scheme` at a fresh terminal. You should see the following: 338 | 339 | ``` 340 | $ mit-scheme 341 | MIT/GNU Scheme running under OS X 342 | Type `^C' (control-C) followed by `H' to obtain information about interrupts. 343 | 344 | Copyright (C) 2019 Massachusetts Institute of Technology 345 | This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 346 | 347 | Image saved on Saturday August 10, 2019 at 6:28:48 PM 348 | Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 349 | 350 | 1 ]=> 351 | ``` 352 | 353 | Once that's working, it's time to install the SCMUtils / Mechanics library. 354 | 355 | ### Manual SCMUtils Installation 356 | 357 | The download link for the library lives at the [SICM course 358 | website](http://groups.csail.mit.edu/mac/users/gjs/6946/installation.html), at 359 | step 4. Here's the [direct download 360 | link](http://groups.csail.mit.edu/mac/users/gjs/6946/scmutils-20190830.tar.gz) 361 | if you prefer that. 362 | 363 | The next few steps come from the instructions at the course site: 364 | 365 | - Expand this gzipped tar archive by executing `tar xzf 366 | scmutils-20190830.tar.gz`. This will make a directory named 367 | `scmutils-20190830`. 368 | - Run `cd scmutils-20190830 && ./install.sh` to install `scmutils` into your 369 | local Scheme installation's resource directory. 370 | - Copy the starter script into `~/bin` by running `cp mechanics.sh ~/bin/mechanics`. 371 | 372 | Test it all out by running `mechanics`. You should see the following: 373 | 374 | ``` 375 | $ mechanics 376 | MIT/GNU Scheme running under OS X 377 | Type `^C' (control-C) followed by `H' to obtain information about interrupts. 378 | 379 | Copyright (C) 2019 Massachusetts Institute of Technology 380 | This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 381 | 382 | Image saved on Friday August 30, 2019 at 11:20:36 PM 383 | Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || SOS 1.8 || XML 1.0 || Edwin 3.117 || X11 1.3 || X11-Screen 1.0 || ScmUtils Mechanics.Summer 2019 384 | 385 | 1 ]=> 386 | ``` 387 | 388 | You're all set now, and can refer back to previous sections for instructions on 389 | how to install X11 and LaTeX, work with the exercises, or configure Emacs. 390 | 391 | ## Thank you! 392 | 393 | Thanks for following along! If you run into any issues, please file a ticket via 394 | [Github Issues](https://github.com/sritchie/sicm/issues). 395 | 396 | If you have any questions, or want to send me a note, you can do that at 397 | sritchie09 at gmail.com. 398 | 399 | ## License 400 | 401 | Copyright 2020, Sam Ritchie. 402 | 403 | Licensed under the [Apache License, Version 404 | 2.0](http://www.apache.org/licenses/LICENSE-2.0). 405 | -------------------------------------------------------------------------------- /WORKFLOW.md: -------------------------------------------------------------------------------- 1 | # My Workflow 2 | 3 | I'm writing this whole thing in org-mode. Here are some tips about how the project is structured. 4 | 5 | ## Header Args 6 | 7 | It takes a while to evaluate each code block, so I've added this to each section: 8 | 9 | ``` 10 | :PROPERTIES: 11 | :header-args: :eval no-export 12 | :END: 13 | ``` 14 | 15 | Then, on each exercise, to add to the default instead of wiping them out, I have a block like this: 16 | 17 | ``` 18 | **** Exercise 9.2: Computing Derivatives 19 | :PROPERTIES: 20 | :header-args+: :tangle ch9/ex9-2.scm 21 | :END: 22 | ``` 23 | 24 | ## Publishing Text with Exercises 25 | 26 | If you include `:comments org`, you'll get all of the surrounding context 27 | spliced in around the exercises. 28 | 29 | ## Noweb 30 | 31 | Say you want to show off some block of code, but splice it in later. 32 | -------------------------------------------------------------------------------- /WRITING.org: -------------------------------------------------------------------------------- 1 | # -*- eval: (org-num-mode 1); -*- 2 | #+startup: indent num 3 | #+date: 2020-05-26 4 | 5 | * How to Use This Setup 6 | 7 | Some notes on how to use this wild setup. 8 | 9 | ** Inserting LaTeX 10 | 11 | LaTeX support is pretty good! If you can manage to make an equation: 12 | 13 | \begin{equation} 14 | \Gamma[q] 15 | \end{equation} 16 | 17 | Then you can type `C-c '` inside the block, and you'll get to the SAME 18 | environment you would have found if you'd inserted an actual LaTeX block. 19 | 20 | That is a nicer way to work, honestly, because then inline previewing works too. 21 | 22 | ** Snippets 23 | 24 | I've cloned this [[https://github.com/madsdk/yasnippets-latex][repository]] into my ~~/.spacemacs.d~. To get these to work in 25 | LaTeX, I had to: 26 | 27 | - place the contents of the ~snippets~ folder that repo into 28 | ~snippets/text-mode~ 29 | - ~mkdir org-mode latex-mode~ 30 | - Copy the dotfiles from the text-mode folder into each subfolder: 31 | 32 | #+begin_src bash 33 | cp text-mode/.yas-parents latex-mode 34 | cp text-mode/.yas-make-groups latex-mode 35 | cp text-mode/.yas-ignore-filenames-as-triggers latex-mode 36 | mv text-mode/.yas-parents org-mode 37 | mv text-mode/.yas-make-groups org-mode 38 | mv text-mode/.yas-ignore-filenames-as-triggers org-mode 39 | #+end_src 40 | 41 | This makes the snippets accessible. Now that I have this, I can type ~eq~, then 42 | at the end type ~M-/~ for ~hippie-expand~ and get a nice equation block. So 43 | good! 44 | 45 | I've also added the auto-completion layer to get this going: 46 | 47 | #+begin_src emacs-lisp 48 | (auto-completion :variables 49 | auto-completion-return-key-behavior 'complete 50 | auto-completion-tab-key-behavior 'complete 51 | auto-completion-enable-snippets-in-popup t) 52 | #+end_src 53 | 54 | * Things I want 55 | 56 | ** References via RefTex 57 | 58 | I haven't done this yet, but it would be excellent to be able to set up 59 | references using Reftex. I've never done this properly. Nice opportunity here, 60 | when I already have a number of references to other guides that I want to share. 61 | 62 | ** Equations INSIDE org-mode 63 | 64 | cdlatex is the answer here. This is not so bad right now, I can always go into 65 | the latex context, but this might make it more natural. 66 | -------------------------------------------------------------------------------- /bin/github-mathjax.crx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/bin/github-mathjax.crx -------------------------------------------------------------------------------- /bin/mechanics: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if xhost >& /dev/null ; then 4 | # NOTE - On OS X, you have to have enabled network connections in XQuartz! 5 | xhost + 127.0.0.1 6 | fi 7 | 8 | workdir="$PWD" 9 | 10 | docker run \ 11 | --ipc host \ 12 | --interactive --tty --rm \ 13 | --workdir $workdir \ 14 | --volume $workdir:$workdir \ 15 | --volume $HOME:$HOME \ 16 | -e DISPLAY=host.docker.internal:0 \ 17 | sritchie/mechanics "$@" 18 | -------------------------------------------------------------------------------- /bin/mit-scheme: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if xhost >& /dev/null ; then 4 | # NOTE - On OS X, you have to have enabled network connections in XQuartz! 5 | xhost + 127.0.0.1 6 | fi 7 | 8 | workdir="$PWD" 9 | 10 | docker run \ 11 | --ipc host \ 12 | --interactive --tty --rm \ 13 | --workdir $workdir \ 14 | --volume $workdir:$workdir \ 15 | -e DISPLAY=host.docker.internal:0 \ 16 | sritchie/mit-scheme "$@" 17 | -------------------------------------------------------------------------------- /ch1/ex1-11.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.11: Kepler's third law 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-11.scm :comments org 4 | ;; :END: 5 | 6 | ;; This exercise asks us to derive [[https://en.wikipedia.org/wiki/Kepler%27s_laws_of_planetary_motion#Third_law_of_Kepler][Kepler's third law]] by considering a Langrangian 7 | ;; that describes two particles rotating in a circular orbit around their center of 8 | ;; mass at some rate. 9 | 10 | 11 | (load "ch1/utils.scm") 12 | 13 | 14 | ;; Here's the Lagrangian for "central force", in polar coordinates. This is 15 | ;; rotational kinetic energy, minus some arbitrary potential $V$ that depends on 16 | ;; the distance $r$ between the two particles. 17 | 18 | 19 | (define ((L-central-polar m V) local) 20 | (let ((q (coordinate local)) 21 | (qdot (velocity local))) 22 | (let ((r (ref q 0)) (phi (ref q 1)) 23 | (rdot (ref qdot 0)) (phidot (ref qdot 1))) 24 | (- (* 1/2 m 25 | (+ (square rdot) (square (* r phidot)))) 26 | (V r))))) 27 | 28 | 29 | ;; #+RESULTS: 30 | ;; : #| L-central-polar |# 31 | 32 | ;; This function defines gravitational potential energy: 33 | 34 | 35 | (define ((gravitational-energy G m1 m2) r) 36 | (- (/ (* G m1 m2) r))) 37 | 38 | 39 | ;; #+RESULTS: 40 | ;; : #| gravitational-energy |# 41 | 42 | ;; What is the mass $m$ in the Lagrangian above? It's the "[[https://en.wikipedia.org/wiki/Reduced_mass][reduced mass]]", totally 43 | ;; unjustified at this point in the book: 44 | 45 | 46 | (define (reduced-mass m1 m2) 47 | (/ (* m1 m2) 48 | (+ m1 m2))) 49 | 50 | 51 | ;; #+RESULTS: 52 | ;; : #| reduced-mass |# 53 | 54 | ;; If you want to see why the reduced mass has the form it does, check out [[https://en.wikipedia.org/wiki/Reduced_mass#Lagrangian_mechanics][this 55 | ;; derivation]]. 56 | 57 | ;; The Lagrangian is written in terms of some angle $\phi$ and $r$, the distance 58 | ;; between the two particles. $q$ defines a circular path: 59 | 60 | 61 | (define ((q r omega) t) 62 | (let ((phi (* omega t))) 63 | (up r phi))) 64 | 65 | 66 | ;; #+RESULTS: 67 | ;; : #| q |# 68 | 69 | ;; Write the Lagrange equations, given $r = a$ and $\omega = n$: 70 | 71 | 72 | (let ((eqfn (Lagrange-equations 73 | (L-central-polar (reduced-mass 'm1 'm2) 74 | (gravitational-energy 'G 'm1 'm2))))) 75 | (->tex-equation 76 | ((eqfn (q 'a 'n)) 't))) 77 | 78 | 79 | ;; #+RESULTS[e8565d29067487b8460bcb96e1a427d9eef22a0c]: 80 | ;; \begin{equation} 81 | ;; \begin{bmatrix} \displaystyle{ {{ - {a}^{3} \cdot m1 \cdot m2 \cdot {n}^{2} + G {m1}^{2} \cdot m2 + G \cdot m1 \cdot {m2}^{2}}\over {{a}^{2} \cdot m1 + {a}^{2} \cdot m2}}} \cr \cr \displaystyle{ 0}\end{bmatrix} 82 | ;; \end{equation} 83 | 84 | ;; These two entries are /residuals/, equal to zero. Stare at the top residual and 85 | ;; you might notice that you can can factor out: 86 | 87 | ;; - the reduced mass, and 88 | ;; - a factor of $1 \over a^2$ 89 | 90 | ;; Manually factor these out: 91 | 92 | 93 | (let ((eqfn (Lagrange-equations 94 | (L-central-polar (reduced-mass 'm1 'm2) 95 | (gravitational-energy 'G 'm1 'm2))))) 96 | (->tex-equation 97 | (* ((eqfn (q 'a 'n)) 't) 98 | (/ (square 'a) 99 | (reduced-mass 'm1 'm2))))) 100 | -------------------------------------------------------------------------------- /ch1/ex1-12.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.12: Lagrange's equations (code) 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-12.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | 9 | 10 | ;; This exercise asks us to write Scheme implementations for each of the three 11 | ;; systems described in [[https://tgvaughan.github.io/sicm/chapter001.html#Exe_1-9][Exercise 1.9]]. 12 | 13 | ;; Before we begin, here is a function that will display an up-tuple of: 14 | 15 | ;; - $\partial_1 L \circ \Gamma[q]$, the generalized force 16 | ;; - $\partial_2 L \circ \Gamma[q]$, the generalized momenta 17 | ;; - $D(\partial_2 L \circ \Gamma[q])$, the derivative of our momenta 18 | ;; - The Lagrange equations for the system. 19 | 20 | 21 | (define (lagrange-equation-steps L q) 22 | (let* ((p1 (compose ((partial 1) L) (Gamma q))) 23 | (p2 (compose ((partial 2) L) (Gamma q))) 24 | (dp2 (D p2))) 25 | (->tex-equation 26 | ((up p1 p2 dp2 (- dp2 p1)) 27 | 't)))) 28 | ;; Part A: Ideal Planar Pendulum 29 | 30 | ;; From the book: 31 | 32 | ;; #+begin_quote 33 | ;; An ideal planar pendulum consists of a bob of mass $m$ connected to a pivot by a 34 | ;; massless rod of length $l$ subject to uniform gravitational acceleration $g$. A 35 | ;; Lagrangian is $L(t, \theta, \dot{\theta}) = {1 \over 2} ml^2\dot{\theta}^2 + 36 | ;; mgl\cos \theta$. The formal parameters of $L$ are $t$, $\theta$, and 37 | ;; $\dot{\theta}$; $\theta$ measures the angle of the pendulum rod to a plumb line 38 | ;; and $\dot{\theta}$ is the angular velocity of the rod. 39 | ;; #+end_quote 40 | 41 | ;; Here is the Lagrangian described by the exercise: 42 | 43 | 44 | (define ((L-pendulum m g l) local) 45 | (let ((theta (coordinate local)) 46 | (theta_dot (velocity local))) 47 | (+ (* 1/2 m (square l) (square theta_dot)) 48 | (* m g l (cos theta))))) 49 | 50 | 51 | ;; #+RESULTS: 52 | ;; : #| L-pendulum |# 53 | 54 | ;; And the steps that lead us to Lagrange's equations: 55 | 56 | 57 | (lagrange-equation-steps 58 | (L-pendulum 'm 'g 'l) 59 | (literal-function 'theta)) 60 | 61 | 62 | ;; #+RESULTS[aaf5812bee20b3464cf996ad648f7000e663545b]: 63 | ;; \begin{equation} 64 | ;; \begin{pmatrix} \displaystyle{ \left( - 1 \right) g l m \sin\left( \theta\left( t \right) \right)} \cr \cr \displaystyle{ {l}^{2} m D\theta\left( t \right)} \cr \cr \displaystyle{ {l}^{2} m {D}^{2}\theta\left( t \right)} \cr \cr \displaystyle{ g l m \sin\left( \theta\left( t \right) \right) + {l}^{2} m {D}^{2}\theta\left( t \right)}\end{pmatrix} 65 | ;; \end{equation} 66 | 67 | ;; The final entry is the Lagrange equation, equal to $0$. Divide out the shared 68 | ;; factors of $m$ and $l$: 69 | 70 | 71 | (let* ((L (L-pendulum 'm 'g 'l)) 72 | (theta (literal-function 'theta)) 73 | (eqs ((Lagrange-equations L) theta))) 74 | (->tex-equation 75 | ((/ eqs (* 'm 'l)) 76 | 't))) 77 | ;; Part B: 2D Potential 78 | 79 | ;; The next problem is in rectangular coordinates. This means that we'll end up 80 | ;; with two Lagrange equations that have to be satisfied. 81 | 82 | ;; From the book: 83 | 84 | ;; #+begin_quote 85 | ;; A particle of mass $m$ moves in a two-dimensional potential $V(x, y) = {(x^2 + 86 | ;; y^2) \over 2} + x^2 y - {y^3 \over 3}$, where $x$ and $y$ are rectangular 87 | ;; coordinates of the particle. A Lagrangian is $L(t;x, y; v_x, v_y) = {1 \over 2} 88 | ;; m (v_x^2 + v_y^2) - V(x, y)$. 89 | ;; #+end_quote 90 | 91 | ;; I have no intuition for /what/ this potential is, by the way. One term, ${x^2 + 92 | ;; y^2} \over 2$, looks like half the square of the distance of the particle away 93 | ;; from 0, or ${1 \over 2} r^2$. What are the other terms? I've been so well 94 | ;; trained that I simply start calculating. 95 | 96 | ;; Define the Lagrangian to be the difference of the kinetic energy and some 97 | ;; potential $V$ that has access to the coordinates: 98 | 99 | 100 | (define (((L-2d-potential m) V) local) 101 | (- (* 1/2 m (square (velocity local))) 102 | (V (coordinate local)))) 103 | 104 | 105 | ;; #+RESULTS: 106 | ;; : #| L-2d-potential |# 107 | 108 | ;; Thanks to the tuple algebra of =scmutils=, This form of the Lagrangian is 109 | ;; general enough that it would work for any number of dimensions in rectangular 110 | ;; space, given some potential $V$. =square= takes a dot product, so we end up with 111 | ;; a kinetic energy term for every spatial dimension. 112 | 113 | ;; Note this for later, as this idea will become useful when the book reaches the 114 | ;; discussion of coordinate transformations. 115 | 116 | ;; Next define the potential from the problem description: 117 | 118 | 119 | (define (V q) 120 | (let ((x (ref q 0)) 121 | (y (ref q 1))) 122 | (- (+ (/ (+ (square x) 123 | (square y)) 124 | 2) 125 | (* (square x) y)) 126 | (/ (cube y) 3)))) 127 | 128 | 129 | ;; #+RESULTS: 130 | ;; : #| V |# 131 | 132 | ;; Our helpful function generates the Lagrange equations, along with each 133 | ;; intermediate step: 134 | 135 | 136 | (lagrange-equation-steps 137 | ((L-2d-potential 'm) V) 138 | (up (literal-function 'x) 139 | (literal-function 'y))) 140 | ;; Part C: Particle on a Sphere 141 | 142 | ;; This problem is slightly more clear. From the book: 143 | 144 | ;; #+begin_quote 145 | ;; A Lagrangian for a particle of mass $m$ constrained to move on a sphere of 146 | ;; radius $R$ is $L(t; \theta, \phi; \alpha, \beta) = {1 \over 2} m 147 | ;; R^2(\alpha^2+(\beta \sin\theta)^2)$. The angle $\theta$ is the colatitude of the 148 | ;; particle and $\phi$ is the longitude; the rate of change of the colatitude is 149 | ;; $\alpha$ and the rate of change of the longitude is $\beta$. 150 | ;; #+end_quote 151 | 152 | ;; So the particle has some generalized kinetic energy with terms for: 153 | 154 | ;; - its speed north and south, and 155 | ;; - its speed east and west, scaled to be strongest at 0 longitude along the $x$ 156 | ;; axis and fall off to nothing at the $y$ axis. 157 | 158 | ;; Here is the Lagrangian: 159 | 160 | 161 | (define ((L-sphere m R) local) 162 | (let* ((q (coordinate local)) 163 | (qdot (velocity local)) 164 | (theta (ref q 0)) 165 | (alpha (ref qdot 0)) 166 | (beta (ref qdot 1))) 167 | (* 1/2 m (square R) 168 | (+ (square alpha) 169 | (square (* beta (sin theta))))))) 170 | 171 | 172 | ;; #+RESULTS: 173 | ;; : #| L-sphere |# 174 | 175 | ;; Here is the full derivation: 176 | 177 | 178 | (lagrange-equation-steps 179 | (L-sphere 'm 'R) 180 | (up (literal-function 'theta) 181 | (literal-function 'phi))) 182 | 183 | 184 | ;; #+RESULTS[5d05668e1d73bcd0f884eb8ba013c4eb56e72fda]: 185 | ;; \begin{equation} 186 | ;; \begin{pmatrix} \displaystyle{ \begin{bmatrix} \displaystyle{ {R}^{2} m \sin\left( \theta\left( t \right) \right) \cos\left( \theta\left( t \right) \right) {\left( D\phi\left( t \right) \right)}^{2}} \cr \cr \displaystyle{ 0}\end{bmatrix}} \cr \cr \displaystyle{ \begin{bmatrix} \displaystyle{ {R}^{2} m D\theta\left( t \right)} \cr \cr \displaystyle{ {R}^{2} m {\left( \sin\left( \theta\left( t \right) \right) \right)}^{2} D\phi\left( t \right)}\end{bmatrix}} \cr \cr \displaystyle{ \begin{bmatrix} \displaystyle{ {R}^{2} m {D}^{2}\theta\left( t \right)} \cr \cr \displaystyle{ 2 {R}^{2} m \sin\left( \theta\left( t \right) \right) D\theta\left( t \right) \cos\left( \theta\left( t \right) \right) D\phi\left( t \right) + {R}^{2} m {\left( \sin\left( \theta\left( t \right) \right) \right)}^{2} {D}^{2}\phi\left( t \right)}\end{bmatrix}} \cr \cr \displaystyle{ \begin{bmatrix} \displaystyle{ - {R}^{2} m \sin\left( \theta\left( t \right) \right) \cos\left( \theta\left( t \right) \right) {\left( D\phi\left( t \right) \right)}^{2} + {R}^{2} m {D}^{2}\theta\left( t \right)} \cr \cr \displaystyle{ 2 {R}^{2} m \sin\left( \theta\left( t \right) \right) D\theta\left( t \right) \cos\left( \theta\left( t \right) \right) D\phi\left( t \right) + {R}^{2} m {\left( \sin\left( \theta\left( t \right) \right) \right)}^{2} {D}^{2}\phi\left( t \right)}\end{bmatrix}}\end{pmatrix} 187 | ;; \end{equation} 188 | 189 | ;; The final Lagrange residuals have a few terms that we can divide out. Scheme 190 | ;; doesn't know that these are meant to be residuals, so it won't cancel out 191 | ;; factors that we can see by eye are missing. 192 | 193 | ;; Isolate the Lagrange equations from the derivation and manually simplify each 194 | ;; equation by dividing out, respectively, $mR^2$ and $mR^2 \sin \theta$: 195 | 196 | 197 | (let* ((L (L-sphere 'm 'R)) 198 | (theta (literal-function 'theta)) 199 | (q (up theta (literal-function 'phi))) 200 | (le ((Lagrange-equations L) q))) 201 | (let ((eq1 (ref le 0)) 202 | (eq2 (ref le 1))) 203 | (->tex-equation 204 | ((up (/ eq1 (* 'm (square 'R))) 205 | (/ eq2 (* (sin theta) 'm (square 'R)))) 206 | 't)))) 207 | -------------------------------------------------------------------------------- /ch1/ex1-13.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.13: Higher-derivative Lagrangians (code) 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-13.scm :comments org 4 | ;; :END: 5 | 6 | ;; This exercise completes exercise 1.10 by asking for implementations of the 7 | ;; higher-order Lagrange equations that we derived. This was a nice Scheme 8 | ;; exercise; I would argue that this implementation should exist in the standard 9 | ;; library. But that would ruin the fun of the exercise... 10 | 11 | 12 | (load "ch1/utils.scm") 13 | ;; Part A: Acceleration-dependent Lagrangian Implementation 14 | 15 | ;; From the book: 16 | 17 | ;; #+begin_quote 18 | ;; Write a procedure to compute the Lagrange equations for Lagrangians that depend 19 | ;; upon acceleration, as in exercise 1.10. Note that Gamma can take an optional 20 | ;; argument giving the length of the initial segment of the local tuple needed. The 21 | ;; default length is 3, giving components of the local tuple up to and including 22 | ;; the velocities. 23 | ;; #+end_quote 24 | 25 | ;; Now that we know the math, the implementation is a straightforward extension of 26 | ;; the =Lagrange-equations= procedure presented in the book: 27 | 28 | 29 | (define ((Lagrange-equations3 L) q) 30 | (let ((state-path (Gamma q 4))) 31 | (+ ((square D) (compose ((partial 3) L) state-path)) 32 | (- (D (compose ((partial 2) L) state-path))) 33 | (compose ((partial 1) L) state-path)))) 34 | ;; Part B: Applying HO-Lagrangians 35 | 36 | ;; Now it's time to use the new function. From the book: 37 | 38 | ;; #+begin_quote 39 | ;; Use your procedure to compute the Lagrange equations for the Lagrangian 40 | 41 | ;; \begin{equation} 42 | ;; L(t, x, v, a) = - {1 \over 2}mxa - {1 \over 2}kx^2 43 | ;; \end{equation} 44 | 45 | ;; Do you recognize the resulting equation of motion? 46 | ;; #+end_quote 47 | 48 | ;; Here is the Lagrangian described in the problem: 49 | 50 | 51 | (define ((L-1-13 m k) local) 52 | (let ((x (coordinate local)) 53 | (a (acceleration local))) 54 | (- (* -1/2 m x a) 55 | (* 1/2 k (square x))))) 56 | 57 | 58 | ;; #+RESULTS: 59 | ;; : #| L-1-13 |# 60 | 61 | ;; Use the new function to generate the Lagrange equations. This call includes a 62 | ;; factor of $-1$ to make the equation look nice: 63 | 64 | 65 | (->tex-equation 66 | (- (((Lagrange-equations3 (L-1-13 'm 'k)) 67 | (literal-function 'x)) 't))) 68 | ;; Part C: Generalized Lagrange Equations 69 | 70 | ;; Now, some more fun with Scheme. It just feels nice to implement Scheme 71 | ;; procedures. From the book: 72 | 73 | ;; #+begin_quote 74 | ;; For more fun, write the general Lagrange equation procedure that takes a 75 | ;; Lagrangian that depends on any number of derivatives, and the number of 76 | ;; derivatives, to produce the required equations of motion. 77 | ;; #+end_quote 78 | 79 | ;; As a reminder, this is the equation that we need to implement for each 80 | ;; coordinate: 81 | 82 | ;; \begin{equation} 83 | ;; 0 = \sum_{i = 0}^n(-1)^i D^{i}(\partial_{i+1}L \circ \Gamma[q]) 84 | ;; \end{equation} 85 | 86 | ;; There are two ideas playing together here. Each term takes an element from: 87 | 88 | ;; - an alternating sequence of $1$ and $-1$ 89 | ;; - a sequence of increasing-index $D^i(\partial_i L \circ \Gamma[q])$ terms 90 | 91 | ;; The alternating $1, -1$ sequence is similar to a more general idea: take any 92 | ;; ordered collection arranged in a cycle, start at some point and walk around the 93 | ;; cycle for $n$ steps. 94 | 95 | ;; If you need to take $n$ steps along a cycle of length $l$, you'll end up 96 | ;; traveling around the cycle between $n \over l$ and ${n \over l} + 1$ times. 97 | 98 | ;; =alternate= generates a list of $n$ total elements generated by walking around 99 | ;; the ordered cycle of supplied =elems=: 100 | 101 | 102 | (define (cycle n elems) 103 | (apply append (make-list n elems))) 104 | 105 | (define (alternating n elems) 106 | (let* ((l (length elems)) 107 | (times (quotient (+ n (-1+ l)) l))) 108 | (list-head (cycle times elems) n))) 109 | 110 | 111 | ;; #+RESULTS: 112 | ;; : #| cycle |# 113 | ;; : 114 | ;; : #| alternating |# 115 | 116 | ;; Now, the general =Lagrange-equations*= implementation. 117 | 118 | ;; This function defines an internal function =term= that generates the $i$th term 119 | ;; of the derivative combination described above. This sequence is zipped with the 120 | ;; sequence of $1, -1$, and =fold-left= generates the sum. 121 | 122 | 123 | (define ((Lagrange-equations* L n) q) 124 | (let ((state-path (Gamma q (1+ n)))) 125 | (define (term i) 126 | ((expt D i) 127 | (compose ((partial (1+ i)) L) state-path))) 128 | (let ((terms (map term (iota n)))) 129 | (fold-left (lambda (acc pair) 130 | (+ acc (apply * pair))) 131 | 0 132 | (zip (alternating n '(1 -1)) 133 | (reverse terms)))))) 134 | 135 | 136 | ;; #+RESULTS: 137 | ;; : #| Lagrange-equations* |# 138 | 139 | ;; Generate the Lagrange equations from part b once more to check that we get the 140 | ;; same result: 141 | 142 | 143 | (->tex-equation 144 | (- (((Lagrange-equations* (L-1-13 'm 'k) 3) 145 | (literal-function 'x)) 't))) 146 | -------------------------------------------------------------------------------- /ch1/ex1-14.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.14: Coordinate-independence of Lagrange equations 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-14.scm :comments org 4 | ;; :END: 5 | 6 | ;; Look carefully at what this exercise is asking us to do: 7 | 8 | ;; #+begin_quote 9 | ;; Check that the Lagrange equations for central force motion in polar coordinates 10 | ;; and in rectangular coordinates are equivalent. Determine the relationship among 11 | ;; the second derivatives by substituting paths into the transformation equations 12 | ;; and computing derivatives, then substitute these relations into the equations of 13 | ;; motion. 14 | ;; #+end_quote 15 | 16 | ;; The punchline that we'll encounter soon is that a coordinate transformation of 17 | ;; applied to some path function $q$ can commute with $\Gamma$. You can always 18 | ;; write some function $C$ of the local tuple that handles the coordinate 19 | ;; transformation /after/ $\Gamma[q]$ instead of transforming the path directly. In 20 | ;; other words, you can always find some $C$ such that 21 | 22 | ;; \begin{equation} 23 | ;; C \circ \Gamma[q] = \Gamma[q'] 24 | ;; \end{equation} 25 | 26 | ;; Because function composition is associative, instead of ever transforming the 27 | ;; path, you can push the coordinate transformation into the Lagrangian to generate 28 | ;; a new Lagrangian: $L = L' \circ C$. 29 | 30 | ;; The section of textbook just before the exercise has given us two Lagrangians in 31 | ;; different coordinates -- =L-central-polar= and =L-rectangular= -- and generated 32 | ;; Lagrange equations from each. 33 | 34 | ;; Our task is to directly transform the Lagrange equations by substituting the 35 | ;; first and second derivatives of the coordinate transformation expression into 36 | ;; one of the sets of equations, and looking to see that it's equivalent to the 37 | ;; other. 38 | 39 | ;; Fair warning: this is much more painful than transforming the Lagrangian 40 | ;; /before/ generating the Lagrange equations. This exercise continues the theme of 41 | ;; devastating you with algebra as a way to show you the horror that the later 42 | ;; techniques were developed to avoid. Let us proceed. 43 | 44 | 45 | (load "ch1/utils.scm") 46 | 47 | 48 | ;; #+RESULTS: 49 | ;; : ;Loading "ch1/utils.scm"... 50 | ;; : ; Loading "ch1/exdisplay.scm"... done 51 | ;; : ;... done 52 | ;; : #| check-f |# 53 | 54 | ;; Here are the two Lagrangians from the book: 55 | 56 | 57 | (define ((L-central-rectangular m U) local) 58 | (let ((q (coordinate local)) 59 | (v (velocity local))) 60 | (- (* 1/2 m (square v)) 61 | (U (sqrt (square q)))))) 62 | 63 | (define ((L-central-polar m U) local) 64 | (let ((q (coordinate local)) 65 | (qdot (velocity local))) 66 | (let ((r (ref q 0)) (phi (ref q 1)) 67 | (rdot (ref qdot 0)) (phidot (ref qdot 1))) 68 | (- (* 1/2 m 69 | (+ (square rdot) 70 | (square (* r phidot))) ) 71 | (U r))))) 72 | 73 | 74 | ;; #+RESULTS: 75 | ;; : #| L-central-rectangular |# 76 | ;; : 77 | ;; : #| L-central-polar |# 78 | 79 | ;; Here are the rectangular equations of motion: 80 | 81 | 82 | (->tex-equation 83 | (((Lagrange-equations 84 | (L-central-rectangular 'm (literal-function 'U))) 85 | (up (literal-function 'x) 86 | (literal-function 'y))) 87 | 't) 88 | "eq:rect-equations") 89 | 90 | 91 | ;; #+RESULTS[3d6b30672d7d2fe77035ee8a5ae5b0f3046f2f90]: 92 | ;; \begin{equation} 93 | ;; \begin{bmatrix} \displaystyle{ {{m {D}^{2}x\left( t \right) \sqrt{{\left( x\left( t \right) \right)}^{2} + {\left( y\left( t \right) \right)}^{2}} + x\left( t \right) DU\left( \sqrt{{\left( x\left( t \right) \right)}^{2} + {\left( y\left( t \right) \right)}^{2}} \right)}\over {\sqrt{{\left( x\left( t \right) \right)}^{2} + {\left( y\left( t \right) \right)}^{2}}}}} \cr \cr \displaystyle{ {{m \sqrt{{\left( x\left( t \right) \right)}^{2} + {\left( y\left( t \right) \right)}^{2}} {D}^{2}y\left( t \right) + y\left( t \right) DU\left( \sqrt{{\left( x\left( t \right) \right)}^{2} + {\left( y\left( t \right) \right)}^{2}} \right)}\over {\sqrt{{\left( x\left( t \right) \right)}^{2} + {\left( y\left( t \right) \right)}^{2}}}}}\end{bmatrix} 94 | ;; \label{eq:rect-equations} 95 | ;; \end{equation} 96 | 97 | 98 | ;; And the polar Lagrange equations: 99 | 100 | 101 | (->tex-equation 102 | (((Lagrange-equations 103 | (L-central-polar 'm (literal-function 'U))) 104 | (up (literal-function 'r) 105 | (literal-function 'phi))) 106 | 't)) 107 | 108 | 109 | ;; #+RESULTS[557893e62f632f0900e9ece883c176eaf5bcfd05]: 110 | ;; \begin{equation} 111 | ;; \begin{bmatrix} \displaystyle{ - m r\left( t \right) {\left( D\phi\left( t \right) \right)}^{2} + m {D}^{2}r\left( t \right) + DU\left( r\left( t \right) \right)} \cr \cr \displaystyle{ m {D}^{2}\phi\left( t \right) {\left( r\left( t \right) \right)}^{2} + 2 m r\left( t \right) D\phi\left( t \right) Dr\left( t \right)}\end{bmatrix} 112 | ;; \end{equation} 113 | 114 | ;; Once again, our goal is to show that, if you can write down coordinate 115 | ;; transformations for the coordinates, velocities and accelerations and substitute 116 | ;; them in to one set of Lagrange equations, the other will appear. 117 | 118 | ;; To do this by hand, take the coordinate transformation described in 1.64 in the 119 | ;; book: 120 | 121 | ;; \begin{equation} 122 | ;; \begin{split} 123 | ;; x &= r \cos \phi \cr 124 | ;; y &= r \sin \phi 125 | ;; \end{split} 126 | ;; \end{equation} 127 | 128 | ;; Note that $x$, $y$, $r$ and $\phi$ are functions of $t$. Take the derivative of 129 | ;; each equation (Use the product and chain rules) to obtain expressions for the 130 | ;; rectangular velocities in terms of the polar coordinates, just like equation 131 | ;; 1.66 in the book: 132 | 133 | ;; \begin{equation} 134 | ;; \begin{split} 135 | ;; Dx(t) &= Dr(t) \cos \phi(t) - r(t) D\phi(t) \sin \phi(t) \cr 136 | ;; Dy(t) &= Dr(t) \sin \phi(t) + r(t) D\phi(t) \cos \phi(t) 137 | ;; \end{split} 138 | ;; \end{equation} 139 | 140 | ;; The rectangular equations of motion have second derivatives, so we need to keep 141 | ;; going. This is too devastating to imagine doing by hand. Let's move to Scheme. 142 | 143 | ;; Write the coordinate transformation for polar coordinates to rectangular in 144 | ;; Scheme: 145 | 146 | 147 | (define (p->r local) 148 | (let* ((polar-tuple (coordinate local)) 149 | (r (ref polar-tuple 0)) 150 | (phi (ref polar-tuple 1)) 151 | (x (* r (cos phi))) 152 | (y (* r (sin phi)))) 153 | (up x y))) 154 | 155 | 156 | ;; #+RESULTS: 157 | ;; : #| p->r |# 158 | 159 | ;; Now use =F->C=, first described on page 46. This is a function that takes a 160 | ;; coordinate transformation like =p->r= and returns a /new/ function that can 161 | ;; convert an entire local tuple from one coordinate system to another; the $C$ 162 | ;; discussed above. 163 | 164 | ;; The version that the book presents on page 46 can only generate a velocity 165 | ;; transformation given a coordinate transformation, but =scmutils= contains a more 166 | ;; general version that will convert as many path elements as you pass to it. 167 | 168 | ;; Here are the rectangular positions, velocities and accelerations, written in 169 | ;; polar coordinates: 170 | 171 | 172 | (let ((convert-path (F->C p->r)) 173 | (polar-path (up 't 174 | (up 'r 'phi) 175 | (up 'rdot 'phidot) 176 | (up 'rdotdot 'phidotdot)))) 177 | (->tex-equation 178 | (convert-path polar-path))) 179 | 180 | 181 | ;; #+RESULTS[1bac37835829a8c17e06699ef20f2e42676725b9]: 182 | ;; \begin{equation} 183 | ;; \begin{pmatrix} \displaystyle{ t} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ r \cos\left( \phi \right)} \cr \cr \displaystyle{ r \sin\left( \phi \right)}\end{pmatrix}} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ - \dot{\phi} r \sin\left( \phi \right) + \dot{r} \cos\left( \phi \right)} \cr \cr \displaystyle{ \dot{\phi} r \cos\left( \phi \right) + \dot{r} \sin\left( \phi \right)}\end{pmatrix}} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ - {\dot{\phi}}^{2} r \cos\left( \phi \right) - 2 \dot{\phi} \dot{r} \sin\left( \phi \right) - \ddot{\phi} r \sin\left( \phi \right) + \ddot{r} \cos\left( \phi \right)} \cr \cr \displaystyle{ - {\dot{\phi}}^{2} r \sin\left( \phi \right) + 2 \dot{\phi} \dot{r} \cos\left( \phi \right) + \ddot{\phi} r \cos\left( \phi \right) + \ddot{r} \sin\left( \phi \right)}\end{pmatrix}}\end{pmatrix} 184 | ;; \end{equation} 185 | 186 | 187 | ;; Ordinarily, it would be too heartbreaking to substitute these in to the 188 | ;; rectangular equations of motion. The fact that we have Scheme on our side gives 189 | ;; me the strength to proceed. 190 | 191 | ;; Write the rectangular Lagrange equations as a function of the local tuple, so we 192 | ;; can call it directly: 193 | 194 | 195 | (define (rect-equations local) 196 | (let* ((q (coordinate local)) 197 | (x (ref q 0)) 198 | (y (ref q 1)) 199 | 200 | (v (velocity local)) 201 | (xdot (ref v 0)) 202 | (ydot (ref v 1)) 203 | 204 | (a (acceleration local)) 205 | (xdotdot (ref a 0)) 206 | (ydotdot (ref a 1)) 207 | 208 | (U (literal-function 'U))) 209 | (up (/ (+ (* 'm xdotdot (sqrt (+ (square x) (square y)))) 210 | (* x ((D U) (sqrt (+ (square x) (square y)))))) 211 | (sqrt (+ (square x) (square y)))) 212 | (/ (+ (* 'm ydotdot (sqrt (+ (square x) (square y)))) 213 | (* y ((D U) (sqrt (+ (square x) (square y)))))) 214 | (sqrt (+ (square x) (square y))))))) 215 | 216 | 217 | ;; #+RESULTS: 218 | ;; : #| rect-equations |# 219 | 220 | ;; Verify that these are, in fact, the rectangular equations of motion by passing 221 | ;; in a symbolic rectangular local tuple: 222 | 223 | 224 | (let ((rect-path (up 't 225 | (up 'x 'y) 226 | (up 'xdot 'ydot) 227 | (up 'xdotdot 'ydotdot)))) 228 | (->tex-equation 229 | (rect-equations rect-path))) 230 | 231 | 232 | ;; #+RESULTS[5e06ee310a8c8e3036c17c5863647c80960dc568]: 233 | ;; \begin{equation} 234 | ;; \begin{pmatrix} \displaystyle{ {{m \ddot{x} \sqrt{{x}^{2} + {y}^{2}} + x DU\left( \sqrt{{x}^{2} + {y}^{2}} \right)}\over {\sqrt{{x}^{2} + {y}^{2}}}}} \cr \cr \displaystyle{ {{m \ddot{y} \sqrt{{x}^{2} + {y}^{2}} + y DU\left( \sqrt{{x}^{2} + {y}^{2}} \right)}\over {\sqrt{{x}^{2} + {y}^{2}}}}}\end{pmatrix} 235 | ;; \end{equation} 236 | 237 | ;; Now use the =p->r= conversion to substitute each of the rectangular values above 238 | ;; with their associated polar values: 239 | 240 | 241 | (let* ((convert-path (F->C p->r)) 242 | (polar-path (up 't 243 | (up 'r 'phi) 244 | (up 'rdot 'phidot) 245 | (up 'rdotdot 'phidotdot))) 246 | (local (convert-path polar-path))) 247 | (->tex-equation 248 | (rect-equations local))) 249 | 250 | 251 | ;; #+RESULTS[577a75ce68ba364856b29d9b49e8f95c130ec027]: 252 | ;; \begin{equation} 253 | ;; \begin{pmatrix} \displaystyle{ - m {\dot{\phi}}^{2} r \cos\left( \phi \right) - 2 m \dot{\phi} \dot{r} \sin\left( \phi \right) - m \ddot{\phi} r \sin\left( \phi \right) + m \ddot{r} \cos\left( \phi \right) + DU\left( r \right) \cos\left( \phi \right)} \cr \cr \displaystyle{ - m {\dot{\phi}}^{2} r \sin\left( \phi \right) + 2 m \dot{\phi} \dot{r} \cos\left( \phi \right) + m \ddot{\phi} r \cos\left( \phi \right) + m \ddot{r} \sin\left( \phi \right) + DU\left( r \right) \sin\left( \phi \right)}\end{pmatrix} 254 | ;; \end{equation} 255 | 256 | ;; Oh no. This looks quite different from the polar Lagrange equations above. What 257 | ;; is the problem? 258 | 259 | ;; I had to stare at this for a long time before I saw what to do. Notice that the 260 | ;; terms we want from the polar Lagrange equations all seem to appear in the first 261 | ;; equation with a $\cos \phi$, and in the second equation with a $\sin \phi$. 262 | ;; Using the trigonometric identity: 263 | 264 | ;; \begin{equation} 265 | ;; (\cos \phi)^2 + (\sin \phi)^2 = 1 266 | ;; \end{equation} 267 | 268 | ;; I realized that I could recover the first equation through a linear combination 269 | ;; of both terms. Multiply the first by $\cos \phi$ and the second by $\sin \phi$, 270 | ;; add them together and the unwanted terms all drop away. 271 | 272 | ;; A similar trick recovers the second equation,given an extra factor of $r$: 273 | 274 | 275 | (let* ((convert-path (F->C p->r)) 276 | (polar-path (up 't 277 | (up 'r 'phi) 278 | (up 'rdot 'phidot) 279 | (up 'rdotdot 'phidotdot))) 280 | (local (convert-path polar-path)) 281 | (eq (rect-equations local))) 282 | (->tex-equation 283 | (up (+ (* (cos 'phi) (ref eq 0)) 284 | (* (sin 'phi) (ref eq 1))) 285 | (- (* 'r (cos 'phi) (ref eq 1)) 286 | (* 'r (sin 'phi) (ref eq 0)))))) 287 | -------------------------------------------------------------------------------- /ch1/ex1-15.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.15: Equivalence 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-15.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | ;; Scheme Tools 9 | 10 | ;; Equation (1.77) in the book describes how to implement $C$ given some arbitrary 11 | ;; $F$. Looking ahead slightly, this is implemented as =F->C= on page 46. 12 | 13 | ;; The following function is a slight redefinition that allows us to use an $F$ 14 | ;; that takes an explicit $(t, x')$, instead of the entire local tuple: 15 | 16 | 17 | (define ((F->C* F) local) 18 | (let ((t (time local)) 19 | (x (coordinate local)) 20 | (v (velocity local))) 21 | (up t 22 | (F t x) 23 | (+ (((partial 0) F) t x) 24 | (* (((partial 1) F) t x) 25 | v))))) 26 | 27 | 28 | ;; #+RESULTS[8ea33eda9107b7b0d6ce890f316eb453b2d96fca]: 29 | ;; : #| F->C* |# 30 | 31 | ;; Next we define $F$, $C$ and $L$ as described above, as well as =qprime=, a 32 | ;; function that can represent our unprimed coordinate path function. 33 | 34 | ;; The types here all imply that the path has one real coordinate. I did this to 35 | ;; make the types easier to understand; the derivation applies equally well to 36 | ;; paths with many dimensions. 37 | 38 | 39 | (define F 40 | (literal-function 'F (-> (X Real Real) Real))) 41 | 42 | (define C (F->C* F)) 43 | 44 | (define L 45 | (literal-function 'L (-> (UP Real Real Real) Real))) 46 | 47 | (define qprime 48 | (literal-function 'qprime)) 49 | 50 | 51 | ;; #+RESULTS: 52 | ;; : #| F |# 53 | ;; : 54 | ;; : #| C |# 55 | ;; : 56 | ;; : #| L |# 57 | ;; : 58 | ;; : #| qprime |# 59 | 60 | ;; When we apply $C$ to the primed local tuple, do we get the transformed tuple 61 | ;; that we expect from 1.77 in the book? 62 | 63 | 64 | (->tex-equation 65 | ((compose C (Gamma qprime)) 't)) 66 | 67 | 68 | ;; #+RESULTS[ecef7fe872de385af827c689dbd0db76aa5319f0]: 69 | ;; \begin{equation} 70 | ;; \begin{pmatrix} \displaystyle{ t} \cr \cr \displaystyle{ F\left( t, {q}^\prime\left( t \right) \right)} \cr \cr \displaystyle{ D{q}^\prime\left( t \right) {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{0}F\left( t, {q}^\prime\left( t \right) \right)}\end{pmatrix} 71 | ;; \end{equation} 72 | 73 | ;; This looks correct. We can also transform the path before passing it to 74 | ;; $\Gamma$: 75 | 76 | 77 | (define ((to-q F qp) t) 78 | (F t (qp t))) 79 | 80 | 81 | ;; #+RESULTS: 82 | ;; : #| to-q |# 83 | 84 | ;; Subtract the two forms to see that they're equivalent: 85 | 86 | 87 | (->tex-equations 88 | ((- (compose C (Gamma qprime)) 89 | (Gamma (to-q F qprime))) 90 | 't)) 91 | 92 | 93 | ;; #+RESULTS[10aea4a5b833aa00e0a1c63049d844dc37528289]: 94 | ;; \begin{equation} 95 | ;; \begin{pmatrix} \displaystyle{ 0} \cr \cr \displaystyle{ 0} \cr \cr \displaystyle{ 0}\end{pmatrix} 96 | ;; \end{equation} 97 | 98 | ;; Now that we know $C$ is correct we can define $q$, the unprimed coordinate path 99 | ;; function, and =Lprime=: 100 | 101 | 102 | (define q (to-q F qprime)) 103 | (define Lprime (compose L C)) 104 | ;; Derivation 105 | 106 | ;; Begin by calculating the components of the Lagrange equations in equation 107 | ;; \eqref{eq:lagrange-prime}. Examine the $\partial_2L'$ term first. 108 | 109 | ;; As we discussed above, function composition is associative, so: 110 | 111 | ;; \begin{equation} 112 | ;; \label{eq:c-l} 113 | ;; (L \circ C) \circ \Gamma[q'] = L' \circ \Gamma[q'] \implies L' = L \circ C 114 | ;; \end{equation} 115 | 116 | ;; Substituting $L'$ from \eqref{eq:c-l} and using the chain rule: 117 | 118 | ;; \begin{equation} 119 | ;; \partial_2L' = \partial_2(L \circ C) = ((DL) \circ C) \partial_2 C 120 | ;; \end{equation} 121 | 122 | ;; I found the next step troubling until I became more comfortable with the 123 | ;; functional notation. 124 | 125 | ;; $C$ is a function that transforms a local tuple. It takes 3 arguments (a tuple 126 | ;; with 3 elements, technically) and returns 3 arguments. $\partial_2 C$ is an 127 | ;; up-tuple with 3 entries. Each entry describes the derivative each component of 128 | ;; $C$'s output with respect to the velocity component of the local tuple. 129 | 130 | ;; $L$ is a function that transforms the 3-element local to a scalar output. $DL$ 131 | ;; is a down-tuple with 3 entries. Each entry describes the derivative of the 132 | ;; single output with respect to each entry of the local tuple. 133 | 134 | ;; The tuple algebra described in Chapter 9 defines multiplication between an up 135 | ;; and down tuple as a dot product, or a "contraction" in the book's language. This 136 | ;; means that we can expand out the product above: 137 | 138 | ;; \begin{equation} 139 | ;; (DL \circ C)\partial_2 C = (\partial_0L \circ C)(I_0 \circ \partial_2 C) + (\partial_1L \circ C)(I_1 \circ \partial_2 C) + (\partial_2L \circ C)(I_2 \circ \partial_2 C) 140 | ;; \end{equation} 141 | 142 | ;; $I_0$, $I_1$ and $I_2$ are "selectors" that return that single element of the 143 | ;; local tuple. 144 | 145 | ;; Example the value of $\partial_2C$ using our Scheme utilities: 146 | 147 | 148 | (->tex-equation 149 | (((partial 2) C) (up 't 'xprime 'vprime)) 150 | "eq:p2c") 151 | 152 | 153 | ;; #+RESULTS[2ad70f16eca982284368a2f70f31de3b2de41025]: 154 | ;; \begin{equation} 155 | ;; \begin{pmatrix} \displaystyle{ 0} \cr \cr \displaystyle{ 0} \cr \cr \displaystyle{ {\partial}_{1}F\left( t, {x}^\prime \right)}\end{pmatrix} 156 | ;; \label{eq:p2c} 157 | ;; \end{equation} 158 | 159 | ;; The first two components are 0, leaving us with: 160 | 161 | ;; \begin{equation} 162 | ;; \partial_2 L' = (DL \circ C)\partial_2 C = (\partial_2L \circ C)(I_2 \circ \partial_2 C) 163 | ;; \end{equation} 164 | 165 | ;; Compose this quantity with $\Gamma[q']$ and distribute the composition into the 166 | ;; product. Remember that $C \circ \Gamma[q'] = \Gamma[q]$: 167 | 168 | ;; \begin{equation} 169 | ;; \begin{aligned} 170 | ;; \partial_2L' \circ \Gamma[q'] & = (\partial_2L \circ C)(I_2 \circ \partial_2 C) \circ \Gamma[q'] \cr 171 | ;; & = (\partial_2L \circ C \circ \Gamma[q'])(I_2 \circ \partial_2 C \circ \Gamma[q']) \cr 172 | ;; & = (\partial_2L \circ \Gamma[q])(I_2 \circ \partial_2 C \circ \Gamma[q']) 173 | ;; \end{aligned} 174 | ;; \end{equation} 175 | 176 | ;; Take the derivative (with respect to time, remember, from the types): 177 | 178 | ;; \begin{equation} 179 | ;; D(\partial_2L' \circ \Gamma[q']) = D\left[(\partial_2L \circ \Gamma[q])(I_2 \circ \partial_2 C \circ \Gamma[q'])\right] 180 | ;; \end{equation} 181 | 182 | ;; Substitute the second term using \eqref{eq:p2c}: 183 | 184 | ;; \begin{equation} 185 | ;; D(\partial_2L' \circ \Gamma[q']) = D\left[(\partial_2L \circ \Gamma[q])\partial_1F(t, q'(t))\right] 186 | ;; \end{equation} 187 | 188 | ;; Expand using the product rule: 189 | 190 | ;; \begin{equation} 191 | ;; \label{eq:ex1-15-dp2l} 192 | ;; D(\partial_2L' \circ \Gamma[q']) = \left[ D(\partial_2L \circ \Gamma[q]) \right]\partial_1F(t, q'(t)) + (\partial_2L \circ \Gamma[q])D\left[ \partial_1F(t, q'(t)) \right] 193 | ;; \end{equation} 194 | 195 | ;; A term from the unprimed Lagrange's equation is peeking. Notice this, but don't 196 | ;; make the substitution just yet. 197 | 198 | ;; Next, expand the $\partial_1 L'$ term: 199 | 200 | ;; \begin{equation} 201 | ;; \partial_1L' = \partial_1(L \circ C) = ((DL) \circ C) \partial_1 C 202 | ;; \end{equation} 203 | 204 | ;; Calculate $\partial_1C$ using our Scheme utilities: 205 | 206 | 207 | (->tex-equation 208 | (((partial 1) C) (up 't 'xprime 'vprime))) 209 | ;; Scheme Derivation 210 | 211 | ;; Can we use Scheme to pursue the same derivation? If we can write the 212 | ;; relationships of the derivation in code, then we'll have a sort of computerized 213 | ;; proof that the primed Lagrange equations are valid. 214 | 215 | ;; First, consider $\partial_1 L' \circ \Gamma[q']$: 216 | 217 | 218 | (->tex-equation 219 | ((compose ((partial 1) Lprime) (Gamma qprime)) 220 | 't)) 221 | 222 | 223 | ;; #+RESULTS[5eac70f3edfcf5feeb3a2eb9b98d89646f21ade3]: 224 | ;; \begin{equation} 225 | ;; D{q}^\prime\left( t \right) {\partial}_{2}L\left( \begin{pmatrix} \displaystyle{ t} \cr \cr \displaystyle{ F\left( t, {q}^\prime\left( t \right) \right)} \cr \cr \displaystyle{ D{q}^\prime\left( t \right) {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{0}F\left( t, {q}^\prime\left( t \right) \right)}\end{pmatrix} \right) {{\partial}_{1}}^{2}\left( F \right)\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) {\partial}_{1}L\left( \begin{pmatrix} \displaystyle{ t} \cr \cr \displaystyle{ F\left( t, {q}^\prime\left( t \right) \right)} \cr \cr \displaystyle{ D{q}^\prime\left( t \right) {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{0}F\left( t, {q}^\prime\left( t \right) \right)}\end{pmatrix} \right) + {\partial}_{2}L\left( \begin{pmatrix} \displaystyle{ t} \cr \cr \displaystyle{ F\left( t, {q}^\prime\left( t \right) \right)} \cr \cr \displaystyle{ D{q}^\prime\left( t \right) {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{0}F\left( t, {q}^\prime\left( t \right) \right)}\end{pmatrix} \right) \left( {\partial}_{0} {\partial}_{1} \right)\left( F \right)\left( t, {q}^\prime\left( t \right) \right) 226 | ;; \end{equation} 227 | 228 | ;; This is completely insane, and already unhelpful. The argument to $L$, we know, 229 | ;; is actually $\Gamma[q]$. Make a function that will replace the tuple with that 230 | ;; reference: 231 | 232 | 233 | (define (->eq expr) 234 | (write-string 235 | (replace-all (->tex-equation* expr) 236 | (->tex* ((Gamma q) 't)) 237 | "\\circ \\Gamma[q]"))) 238 | 239 | 240 | ;; #+RESULTS: 241 | ;; : #| ->eq |# 242 | 243 | ;; Try again: 244 | 245 | 246 | (->eq 247 | ((compose ((partial 1) Lprime) (Gamma qprime)) 248 | 't)) 249 | 250 | 251 | ;; #+RESULTS[ee6c612cadd91730dd0142a4dd7476fda80d6e07]: 252 | ;; \begin{equation} 253 | ;; D{q}^\prime\left( t \right) {\partial}_{2}L\left( \circ \Gamma[q] \right) {{\partial}_{1}}^{2}\left( F \right)\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) {\partial}_{1}L\left( \circ \Gamma[q] \right) + {\partial}_{2}L\left( \circ \Gamma[q] \right) \left( {\partial}_{0} {\partial}_{1} \right)\left( F \right)\left( t, {q}^\prime\left( t \right) \right) 254 | ;; \end{equation} 255 | 256 | ;; Ignore the parentheses around $\circ \Gamma[q]$ and this looks better. 257 | 258 | ;; The $\partial_1 L \circ \Gamma[q]$ term of the unprimed Lagrange equations is 259 | ;; nestled inside the expansion above, multiplied by a factor $\partial_1F(t, 260 | ;; q'(t))$: 261 | 262 | 263 | (let* ((factor (((partial 1) F) 't (qprime 't)))) 264 | (->eq 265 | ((* factor (compose ((partial 1) L) (Gamma q))) 266 | 't))) 267 | 268 | 269 | ;; #+RESULTS[31b49f8349da58b715e99a7cbcdf983dc4e12d1e]: 270 | ;; \begin{equation} 271 | ;; {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) {\partial}_{1}L\left( \circ \Gamma[q] \right) 272 | ;; \end{equation} 273 | 274 | ;; Next, consider the $D(\partial_2 L' \circ \Gamma[q'])$ term: 275 | 276 | 277 | (->eq 278 | ((D (compose ((partial 2) Lprime) (Gamma qprime))) 279 | 't)) 280 | 281 | 282 | ;; #+RESULTS[9813f05b0fc4d5e7ad9ce035bca6e494cb087d84]: 283 | ;; \begin{equation} 284 | ;; {\left( D{q}^\prime\left( t \right) \right)}^{2} {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) {{\partial}_{1}}^{2}\left( F \right)\left( t, {q}^\prime\left( t \right) \right) {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) + D{q}^\prime\left( t \right) {\left( {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) \right)}^{2} \left( {\partial}_{1} {\partial}_{2} \right)\left( L \right)\left( \circ \Gamma[q] \right) + 2 D{q}^\prime\left( t \right) {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) \left( {\partial}_{0} {\partial}_{1} \right)\left( F \right)\left( t, {q}^\prime\left( t \right) \right) {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) + {\left( {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) \right)}^{2} {D}^{2}{q}^\prime\left( t \right) {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) + {\partial}_{0}F\left( t, {q}^\prime\left( t \right) \right) {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) \left( {\partial}_{1} {\partial}_{2} \right)\left( L \right)\left( \circ \Gamma[q] \right) + D{q}^\prime\left( t \right) {\partial}_{2}L\left( \circ \Gamma[q] \right) {{\partial}_{1}}^{2}\left( F \right)\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) {{\partial}_{0}}^{2}\left( F \right)\left( t, {q}^\prime\left( t \right) \right) + {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) \left( {\partial}_{0} {\partial}_{2} \right)\left( L \right)\left( \circ \Gamma[q] \right) + {\partial}_{2}L\left( \circ \Gamma[q] \right) \left( {\partial}_{0} {\partial}_{1} \right)\left( F \right)\left( t, {q}^\prime\left( t \right) \right) 285 | ;; \end{equation} 286 | 287 | 288 | ;; This, again, is total madness. We really want some way to control how Scheme 289 | ;; expands terms. 290 | 291 | ;; But we know what we're looking for. Expand out the matching term of the unprimed 292 | ;; Lagrange equations: 293 | 294 | 295 | (->eq 296 | ((D (compose ((partial 2) L) (Gamma q))) 297 | 't)) 298 | 299 | 300 | ;; #+RESULTS[9937f7c80dcdc8744c8f2a1a57505172c55bee17]: 301 | ;; \begin{equation} 302 | ;; {\left( D{q}^\prime\left( t \right) \right)}^{2} {{\partial}_{1}}^{2}\left( F \right)\left( t, {q}^\prime\left( t \right) \right) {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) + D{q}^\prime\left( t \right) {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) \left( {\partial}_{1} {\partial}_{2} \right)\left( L \right)\left( \circ \Gamma[q] \right) + 2 D{q}^\prime\left( t \right) \left( {\partial}_{0} {\partial}_{1} \right)\left( F \right)\left( t, {q}^\prime\left( t \right) \right) {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) + {\partial}_{1}F\left( t, {q}^\prime\left( t \right) \right) {D}^{2}{q}^\prime\left( t \right) {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) + {\partial}_{0}F\left( t, {q}^\prime\left( t \right) \right) \left( {\partial}_{1} {\partial}_{2} \right)\left( L \right)\left( \circ \Gamma[q] \right) + {{\partial}_{2}}^{2}\left( L \right)\left( \circ \Gamma[q] \right) {{\partial}_{0}}^{2}\left( F \right)\left( t, {q}^\prime\left( t \right) \right) + \left( {\partial}_{0} {\partial}_{2} \right)\left( L \right)\left( \circ \Gamma[q] \right) 303 | ;; \end{equation} 304 | 305 | ;; Staring at these two equations, it becomes clear that the first contains the 306 | ;; second, multiplied by $\partial_1F(t, q'(t))$, the same factor that appeared in 307 | ;; the expansion of the $\partial_1 L \circ \Gamma[q]$ term. 308 | 309 | ;; Try writing out the primed Lagrange equations, and subtracting the unprimed 310 | ;; Lagrange equations, scaled by this factor: 311 | 312 | 313 | (let* ((primed-lagrange 314 | (- (D (compose ((partial 2) Lprime) (Gamma qprime))) 315 | (compose ((partial 1) Lprime) (Gamma qprime)))) 316 | 317 | (lagrange 318 | (- (D (compose ((partial 2) L) (Gamma q))) 319 | (compose ((partial 1) L) (Gamma q)))) 320 | 321 | (factor 322 | (compose coordinate ((partial 1) C) (Gamma qprime)))) 323 | (->tex-equation 324 | ((- primed-lagrange (* factor lagrange)) 325 | 't))) 326 | -------------------------------------------------------------------------------- /ch1/ex1-16.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.16: Central force motion 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-16.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | ;; Scheme Approach 9 | 10 | ;; To show the rectangular Lagrangian, get the procedure from page 41: 11 | 12 | 13 | (define ((L-central-rectangular m U) local) 14 | (let ((q (coordinate local)) 15 | (v (velocity local))) 16 | (- (* 1/2 m (square v)) 17 | (U (sqrt (square q)))))) 18 | 19 | 20 | ;; This is already written in a form that can handle an arbitrary number of 21 | ;; coordiantes. Confirm the rectangular Lagrangian by passing in a local tuple with 22 | ;; 3 dimensional coordinates and velocities: 23 | 24 | 25 | (->tex-equation 26 | ((L-central-rectangular 'm (literal-function 'U)) 27 | (up 't 28 | (up 'x 'y 'z) 29 | (up 'v_x 'v_y 'v_z)))) 30 | 31 | 32 | ;; #+RESULTS[9bf8352b0d3e667e7149e5519cc568efbbf2f331]: 33 | ;; \begin{equation} 34 | ;; {{1}\over {2}} m {{v}_{x}}^{2} + {{1}\over {2}} m {{v}_{y}}^{2} + {{1}\over {2}} m {{v}_{z}}^{2} - U\left( \sqrt{{x}^{2} + {y}^{2} + {z}^{2}} \right) 35 | ;; \end{equation} 36 | 37 | 38 | ;; Next, the spherical. Write down the coordinate transformation from spherical to 39 | ;; rectangular coordinates as a Scheme procedure: 40 | 41 | 42 | (define (spherical->rect local) 43 | (let* ((q (coordinate local)) 44 | (r (ref q 0)) 45 | (theta (ref q 1)) 46 | (phi (ref q 2))) 47 | (up (* r (sin theta) (cos phi)) 48 | (* r (sin theta) (sin phi)) 49 | (* r (cos theta))))) 50 | 51 | 52 | ;; #+RESULTS: 53 | ;; : #| spherical->rect |# 54 | 55 | ;; Here are the velocities calculated above by hand: 56 | 57 | 58 | (->tex-equation 59 | (velocity 60 | ((F->C spherical->rect) 61 | (up 't 62 | (up 'r 'theta 'phi) 63 | (up 'rdot 'thetadot 'phidot))))) 64 | 65 | 66 | ;; #+RESULTS[b41cbe257b2a859243c9b36052b54e533d08484e]: 67 | ;; \begin{equation} 68 | ;; \begin{pmatrix} \displaystyle{ - \dot{\phi} r \sin\left( \phi \right) \sin\left( \theta \right) + r \dot{\theta} \cos\left( \phi \right) \cos\left( \theta \right) + \dot{r} \cos\left( \phi \right) \sin\left( \theta \right)} \cr \cr \displaystyle{ \dot{\phi} r \cos\left( \phi \right) \sin\left( \theta \right) + r \dot{\theta} \sin\left( \phi \right) \cos\left( \theta \right) + \dot{r} \sin\left( \phi \right) \sin\left( \theta \right)} \cr \cr \displaystyle{ - r \dot{\theta} \sin\left( \theta \right) + \dot{r} \cos\left( \theta \right)}\end{pmatrix} 69 | ;; \end{equation} 70 | 71 | 72 | ;; Now that we have $L$ and $C$, we can compose them to get $L'$, our spherical 73 | ;; Lagrangian: 74 | 75 | 76 | (define (L-central-spherical m U) 77 | (compose (L-central-rectangular m U) 78 | (F->C spherical->rect))) 79 | 80 | 81 | ;; #+RESULTS: 82 | ;; : #| L-central-spherical |# 83 | 84 | ;; Confirm that this is equivalent to the analytic solution: 85 | 86 | 87 | (->tex-equation 88 | ((L-central-spherical 'm (literal-function 'U)) 89 | (up 't 90 | (up 'r 'theta 'phi) 91 | (up 'rdot 'thetadot 'phidot)))) 92 | ;; Exercise 1.17: Bead on a helical wire 93 | ;; :PROPERTIES: 94 | ;; :header-args+: :tangle ch1/ex1-16.scm :comments org 95 | ;; :END: 96 | 97 | 98 | (load "ch1/utils.scm") 99 | 100 | 101 | ;; #+RESULTS: 102 | ;; : ;Loading "ch1/utils.scm"... 103 | ;; : ; Loading "ch1/exdisplay.scm"... done 104 | ;; : ;... done 105 | ;; : #| check-f |# 106 | 107 | ;; This, and the next three exercises, are here to give you practice in the real 108 | ;; art, of difficulty, of any dynamics problem. It's easy to change coordinates. So 109 | ;; what coordinates do you use? 110 | 111 | ;; #+begin_quote 112 | ;; A bead of mass $m$ is constrained to move on a frictionless helical wire. The 113 | ;; helix is oriented so that its axis is horizontal. The diameter of the helix is 114 | ;; $d$ and its pitch (turns per unit length) is $h$. The system is in a uniform 115 | ;; gravitational field with vertical acceleration $g$. Formulate a Lagrangian that 116 | ;; describes the system and find the Lagrange equations of motion. 117 | ;; #+end_quote 118 | 119 | ;; I'll replace this with a better picture later, but this is the setup: 120 | 121 | ;; #+DOWNLOADED: screenshot @ 2020-06-25 11:03:55 122 | ;; #+attr_org: :width 400px 123 | ;; #+attr_html: :width 80% :align center 124 | ;; #+attr_latex: :width 8cm 125 | ;; [[file:images/Lagrangian_Mechanics/2020-06-25_11-03-55_screenshot.png]] 126 | 127 | 128 | (define ((turns->rect d h) local) 129 | (let* ((turns (coordinate local)) 130 | (theta (* turns 2 'pi))) 131 | (up (/ turns h) 132 | (* (/ d 2) (cos theta)) 133 | (* (/ d 2) (sin theta))))) 134 | 135 | 136 | ;; #+RESULTS: 137 | ;; : #| turns->rect |# 138 | 139 | ;; Or you could do this. Remember, these transformations need to be functions of a 140 | ;; local tuple, so if you're going to compose them, remember to put =coordinate= at 141 | ;; the beginning of the composition. 142 | 143 | 144 | (define ((turns->x-theta h) q) 145 | (up (/ q h) 146 | (* q 2 'pi))) 147 | 148 | (define ((x-theta->rect d) q) 149 | (let* ((x (ref q 0)) 150 | (theta (ref q 1))) 151 | (up x 152 | (* (/ d 2) (cos theta)) 153 | (* (/ d 2) (sin theta))))) 154 | 155 | (define (turns->rect* d h) 156 | (compose (x-theta->rect d) 157 | (turns->x-theta h) 158 | coordinate)) 159 | 160 | 161 | ;; #+RESULTS: 162 | ;; : #| turns->x-theta |# 163 | ;; : 164 | ;; : #| x-theta->rect |# 165 | ;; : 166 | ;; : #| turns->rect* |# 167 | 168 | ;; The transformations are identical: 169 | 170 | 171 | (->tex-equation 172 | ((- (turns->rect 'd 'h) 173 | (turns->rect* 'd 'h)) 174 | (up 't 'n 'ndot))) 175 | 176 | 177 | ;; #+RESULTS[3fa8a307ddde828e0f3b9b6c573e5935c577f76a]: 178 | ;; \begin{equation} 179 | ;; \begin{pmatrix} \displaystyle{ 0} \cr \cr \displaystyle{ 0} \cr \cr \displaystyle{ 0}\end{pmatrix} 180 | ;; \end{equation} 181 | 182 | ;; Define the Lagrangian: 183 | 184 | 185 | (define ((L-rectangular m U) local) 186 | (let ((q (coordinate local)) 187 | (v (velocity local))) 188 | (- (* 1/2 m (square v)) 189 | (U q)))) 190 | 191 | (define (L-turns m d h U) 192 | (compose (L-rectangular m U) 193 | (F->C (turns->rect d h)))) 194 | 195 | 196 | ;; #+RESULTS: 197 | ;; : #| L-rectangular |# 198 | ;; : 199 | ;; : #| L-turns |# 200 | 201 | ;; The potential is a uniform gravitational acceleration: 202 | 203 | 204 | (define ((U-grav m g) q) 205 | (* m g (ref q 2))) 206 | 207 | 208 | ;; #+RESULTS: 209 | ;; : #| U-grav |# 210 | 211 | ;; Final Lagrangian: 212 | 213 | 214 | (->tex-equation 215 | ((L-turns 'm 'd 'h (U-grav 'm 'g)) 216 | (up 't 'n 'ndot))) 217 | 218 | 219 | ;; #+RESULTS[a486b9871810f8a74d1883be47666fa323a6de81]: 220 | ;; \begin{equation} 221 | ;; {{{{1}\over {2}} {d}^{2} {h}^{2} m {\dot{n}}^{2} {\pi}^{2} - {{1}\over {2}} d g {h}^{2} m \sin\left( 2 n \pi \right) + {{1}\over {2}} m {\dot{n}}^{2}}\over {{h}^{2}}} 222 | ;; \end{equation} 223 | 224 | ;; Lagrange equations of motion: 225 | 226 | 227 | (let* ((L (L-turns 'm 'd 'h (U-grav 'm 'g))) 228 | (n (literal-function 'n))) 229 | (->tex-equation 230 | (((Lagrange-equations L) n) 't))) 231 | ;; Exercise 1.18: Bead on a triaxial surface 232 | ;; :PROPERTIES: 233 | ;; :header-args+: :tangle ch1/ex1-16.scm :comments org 234 | ;; :END: 235 | 236 | 237 | (load "ch1/utils.scm") 238 | 239 | 240 | ;; #+RESULTS: 241 | ;; : ;Loading "ch1/utils.scm"... 242 | ;; : ; Loading "ch1/exdisplay.scm"... done 243 | ;; : ;... done 244 | ;; : #| check-f |# 245 | 246 | ;; #+begin_quote 247 | ;; A bead of mass $m$ moves without friction on a triaxial ellipsoidal surface. In 248 | ;; rectangular coordinates the surface satisfies 249 | 250 | ;; \begin{equation} 251 | ;; {x^2 \over a^2} + {y^2 \over b^2} + {z^2 \over c^2} = 1 252 | ;; \end{equation} 253 | 254 | ;; for some constants $a$, $b$, and $c$. Identify suitable generalized coordinates, 255 | ;; formulate a Lagrangian, and find Lagrange's equations. 256 | ;; #+end_quote 257 | 258 | ;; The transformation to elliptical coordinates is very similar to the spherical 259 | ;; coordinate transformation, but with a fixed $a$, $b$ and $c$ coefficient for 260 | ;; each rectangular dimension, and no more radial degree of freedom: 261 | 262 | 263 | (define ((elliptical->rect a b c) local) 264 | (let* ((q (coordinate local)) 265 | (theta (ref q 0)) 266 | (phi (ref q 1))) 267 | (up (* a (sin theta) (cos phi)) 268 | (* b (sin theta) (sin phi)) 269 | (* c (cos theta))))) 270 | 271 | 272 | ;; #+RESULTS: 273 | ;; : #| elliptical->rect |# 274 | 275 | ;; Next, the Lagrangian: 276 | 277 | 278 | (define ((L-free-particle m) local) 279 | (* 1/2 m (square 280 | (velocity local)))) 281 | 282 | (define (L-central-triaxial m a b c) 283 | (compose (L-free-particle m) 284 | (F->C (elliptical->rect a b c)))) 285 | 286 | 287 | ;; #+RESULTS: 288 | ;; : #| L-free-particle |# 289 | ;; : 290 | ;; : #| L-central-triaxial |# 291 | 292 | ;; Final Lagrangian: 293 | 294 | 295 | (let ((local (up 't 296 | (up 'theta 'phi) 297 | (up 'thetadot 'phidot)))) 298 | (->tex-equation 299 | ((L-central-triaxial 'm 'a 'b 'c) local))) 300 | 301 | 302 | ;; #+RESULTS[96029124f8a649771c860516d1c6e668422de93e]: 303 | ;; \begin{equation} 304 | ;; {{1}\over {2}} {a}^{2} m {\dot{\phi}}^{2} {\left( \sin\left( \phi \right) \right)}^{2} {\left( \sin\left( \theta \right) \right)}^{2} - {a}^{2} m \dot{\phi} \dot{\theta} \sin\left( \phi \right) \sin\left( \theta \right) \cos\left( \phi \right) \cos\left( \theta \right) + {{1}\over {2}} {a}^{2} m {\dot{\theta}}^{2} {\left( \cos\left( \phi \right) \right)}^{2} {\left( \cos\left( \theta \right) \right)}^{2} + {{1}\over {2}} {b}^{2} m {\dot{\phi}}^{2} {\left( \sin\left( \theta \right) \right)}^{2} {\left( \cos\left( \phi \right) \right)}^{2} + {b}^{2} m \dot{\phi} \dot{\theta} \sin\left( \phi \right) \sin\left( \theta \right) \cos\left( \phi \right) \cos\left( \theta \right) + {{1}\over {2}} {b}^{2} m {\dot{\theta}}^{2} {\left( \sin\left( \phi \right) \right)}^{2} {\left( \cos\left( \theta \right) \right)}^{2} + {{1}\over {2}} {c}^{2} m {\dot{\theta}}^{2} {\left( \sin\left( \theta \right) \right)}^{2} 305 | ;; \end{equation} 306 | 307 | ;; I'm sure there's some simplification in there for us. But why? 308 | 309 | ;; Lagrange equations of motion: 310 | 311 | 312 | (let* ((L (L-central-triaxial 'm 'a 'b 'c)) 313 | (theta (literal-function 'theta)) 314 | (phi (literal-function 'phi))) 315 | (->tex-equation 316 | (((Lagrange-equations L) (up theta phi)) 317 | 't))) 318 | ;; Exercise 1.19: Two-bar linkage 319 | ;; :PROPERTIES: 320 | ;; :header-args+: :tangle ch1/ex1-16.scm :comments org 321 | ;; :END: 322 | 323 | ;; Double pendulum, sort of, except the whole thing can fly around the plane. 324 | 325 | ;; The system description is: 326 | 327 | 328 | (load "ch1/utils.scm") 329 | 330 | 331 | ;; #+RESULTS: 332 | ;; : ;Loading "ch1/utils.scm"... 333 | ;; : ; Loading "ch1/exdisplay.scm"... done 334 | ;; : ;... done 335 | ;; : #| check-f |# 336 | 337 | ;; #+begin_quote 338 | ;; The two-bar linkage shown in figure 1.3 is constrained to move in the plane. It 339 | ;; is composed of three small massive bodies interconnected by two massless rigid 340 | ;; rods in a uniform gravitational field with vertical acceleration g. The rods are 341 | ;; pinned to the central body by a hinge that allows the linkage to fold. The 342 | ;; system is arranged so that the hinge is completely free: the members can go 343 | ;; through all configurations without collision. Formulate a Lagrangian that 344 | ;; describes the system and find the Lagrange equations of motion. Use the computer 345 | ;; to do this, because the equations are rather big. 346 | ;; #+end_quote 347 | 348 | ;; This is new. Now we have multiple bodies: 349 | 350 | ;; #+DOWNLOADED: https://tgvaughan.github.io/sicm/images/Art_P146.jpg @ 2020-06-29 05:39:01 351 | ;; #+attr_org: :width 400px 352 | ;; #+attr_html: :width 80% :align center 353 | ;; #+attr_latex: :width 8cm 354 | ;; [[file:images/Lagrangian_Mechanics/2020-06-29_05-39-01_Art_P146.jpg]] 355 | 356 | ;; We can handle this by treating our coordinate space as having new dimensions 357 | ;; for, say, $x_0$, $y_0$, $x_1$, $y_1$. The fact that multiple coordinates refer 358 | ;; to the same particle doesn't matter for the Lagrangian. But it's a confusing 359 | ;; API. 360 | 361 | ;; /Without/ any constraints, we have six degrees of freedom. $x, y$ for each 362 | ;; particle. With the constraints we have: 363 | 364 | ;; 1) $x, y$ for the central body 365 | ;; 2) $\theta$ and $\phi$ for the angles off center. 366 | 367 | ;; (Sketch these out on the picture for the final version.) 368 | 369 | ;; \begin{equation} 370 | ;; \begin{aligned} 371 | ;; x_2(t) & = x_2(t) \cr 372 | ;; y_2(t) & = y_2(t) \cr 373 | ;; x_1(t) & = x_2(t) + l_1 \sin \theta \cr 374 | ;; y_1(t) & = y_2(t) - l_1 \cos \theta \cr 375 | ;; x_3(t) & = x_2(t) + l_2 \sin \phi \cr 376 | ;; y_3(t) & = y_2(t) - l_2 \cos \phi 377 | ;; \end{aligned} 378 | ;; \end{equation} 379 | 380 | ;; Sketch out why this makes sense. Each angle is positive CCW for consistency, 381 | ;; since they can swing all the way around. 382 | 383 | ;; Write the coordinate transformation in scheme. 384 | 385 | 386 | (define ((double-linkage->rect l1 l2) local) 387 | (let* ((q (coordinate local)) 388 | (theta (ref q 0)) 389 | (phi (ref q 1)) 390 | (x2 (ref q 2)) 391 | (y2 (ref q 3))) 392 | (up (+ x2 (* l1 (sin theta))) 393 | (- y2 (* l1 (cos theta))) 394 | x2 395 | y2 396 | (+ x2 (* l2 (sin phi))) 397 | (- y2 (* l2 (cos phi)))))) 398 | 399 | 400 | ;; #+RESULTS: 401 | ;; : #| double-linkage->rect |# 402 | 403 | ;; Next, the Lagrangian given rectangular coordinates, assuming no constraints. 404 | ;; Remember, we have a uniform gravitational field pointing down; this means that 405 | ;; each of the components has a potential dragging on it. 406 | 407 | 408 | (define ((L-double-linkage-rect m1 m2 m3 U) local) 409 | (let* ((v (velocity local)) 410 | (vx1 (ref v 0)) 411 | (vy1 (ref v 1)) 412 | (vx2 (ref v 2)) 413 | (vy2 (ref v 3)) 414 | (vx3 (ref v 4)) 415 | (vy3 (ref v 5))) 416 | (- (+ (* m1 (+ (square vx1) 417 | (square vy1))) 418 | (* m2 (+ (square vx2) 419 | (square vy2))) 420 | (* m3 (+ (square vx3) 421 | (square vy3)))) 422 | (U (coordinate local))))) 423 | 424 | 425 | ;; #+RESULTS: 426 | ;; : #| L-double-linkage-rect |# 427 | 428 | ;; And the composition: 429 | 430 | 431 | (define (L-double-linkage l1 l2 m1 m2 m3 U) 432 | (compose (L-double-linkage-rect m1 m2 m3 U) 433 | (F->C (double-linkage->rect l1 l2)))) 434 | 435 | 436 | ;; #+RESULTS: 437 | ;; : #| L-double-linkage |# 438 | 439 | ;; Gravitational potential: 440 | 441 | 442 | (define ((U-gravity g m1 m2 m3) q) 443 | (let* ((y1 (ref q 1)) 444 | (y2 (ref q 3)) 445 | (y3 (ref q 5))) 446 | (* g (+ (* m1 y1) 447 | (* m2 y2) 448 | (* m3 y3))))) 449 | 450 | 451 | ;; #+RESULTS: 452 | ;; : #| U-gravity |# 453 | 454 | 455 | (let ((local (up 't 456 | (up 'theta 'phi 'x_2 'y_2) 457 | (up 'thetadot 'phidot 'xdot_2 'ydot_2))) 458 | (U (U-gravity 'g 'm_1 'm_2 'm_3))) 459 | (->tex-equation 460 | ((L-double-linkage 'l_1 'l_2 'm_1 'm_2 'm_3 U) local))) 461 | 462 | 463 | ;; #+RESULTS[871defa58c4637289b4aa4236e470eceed35fc24]: 464 | ;; \begin{equation} 465 | ;; {{l}_{1}}^{2} {m}_{1} {\dot{\theta}}^{2} + 2 {l}_{1} {m}_{1} \dot{\theta} {\dot{x}}_{2} \cos\left( \theta \right) + 2 {l}_{1} {m}_{1} \dot{\theta} {\dot{y}}_{2} \sin\left( \theta \right) + {{l}_{2}}^{2} {m}_{3} {\dot{\phi}}^{2} + 2 {l}_{2} {m}_{3} \dot{\phi} {\dot{x}}_{2} \cos\left( \phi \right) + 2 {l}_{2} {m}_{3} \dot{\phi} {\dot{y}}_{2} \sin\left( \phi \right) + g {l}_{1} {m}_{1} \cos\left( \theta \right) + g {l}_{2} {m}_{3} \cos\left( \phi \right) - g {m}_{1} {y}_{2} - g {m}_{2} {y}_{2} - g {m}_{3} {y}_{2} + {m}_{1} {{\dot{x}}_{2}}^{2} + {m}_{1} {{\dot{y}}_{2}}^{2} + {m}_{2} {{\dot{x}}_{2}}^{2} + {m}_{2} {{\dot{y}}_{2}}^{2} + {m}_{3} {{\dot{x}}_{2}}^{2} + {m}_{3} {{\dot{y}}_{2}}^{2} 466 | ;; \end{equation} 467 | 468 | ;; Lagrange equations of motion: 469 | 470 | 471 | (let* ((U (U-gravity 'g 'm_1 'm_2 'm_3)) 472 | (L (L-double-linkage 'l_1 'l_2 'm_1 'm_2 'm_3 U)) 473 | (theta (literal-function 'theta)) 474 | (phi (literal-function 'phi)) 475 | (x2 (literal-function 'x_2)) 476 | (y2 (literal-function 'y_2))) 477 | (->tex-equation 478 | (((Lagrange-equations L) (up theta phi x2 y2)) 479 | 't))) 480 | 481 | 482 | ;; #+RESULTS[891b221c072e1a0a84d8a553f44953d7e1708fec]: 483 | ;; \begin{equation} 484 | ;; \begin{bmatrix} \displaystyle{ g {l}_{1} {m}_{1} \sin\left( \theta\left( t \right) \right) + 2 {{l}_{1}}^{2} {m}_{1} {D}^{2}\theta\left( t \right) + 2 {l}_{1} {m}_{1} \sin\left( \theta\left( t \right) \right) {D}^{2}{y}_{2}\left( t \right) + 2 {l}_{1} {m}_{1} \cos\left( \theta\left( t \right) \right) {D}^{2}{x}_{2}\left( t \right)} \cr \cr \displaystyle{ g {l}_{2} {m}_{3} \sin\left( \phi\left( t \right) \right) + 2 {{l}_{2}}^{2} {m}_{3} {D}^{2}\phi\left( t \right) + 2 {l}_{2} {m}_{3} \sin\left( \phi\left( t \right) \right) {D}^{2}{y}_{2}\left( t \right) + 2 {l}_{2} {m}_{3} \cos\left( \phi\left( t \right) \right) {D}^{2}{x}_{2}\left( t \right)} \cr \cr \displaystyle{ - 2 {l}_{1} {m}_{1} \sin\left( \theta\left( t \right) \right) {\left( D\theta\left( t \right) \right)}^{2} - 2 {l}_{2} {m}_{3} \sin\left( \phi\left( t \right) \right) {\left( D\phi\left( t \right) \right)}^{2} + 2 {l}_{1} {m}_{1} {D}^{2}\theta\left( t \right) \cos\left( \theta\left( t \right) \right) + 2 {l}_{2} {m}_{3} {D}^{2}\phi\left( t \right) \cos\left( \phi\left( t \right) \right) + 2 {m}_{1} {D}^{2}{x}_{2}\left( t \right) + 2 {m}_{2} {D}^{2}{x}_{2}\left( t \right) + 2 {m}_{3} {D}^{2}{x}_{2}\left( t \right)} \cr \cr \displaystyle{ 2 {l}_{1} {m}_{1} {\left( D\theta\left( t \right) \right)}^{2} \cos\left( \theta\left( t \right) \right) + 2 {l}_{2} {m}_{3} {\left( D\phi\left( t \right) \right)}^{2} \cos\left( \phi\left( t \right) \right) + 2 {l}_{1} {m}_{1} {D}^{2}\theta\left( t \right) \sin\left( \theta\left( t \right) \right) + 2 {l}_{2} {m}_{3} {D}^{2}\phi\left( t \right) \sin\left( \phi\left( t \right) \right) + g {m}_{1} + g {m}_{2} + g {m}_{3} + 2 {m}_{1} {D}^{2}{y}_{2}\left( t \right) + 2 {m}_{2} {D}^{2}{y}_{2}\left( t \right) + 2 {m}_{3} {D}^{2}{y}_{2}\left( t \right)}\end{bmatrix} 485 | ;; \end{equation} 486 | 487 | ;; Kill some clear factors: 488 | 489 | 490 | (let* ((U (U-gravity 'g 'm_1 'm_2 'm_3)) 491 | (L (L-double-linkage 'l_1 'l_2 'm_1 'm_2 'm_3 U)) 492 | (theta (literal-function 'theta)) 493 | (phi (literal-function 'phi)) 494 | (x2 (literal-function 'x_2)) 495 | (y2 (literal-function 'y_2)) 496 | (eqs (((Lagrange-equations L) (up theta phi x2 y2)) 497 | 't))) 498 | (->tex-equation 499 | (up (/ (ref eqs 0) 'l_1 'm_1) 500 | (/ (ref eqs 1) 'l_2 'm_3) 501 | (/ (ref eqs 2) 2) 502 | (ref eqs 3)))) 503 | ;; Exercise 1.20: Sliding pendulum 504 | ;; :PROPERTIES: 505 | ;; :header-args+: :tangle ch1/ex1-16.scm :comments org 506 | ;; :END: 507 | 508 | 509 | (load "ch1/utils.scm") 510 | 511 | 512 | ;; #+RESULTS: 513 | ;; : ;Loading "ch1/utils.scm"... 514 | ;; : ; Loading "ch1/exdisplay.scm"... done 515 | ;; : ;... done 516 | ;; : #| check-f |# 517 | 518 | ;; #+begin_quote 519 | ;; Consider a pendulum of length $l$ attached to a support that is free to move 520 | ;; horizontally, as shown in figure 1.4. Let the mass of the support be $m1$ and 521 | ;; the mass of the pendulum bob be $m2$. Formulate a Lagrangian and derive 522 | ;; Lagrange's equations for this system. 523 | ;; #+end_quote 524 | 525 | ;; This is interesting, and totally not-obvious how to represent with Newtonian 526 | ;; mechanics. Here it is pretty simple. The setup: 527 | 528 | ;; #+DOWNLOADED: https://tgvaughan.github.io/sicm/images/Art_P147.jpg @ 2020-06-29 05:39:33 529 | ;; #+attr_org: :width 400px 530 | ;; #+attr_html: :width 80% :align center 531 | ;; #+attr_latex: :width 8cm 532 | ;; [[file:images/Lagrangian_Mechanics/2020-06-29_05-39-33_Art_P147.jpg]] 533 | 534 | ;; We can use 2 coordinates: 535 | 536 | ;; 1. the horizontal position of the cart 537 | ;; 2. the angle $\theta$ of the bob. 538 | 539 | ;; Here's the conversion to rectangular: 540 | 541 | ;; \begin{equation} 542 | ;; \begin{aligned} 543 | ;; x_1(t) & = x_1(t) \cr 544 | ;; y_1(t) & = l \cr 545 | ;; x_2(t) & = x_1(t) + l \sin \theta \cr 546 | ;; y_2(t) & = l(1 - \cos \theta) 547 | ;; \end{aligned} 548 | ;; \end{equation} 549 | 550 | ;; Draw these on the picture to make it clearer. 551 | 552 | ;; Write the coordinate transformation in scheme. 553 | 554 | 555 | (define ((sliding-pend->rect l) local) 556 | (let* ((q (coordinate local)) 557 | (x1 (ref q 0)) 558 | (theta (ref q 1))) 559 | (up x1 560 | l 561 | (+ x1 (* l (sin theta))) 562 | (* l (- 1 (cos theta)))))) 563 | 564 | 565 | ;; #+RESULTS: 566 | ;; : #| sliding-pend->rect |# 567 | 568 | ;; Next, the Lagrangian given rectangular coordinates, assuming no constraints: 569 | 570 | 571 | (define ((L-sliding-pend-rect m1 m2 U) local) 572 | (let* ((v (velocity local)) 573 | (vx1 (ref v 0)) 574 | (vy1 (ref v 1)) 575 | (vx2 (ref v 2)) 576 | (vy2 (ref v 3))) 577 | (- (+ (* m1 (+ (square vx1) 578 | (square vy1))) 579 | (* m2 (+ (square vx2) 580 | (square vy2)))) 581 | (U (coordinate local))))) 582 | 583 | 584 | ;; #+RESULTS: 585 | ;; : #| L-sliding-pend-rect |# 586 | 587 | ;; And the composition: 588 | 589 | 590 | (define (L-sliding-pend l m1 m2 U) 591 | (compose (L-sliding-pend-rect m1 m2 U) 592 | (F->C (sliding-pend->rect l)))) 593 | 594 | 595 | ;; #+RESULTS: 596 | ;; : #| L-sliding-pend |# 597 | 598 | ;; Gravitational potential. I could include the cart here, but since we know it's 599 | ;; fixed gravitationally it wouldn't change the equations of motion. 600 | 601 | 602 | (define ((U-gravity g m2) q) 603 | (let* ((y2 (ref q 3))) 604 | (* m2 g y2))) 605 | 606 | 607 | ;; #+RESULTS: 608 | ;; : #| U-gravity |# 609 | 610 | 611 | (let ((local (up 't 612 | (up 'x_1 'theta) 613 | (up 'xdot_1 'thetadot))) 614 | (U (U-gravity 'g 'm_2))) 615 | (->tex-equation 616 | ((L-sliding-pend 'l 'm_1 'm_2 U) local))) 617 | 618 | 619 | ;; #+RESULTS[a0d77887cb7ea10a807f5718c1383453f676c148]: 620 | ;; \begin{equation} 621 | ;; {l}^{2} {m}_{2} {\dot{\theta}}^{2} + 2 l {m}_{2} \dot{\theta} {\dot{x}}_{1} \cos\left( \theta \right) + g l {m}_{2} \cos\left( \theta \right) - g l {m}_{2} + {m}_{1} {{\dot{x}}_{1}}^{2} + {m}_{2} {{\dot{x}}_{1}}^{2} 622 | ;; \end{equation} 623 | 624 | ;; Lagrange equations of motion: 625 | 626 | 627 | (let* ((U (U-gravity 'g 'm_2)) 628 | (L (L-sliding-pend 'l 'm_1 'm_2 U)) 629 | (x1 (literal-function 'x_1)) 630 | (theta (literal-function 'theta))) 631 | (->tex-equation 632 | (((Lagrange-equations L) (up x1 theta)) 633 | 't))) 634 | 635 | 636 | ;; #+RESULTS[a556eaea3f66fe4d94bd82a34c9f2e786a4187a1]: 637 | ;; \begin{equation} 638 | ;; \begin{bmatrix} \displaystyle{ - 2 l {m}_{2} \sin\left( \theta\left( t \right) \right) {\left( D\theta\left( t \right) \right)}^{2} + 2 l {m}_{2} {D}^{2}\theta\left( t \right) \cos\left( \theta\left( t \right) \right) + 2 {m}_{1} {D}^{2}{x}_{1}\left( t \right) + 2 {m}_{2} {D}^{2}{x}_{1}\left( t \right)} \cr \cr \displaystyle{ g l {m}_{2} \sin\left( \theta\left( t \right) \right) + 2 {l}^{2} {m}_{2} {D}^{2}\theta\left( t \right) + 2 l {m}_{2} {D}^{2}{x}_{1}\left( t \right) \cos\left( \theta\left( t \right) \right)}\end{bmatrix} 639 | ;; \end{equation} 640 | 641 | ;; Cleaner: 642 | 643 | 644 | (let* ((U (U-gravity 'g 'm_2)) 645 | (L (L-sliding-pend 'l 'm_1 'm_2 U)) 646 | (x1 (literal-function 'x_1)) 647 | (theta (literal-function 'theta)) 648 | (eqs (((Lagrange-equations L) (up x1 theta)) 649 | 't))) 650 | (->tex-equation 651 | (up (ref eqs 0) 652 | (/ (ref eqs 1) 'l 'm_2)))) 653 | -------------------------------------------------------------------------------- /ch1/ex1-21.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.21: A dumbbell 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-21.scm :comments org 4 | ;; :END: 5 | 6 | ;; The uneven dumbbell. We've just made it through four exercises which embrace the 7 | ;; idea that you can bake constraints into the coordinate transformation. But why 8 | ;; should we believe that this is allowed? 9 | 10 | ;; This exercise comes after a section called "Why it Works". 11 | 12 | ;; The next exercise tries to do a coordinate change that is really careful about 13 | ;; /not/ changing the dimension of the configuration space, so that we can show 14 | ;; that this move is allowed. Here's the setup: 15 | 16 | ;; #+DOWNLOADED: https://tgvaughan.github.io/sicm/images/Art_P166.jpg @ 2020-06-29 05:40:00 17 | ;; #+attr_org: :width 400px 18 | ;; #+attr_html: :width 80% :align center 19 | ;; #+attr_latex: :width 8cm 20 | ;; [[file:images/Lagrangian_Mechanics/2020-06-29_05-40-00_Art_P166.jpg]] 21 | 22 | 23 | (load "ch1/utils.scm") 24 | ;; Multiple Particle API 25 | 26 | ;; Many exercises have been dealing with multiple particles so far. Let's introduce 27 | ;; some functions that let us pluck the appropriate coordinates out of the local 28 | ;; tuple. 29 | 30 | ;; If we have the velocity and mass of a particle, its kinetic energy is easy to 31 | ;; define: 32 | 33 | 34 | (define (KE-particle m v) 35 | (* 1/2 m (square v))) 36 | 37 | 38 | ;; #+RESULTS: 39 | ;; : #| KE-particle |# 40 | 41 | ;; This next function, =extract-particle=, takes a number of components -- 2 for a 42 | ;; particle with 2 components, 3 for a particle in space, etc -- and returns a 43 | ;; function of =local= and =i=, a particle index. This function can be used to 44 | ;; extract a sub-local-tuple for that particle from a flattened list. 45 | 46 | 47 | (define ((extract-particle pieces) local i) 48 | (let* ((indices (apply up (iota pieces (* i pieces)))) 49 | (extract (lambda (tuple) 50 | (vector-map (lambda (i) 51 | (ref tuple i)) 52 | indices)))) 53 | (up (time local) 54 | (extract (coordinate local)) 55 | (extract (velocity local))))) 56 | ;; Part B: Dumbbell Lagrangian 57 | 58 | ;; #+begin_quote 59 | ;; Write the formal Lagrangian 60 | 61 | ;; \begin{equation} 62 | ;; L(t; x_0, y_0, x_1, y_1, F; \dot{x}_0, \dot{y}_0, \dot{x}_1, \dot{y}_1, \dot{F}) 63 | ;; \end{equation} 64 | 65 | ;; such that Lagrange's equations will yield the Newton's equations you derived in 66 | ;; part *a*. 67 | ;; #+end_quote 68 | 69 | 70 | ;; Here is how we model constraint forces. Each pair of particles has some 71 | ;; constraint potential acting between them: 72 | 73 | ;; #+name: U-constraint 74 | 75 | (define (U-constraint q0 q1 F l) 76 | (* (/ F (* 2 l)) 77 | (- (square (- q1 q0)) 78 | (square l)))) 79 | 80 | 81 | ;; #+RESULTS: 82 | ;; : #| U-constraint |# 83 | 84 | ;; And here's a Lagrangian for two free particles, subject to a constraint 85 | ;; potential $F$ acting between them. 86 | 87 | ;; #+name: L-free-constrained 88 | 89 | (define ((L-free-constrained m0 m1 l) local) 90 | (let* ((extract (extract-particle 2)) 91 | (p0 (extract local 0)) 92 | (q0 (coordinate p0)) 93 | (qdot0 (velocity p0)) 94 | 95 | (p1 (extract local 1)) 96 | (q1 (coordinate p1)) 97 | (qdot1 (velocity p1)) 98 | 99 | (F (ref (coordinate local) 4))) 100 | (- (+ (KE-particle m0 qdot0) 101 | (KE-particle m1 qdot1)) 102 | (U-constraint q0 q1 F l)))) 103 | 104 | 105 | ;; #+RESULTS: 106 | ;; : #| L-free-constrained |# 107 | 108 | ;; Finally, the path. This is rectangular coordinates for each piece, plus $F$ 109 | ;; between them. 110 | 111 | 112 | (define q-rect 113 | (up (literal-function 'x_0) 114 | (literal-function 'y_0) 115 | (literal-function 'x_1) 116 | (literal-function 'y_1) 117 | (literal-function 'F))) 118 | 119 | 120 | ;; #+RESULTS: 121 | ;; : #| q-rect |# 122 | 123 | ;; This shows the lagrangian itself, which answers part b: 124 | 125 | 126 | (let* ((L (L-free-constrained 'm_0 'm_1 'l)) 127 | (f (compose L (Gamma q-rect)))) 128 | (->tex-equation 129 | (f 't))) 130 | 131 | 132 | ;; #+RESULTS[9e535179734061e62fa19be6d57ad8f8846008d9]: 133 | ;; \begin{equation} 134 | ;; {{{{1}\over {2}} l {m}_{0} {\left( D{x}_{0}\left( t \right) \right)}^{2} + {{1}\over {2}} l {m}_{0} {\left( D{y}_{0}\left( t \right) \right)}^{2} + {{1}\over {2}} l {m}_{1} {\left( D{x}_{1}\left( t \right) \right)}^{2} + {{1}\over {2}} l {m}_{1} {\left( D{y}_{1}\left( t \right) \right)}^{2} + {{1}\over {2}} {l}^{2} F\left( t \right) - {{1}\over {2}} F\left( t \right) {\left( {x}_{1}\left( t \right) \right)}^{2} + F\left( t \right) {x}_{1}\left( t \right) {x}_{0}\left( t \right) - {{1}\over {2}} F\left( t \right) {\left( {x}_{0}\left( t \right) \right)}^{2} - {{1}\over {2}} F\left( t \right) {\left( {y}_{1}\left( t \right) \right)}^{2} + F\left( t \right) {y}_{1}\left( t \right) {y}_{0}\left( t \right) - {{1}\over {2}} F\left( t \right) {\left( {y}_{0}\left( t \right) \right)}^{2}}\over {l}} 135 | ;; \end{equation} 136 | 137 | ;; Here are the Lagrange equations, which, if you squint, are like Newton's 138 | ;; equations from part a. 139 | 140 | 141 | (let* ((L (L-free-constrained 'm_0 'm_1 'l)) 142 | (f ((Lagrange-equations L) q-rect))) 143 | (->tex-equation 144 | (f 't))) 145 | ;; Part C: Coordinate Change 146 | 147 | ;; #+begin_quote 148 | ;; Make a change of coordinates to a coordinate system with center of mass 149 | ;; coordinates $x_{CM}$, $y_{CM}$, angle $\theta$, distance between the particles 150 | ;; $c$, and tension force $F$. Write the Lagrangian in these coordinates, and write 151 | ;; the Lagrange equations. 152 | ;; #+end_quote 153 | 154 | ;; This is a coordinate change that is very careful not to reduce the degrees of 155 | ;; freedom. 156 | 157 | ;; First, the coordinate change: 158 | 159 | 160 | (define ((cm-theta->rect m0 m1) local) 161 | (let* ((q (coordinate local)) 162 | (x_cm (ref q 0)) 163 | (y_cm (ref q 1)) 164 | (theta (ref q 2)) 165 | (c (ref q 3)) 166 | (F (ref q 4)) 167 | (total-mass (+ m0 m1)) 168 | (m0-distance (* c (/ m1 total-mass))) 169 | (m1-distance (* c (/ m0 total-mass)))) 170 | (up (- x_cm (* m0-distance (cos theta))) 171 | (- y_cm (* m0-distance (sin theta))) 172 | (+ x_cm (* m1-distance (cos theta))) 173 | (+ y_cm (* m1-distance (sin theta))) 174 | F))) 175 | 176 | 177 | ;; #+RESULTS: 178 | ;; : #| cm-theta->rect |# 179 | 180 | ;; Then the coordinate change applied to the local tuple: 181 | 182 | 183 | (let ((local (up 't 184 | (up 'x_cm 'y_cm 'theta 'c 'F) 185 | (up 'xdot_cm 'ydot_cm 'thetadot 'cdot 'Fdot))) 186 | (C (F->C (cm-theta->rect 'm_0 'm_1)))) 187 | (->tex-equation 188 | (C local))) 189 | 190 | 191 | ;; #+RESULTS[2c67e287b90be4d75ab8c396222d968e56d71383]: 192 | ;; \begin{equation} 193 | ;; \begin{pmatrix} \displaystyle{ t} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ {{ - c {m}_{1} \cos\left( \theta \right) + {m}_{0} {x}_{cm} + {m}_{1} {x}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ {{ - c {m}_{1} \sin\left( \theta \right) + {m}_{0} {y}_{cm} + {m}_{1} {y}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ {{c {m}_{0} \cos\left( \theta \right) + {m}_{0} {x}_{cm} + {m}_{1} {x}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ {{c {m}_{0} \sin\left( \theta \right) + {m}_{0} {y}_{cm} + {m}_{1} {y}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ F}\end{pmatrix}} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ {{c {m}_{1} \dot{\theta} \sin\left( \theta \right) - \dot{c} {m}_{1} \cos\left( \theta \right) + {m}_{0} {\dot{x}}_{cm} + {m}_{1} {\dot{x}}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ {{ - c {m}_{1} \dot{\theta} \cos\left( \theta \right) - \dot{c} {m}_{1} \sin\left( \theta \right) + {m}_{0} {\dot{y}}_{cm} + {m}_{1} {\dot{y}}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ {{ - c {m}_{0} \dot{\theta} \sin\left( \theta \right) + \dot{c} {m}_{0} \cos\left( \theta \right) + {m}_{0} {\dot{x}}_{cm} + {m}_{1} {\dot{x}}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ {{c {m}_{0} \dot{\theta} \cos\left( \theta \right) + \dot{c} {m}_{0} \sin\left( \theta \right) + {m}_{0} {\dot{y}}_{cm} + {m}_{1} {\dot{y}}_{cm}}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ \dot{F}}\end{pmatrix}}\end{pmatrix} 194 | ;; \end{equation} 195 | 196 | ;; Then the Lagrangian in the new coordinates; 197 | 198 | 199 | (define (L-free-constrained* m0 m1 l) 200 | (compose (L-free-constrained m0 m1 l) 201 | (F->C (cm-theta->rect m0 m1)))) 202 | 203 | 204 | ;; #+RESULTS: 205 | ;; : #| L-free-constrained* |# 206 | 207 | ;; This shows the lagrangian itself, after the coordinate transformation: 208 | 209 | 210 | (let* ((q (up (literal-function 'x_cm) 211 | (literal-function 'y_cm) 212 | (literal-function 'theta) 213 | (literal-function 'c) 214 | (literal-function 'F))) 215 | (L (L-free-constrained* 'm_0 'm_1 'l)) 216 | (f (compose L (Gamma q)))) 217 | (->tex-equation 218 | (f 't))) 219 | 220 | 221 | ;; #+RESULTS[d36e7f3c5c5e5a8663d599a055face7a7f6ddb61]: 222 | ;; \begin{equation} 223 | ;; {{l {m}_{0} {m}_{1} {\left( c\left( t \right) \right)}^{2} {\left( D\theta\left( t \right) \right)}^{2} + l {{m}_{0}}^{2} {\left( D{x}_{cm}\left( t \right) \right)}^{2} + l {{m}_{0}}^{2} {\left( D{y}_{cm}\left( t \right) \right)}^{2} + 2 l {m}_{0} {m}_{1} {\left( D{x}_{cm}\left( t \right) \right)}^{2} + 2 l {m}_{0} {m}_{1} {\left( D{y}_{cm}\left( t \right) \right)}^{2} + l {m}_{0} {m}_{1} {\left( Dc\left( t \right) \right)}^{2} + l {{m}_{1}}^{2} {\left( D{x}_{cm}\left( t \right) \right)}^{2} + l {{m}_{1}}^{2} {\left( D{y}_{cm}\left( t \right) \right)}^{2} + {l}^{2} {m}_{0} F\left( t \right) + {l}^{2} {m}_{1} F\left( t \right) - {m}_{0} F\left( t \right) {\left( c\left( t \right) \right)}^{2} - {m}_{1} F\left( t \right) {\left( c\left( t \right) \right)}^{2}}\over {2 l {m}_{0} + 2 l {m}_{1}}} 224 | ;; \end{equation} 225 | 226 | ;; Here are the Lagrange equations: 227 | 228 | 229 | (let* ((q (up (literal-function 'x_cm) 230 | (literal-function 'y_cm) 231 | (literal-function 'theta) 232 | (literal-function 'c) 233 | (literal-function 'F))) 234 | (L (L-free-constrained* 'm_0 'm_1 'l)) 235 | (f ((Lagrange-equations L) q))) 236 | (->tex-equation 237 | (f 't))) 238 | ;; Part D: Substitute $c(t) = l$ 239 | 240 | ;; #+begin_quote 241 | ;; You may deduce from one of these equations that $c(t) = l$. From this fact we 242 | ;; get that $Dc = 0$ and $D^2c = 0$. Substitute these into the Lagrange equations 243 | ;; you just computed to get the equation of motion for $x_{CM}$, $y_{CM}$, 244 | ;; $\theta$. 245 | ;; #+end_quote 246 | 247 | ;; We can substitute the constant value of $c$ using a function that always returns 248 | ;; $l$ to get simplified equations: 249 | 250 | 251 | (let* ((q (up (literal-function 'x_cm) 252 | (literal-function 'y_cm) 253 | (literal-function 'theta) 254 | (lambda (t) 'l) 255 | (literal-function 'F))) 256 | (L (L-free-constrained* 'm_0 'm_1 'l)) 257 | (f ((Lagrange-equations L) q))) 258 | (->tex-equation 259 | (f 't))) 260 | 261 | 262 | ;; #+RESULTS[a51bdf5bbe673771262278b5dca048646c257752]: 263 | ;; \begin{equation} 264 | ;; \begin{bmatrix} \displaystyle{ {m}_{0} {D}^{2}{x}_{cm}\left( t \right) + {m}_{1} {D}^{2}{x}_{cm}\left( t \right)} \cr \cr \displaystyle{ {m}_{0} {D}^{2}{y}_{cm}\left( t \right) + {m}_{1} {D}^{2}{y}_{cm}\left( t \right)} \cr \cr \displaystyle{ {{{l}^{2} {m}_{0} {m}_{1} {D}^{2}\theta\left( t \right)}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ {{ - l {m}_{0} {m}_{1} {\left( D\theta\left( t \right) \right)}^{2} + {m}_{0} F\left( t \right) + {m}_{1} F\left( t \right)}\over {{m}_{0} + {m}_{1}}}} \cr \cr \displaystyle{ 0}\end{bmatrix} 265 | ;; \end{equation} 266 | 267 | ;; This is saying that the acceleration on the center of mass is 0. 268 | 269 | ;; The fourth equation, the equation of motion for the $c(t)$, is interesting here. 270 | ;; We need to pull in the definition of "reduced mass" from exercise 1.11: 271 | 272 | 273 | (define (reduced-mass m1 m2) 274 | (/ (* m1 m2) 275 | (+ m1 m2))) 276 | 277 | 278 | ;; #+RESULTS: 279 | ;; : #| reduced-mass |# 280 | 281 | ;; If we let $m$ be the reduced mass, this equation states: 282 | 283 | ;; \begin{equation} 284 | ;; \label{eq:constraint-force} 285 | ;; F(t) = m l \dot{\theta}^2 286 | ;; \end{equation} 287 | 288 | ;; We can verify this with Scheme by subtracting the two equations: 289 | 290 | 291 | (let* ((F (literal-function 'F)) 292 | (theta (literal-function 'theta)) 293 | (q (up (literal-function 'x_cm) 294 | (literal-function 'y_cm) 295 | theta 296 | (lambda (t) 'l) 297 | F)) 298 | (L (L-free-constrained* 'm_0 'm_1 'l)) 299 | (f ((Lagrange-equations L) q)) 300 | 301 | (m (reduced-mass 'm_0 'm_1))) 302 | (->tex-equation 303 | (- (ref (f 't) 3) 304 | (- (F 't) 305 | (* m 'l (square ((D theta) 't))))))) 306 | ;; Part E: New Lagrangian 307 | 308 | ;; #+begin_quote 309 | ;; Make a Lagrangian ($= T − V$) for the system described with the irredundant 310 | ;; generalized coordinates $x_{CM}$, $y_{CM}$, $\theta$ and compute the Lagrange 311 | ;; equations from this Lagrangian. They should be the same equations as you derived 312 | ;; for the same coordinates in part d. 313 | ;; #+end_quote 314 | 315 | ;; For part e, I wrote this in the notebook - it is effectively identical to the 316 | ;; substitution that is happening on the computer, so I'm going to ignore this. You 317 | ;; just get more cancellations. 318 | 319 | ;; But let's go at it, for fun. 320 | 321 | ;; Here's the Lagrangian of 2 free particles: 322 | 323 | 324 | (define ((L-free2 m0 m1) local) 325 | (let* ((extract (extract-particle 2)) 326 | 327 | (p0 (extract local 0)) 328 | (q0 (coordinate p0)) 329 | (qdot0 (velocity p0)) 330 | 331 | (p1 (extract local 1)) 332 | (q1 (coordinate p1)) 333 | (qdot1 (velocity p1))) 334 | (+ (KE-particle m0 qdot0) 335 | (KE-particle m1 qdot1)))) 336 | 337 | 338 | ;; #+RESULTS: 339 | ;; : #| L-free2 |# 340 | 341 | ;; Then a version of =cm-theta->rect= where we ignore $F$, and sub in a constant 342 | ;; $l$: 343 | 344 | 345 | (define ((cm-theta->rect* m0 m1 l) local) 346 | (let* ((q (coordinate local)) 347 | (x_cm (ref q 0)) 348 | (y_cm (ref q 1)) 349 | (theta (ref q 2)) 350 | (total-mass (+ m0 m1)) 351 | (m0-distance (* l (/ m1 total-mass))) 352 | (m1-distance (* l (/ m0 total-mass)))) 353 | (up (- x_cm (* m0-distance (cos theta))) 354 | (- y_cm (* m0-distance (sin theta))) 355 | (+ x_cm (* m1-distance (cos theta))) 356 | (+ y_cm (* m1-distance (sin theta)))))) 357 | 358 | 359 | ;; #+RESULTS[aee3cbebd833662ba2610e81cef9e42936dcb703]: 360 | ;; #| cm-theta->rect* |# 361 | 362 | ;; The Lagrangian: 363 | 364 | 365 | (define (L-free-constrained2 m0 m1 l) 366 | (compose (L-free2 m0 m1) 367 | (F->C (cm-theta->rect* m0 m1 l)))) 368 | 369 | 370 | ;; #+RESULTS: 371 | ;; : #| L-free-constrained2 |# 372 | 373 | ;; Equations: 374 | 375 | 376 | (let* ((q (up (literal-function 'x_cm) 377 | (literal-function 'y_cm) 378 | (literal-function 'theta) 379 | (lambda (t) 'l) 380 | (literal-function 'F))) 381 | (L1 (L-free-constrained* 'm_0 'm_1 'l)) 382 | (L2 (L-free-constrained2 'm_0 'm_1 'l))) 383 | (->tex-equation 384 | ((- ((Lagrange-equations L1) q) 385 | ((Lagrange-equations L2) q)) 386 | 't))) 387 | -------------------------------------------------------------------------------- /ch1/ex1-22.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.22: Driven pendulum 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-22.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | ;; Part B: Lagrangian 9 | 10 | ;; Now write the Lagrangian for the driven pendulum in rectangular coordinates. The 11 | ;; constraint force takes the same shape as in exercise 1.21: 12 | 13 | 14 | (define (U-constraint q0 q1 F l) 15 | (* (/ F (* 2 l)) 16 | (- (square (- q1 q0)) 17 | (square l)))) 18 | 19 | 20 | ;; #+RESULTS: 21 | ;; : #| U-constraint |# 22 | 23 | ;; The Lagrangian is similar, but only involves a single particle -- the pendulum 24 | ;; bob. We can generate the constraint force by directly building the support's 25 | ;; coordinates, rather than extracting them from the local tuple. 26 | 27 | ;; #+name: L-driven-free 28 | 29 | (define ((L-driven-free m l y U) local) 30 | (let* ((extract (extract-particle 2)) 31 | (bob (extract local 0)) 32 | (q (coordinate bob)) 33 | (qdot (velocity bob)) 34 | (F (ref (coordinate local) 2))) 35 | (- (KE-particle m qdot) 36 | (U q) 37 | (U-constraint (up 0 (y (time local))) 38 | q 39 | F 40 | l)))) 41 | 42 | 43 | ;; Here is the now-familiar equation for a uniform gravitational potential, acting 44 | ;; on the $y$ coordinate: 45 | 46 | ;; #+name: U-gravity 47 | 48 | (define ((U-gravity g m) q) 49 | (let* ((y (ref q 1))) 50 | (* m g y))) 51 | 52 | 53 | ;; #+RESULTS: 54 | ;; : #| U-gravity |# 55 | 56 | ;; Now use the new Lagrangian to generate equations of motion for the three 57 | ;; coordinates $x$, $y$ and $F$: 58 | 59 | 60 | (let* ((q (up (literal-function 'x) 61 | (literal-function 'y) 62 | (literal-function 'F))) 63 | (U (U-gravity 'g 'm)) 64 | (y (literal-function 'y_s)) 65 | (L (L-driven-free 'm 'l y U)) 66 | (f ((Lagrange-equations L) q))) 67 | (->tex-equation 68 | (f 't))) 69 | 70 | 71 | ;; #+RESULTS[a7c6fc40bbcba84c2c0ef9058455e719c4ac8045]: 72 | ;; \begin{equation} 73 | ;; \begin{bmatrix} \displaystyle{ {{l m {D}^{2}x\left( t \right) + F\left( t \right) x\left( t \right)}\over {l}}} \cr \cr \displaystyle{ {{g l m + l m {D}^{2}y\left( t \right) - F\left( t \right) {y}_{s}\left( t \right) + F\left( t \right) y\left( t \right)}\over {l}}} \cr \cr \displaystyle{ {{ - {{1}\over {2}} {l}^{2} + {{1}\over {2}} {\left( {y}_{s}\left( t \right) \right)}^{2} - {y}_{s}\left( t \right) y\left( t \right) + {{1}\over {2}} {\left( y\left( t \right) \right)}^{2} + {{1}\over {2}} {\left( x\left( t \right) \right)}^{2}}\over {l}}}\end{bmatrix} 74 | ;; \end{equation} 75 | 76 | ;; The first two equations of motion match the equations we derived in part A, 77 | ;; using Newton's equations. The third states that 78 | 79 | ;; \begin{equation} 80 | ;; l^2 = x(t)^2 + (y_s(t) - y(t))^&2 81 | ;; \end{equation} 82 | 83 | ;; Verified, with some extra terms to force the simplification: 84 | 85 | 86 | (let* ((q (up (literal-function 'x) 87 | (literal-function 'y) 88 | (literal-function 'F))) 89 | (U (U-gravity 'g 'm)) 90 | (y (literal-function 'y_s)) 91 | (L (L-driven-free 'm 'l y U)) 92 | (f ((Lagrange-equations L) q)) 93 | (eq (ref (f 't) 2))) 94 | (->tex-equation 95 | (- eq 96 | (/ (* 1/2 (- (+ (square ((literal-function 'x) 't)) 97 | (square ((- y (literal-function 'y)) 't))) 98 | (square 'l))) 99 | 'l)))) 100 | ;; Part C: Coordinate Change 101 | 102 | ;; Now we want to verify that we get the same Lagrangian and equations of motion as 103 | ;; in 1.88 from the book. We also want to analyze the constraint forces. To do this 104 | ;; we need to introduce a coordinate change. 105 | 106 | ;; To analyze the constraint forces, we have to do the same trick as in exercise 107 | ;; 1.21 and use a coordinate $c(t) = l$. The new coordinates are $(\theta, c, F)$: 108 | 109 | ;; #+name: driven-polar->rect 110 | 111 | (define ((driven-polar->rect y) local) 112 | (let* ((q (coordinate local)) 113 | (theta (ref q 0)) 114 | (c (ref q 1)) 115 | (F (ref q 2))) 116 | (up (* c (sin theta)) 117 | (- (y (time local)) (* c (cos theta))) 118 | F))) 119 | 120 | 121 | ;; #+RESULTS: 122 | ;; : #| driven-polar->rect |# 123 | 124 | ;; Compose the coordinate change with the rectangular Lagrangian: 125 | 126 | ;; #+name: L-driven-pend 127 | 128 | (define (L-driven-pend m l y U) 129 | (compose (L-driven-free m l y U) 130 | (F->C (driven-polar->rect y)))) 131 | 132 | 133 | ;; #+RESULTS: 134 | ;; : #| L-driven-pend |# 135 | 136 | ;; Examine the Lagrangian itself, after the coordinate transformation. (Notice that 137 | ;; we're using a constant function for $c(t)$ that always returns $l$.) 138 | 139 | 140 | (let* ((q (up (literal-function 'theta) 141 | (lambda (t) 'l) 142 | (literal-function 'F))) 143 | (y (literal-function 'y_s)) 144 | (L (L-driven-pend 'm 'l y (U-gravity 'g 'm))) 145 | (f (compose L (Gamma q)))) 146 | (->tex-equation 147 | (f 't))) 148 | 149 | 150 | ;; #+RESULTS[306c957e09bfd22ebe85e5c6fb9380ff977df1e9]: 151 | ;; \begin{equation} 152 | ;; {{1}\over {2}} {l}^{2} m {\left( D\theta\left( t \right) \right)}^{2} + l m D{y}_{s}\left( t \right) \sin\left( \theta\left( t \right) \right) D\theta\left( t \right) + g l m \cos\left( \theta\left( t \right) \right) - g m {y}_{s}\left( t \right) + {{1}\over {2}} m {\left( D{y}_{s}\left( t \right) \right)}^{2} 153 | ;; \end{equation} 154 | 155 | ;; Looks just like equation 1.88. 156 | 157 | ;; Next, examine the Lagrange equations, using the same substitution of $c(t) = l$: 158 | 159 | 160 | (let* ((q (up (literal-function 'theta) 161 | (lambda (t) 'l) 162 | (literal-function 'F))) 163 | (y (literal-function 'y_s)) 164 | (L (L-driven-pend 'm 'l y (U-gravity 'g 'm))) 165 | (f ((Lagrange-equations L) q))) 166 | (->tex-equation 167 | (f 't))) 168 | -------------------------------------------------------------------------------- /ch1/ex1-23.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.23: Fill in the details 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-23.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-24.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.24: Constraint forces 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-24.scm :comments org 4 | ;; :END: 5 | 6 | ;; This is a special case of a solution we found in exercise 1.22. In that 7 | ;; exercise, we found the constraint forces on a driven pendulum. By setting 8 | ;; $y_s(t) = l$, we can read off the constraint forces for the undriven pendulum. 9 | 10 | 11 | (load "ch1/utils.scm") 12 | 13 | 14 | ;; #+RESULTS: 15 | ;; : ;Loading "ch1/utils.scm"... 16 | ;; : ; Loading "ch1/exdisplay.scm"... done 17 | ;; : ;... done 18 | ;; : #| check-f |# 19 | 20 | ;; Take some definitions that we need: 21 | 22 | 23 | (define ((L-driven-free m l y U) local) 24 | (let* ((extract (extract-particle 2)) 25 | (bob (extract local 0)) 26 | (q (coordinate bob)) 27 | (qdot (velocity bob)) 28 | (F (ref (coordinate local) 2))) 29 | (- (KE-particle m qdot) 30 | (U q) 31 | (U-constraint (up 0 (y (time local))) 32 | q 33 | F 34 | l)))) 35 | 36 | (define ((U-gravity g m) q) 37 | (let* ((y (ref q 1))) 38 | (* m g y))) 39 | 40 | (define ((driven-polar->rect y) local) 41 | (let* ((q (coordinate local)) 42 | (theta (ref q 0)) 43 | (c (ref q 1)) 44 | (F (ref q 2))) 45 | (up (* c (sin theta)) 46 | (- (y (time local)) (* c (cos theta))) 47 | F))) 48 | 49 | (define (L-driven-pend m l y U) 50 | (compose (L-driven-free m l y U) 51 | (F->C (driven-polar->rect y)))) 52 | 53 | 54 | ;; #+RESULTS: 55 | ;; : #| L-driven-free |# 56 | ;; : 57 | ;; : #| U-gravity |# 58 | ;; : 59 | ;; : #| driven-polar->rect |# 60 | ;; : 61 | ;; : #| L-driven-pend |# 62 | 63 | ;; The second equation of motion, for the $c$ coordinate, gives us an equation in 64 | ;; terms of tension. Substitute in a constant pendulum support position by defining 65 | ;; the support position function to be =(lambda (t) 'l)=: 66 | 67 | 68 | (let* ((q (up (literal-function 'theta) 69 | (lambda (t) 'l) 70 | (literal-function 'F))) 71 | (y (lambda (t) 'l)) 72 | (L (L-driven-pend 'm 'l y (U-gravity 'g 'm))) 73 | (f ((Lagrange-equations L) q))) 74 | (->tex-equation 75 | (ref (f 't) 1))) 76 | -------------------------------------------------------------------------------- /ch1/ex1-25.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.25: Foucalt pendulum Lagrangian 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-25.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-26.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.26: Properties of $D_t$ 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-26.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-27.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.27: Lagrange equations for total time derivatives 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-27.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-28.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.28: Total Time Derivatives 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-28.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | ;; part A 9 | 10 | ;; nice, easy to guess. 11 | 12 | 13 | (define ((FA m) local) 14 | (let ((x (coordinate local))) 15 | (* m x))) 16 | 17 | 18 | ;; Show the function of t, and confirm that both methods are equivalent. 19 | 20 | 21 | (check-f (FA 'm) 22 | (literal-function 'x)) 23 | ;; Part B 24 | 25 | ;; NOT a total time derivative. 26 | 27 | ;; Define G directly: 28 | 29 | 30 | (define ((GB m) local) 31 | (let* ((t (time local)) 32 | (v_x (velocity local)) 33 | (GB0 0) 34 | (GB1 (* m (cos t)))) 35 | (+ GB0 (* GB1 v_x)))) 36 | 37 | 38 | ;; And show the full G, for fun: 39 | 40 | 41 | (let ((f (compose (GB 'm) (Gamma (literal-function 'x))))) 42 | (se (f 't))) 43 | 44 | 45 | 46 | ;; It's easier to confirm that this is not a total time derivative by checking the 47 | ;; partials. 48 | 49 | 50 | (define (GB-properties m) 51 | (let ((GB0 (lambda (local) 0)) 52 | (GB1 (lambda (local) 53 | (* m (cos (time local)))))) 54 | (G-properties GB0 GB1 (literal-function 'x)))) 55 | 56 | 57 | ;; It's clear here that the second and third tuple entries aren't equal, so we 58 | ;; don't have a total time derivative. 59 | 60 | 61 | (se (GB-properties 'm)) 62 | ;; Part C 63 | 64 | ;; no problem, we've got a total time derivative on our hands. 65 | 66 | 67 | (define (FC local) 68 | (let ((t (time local)) 69 | (x (coordinate local))) 70 | (* x (cos t)))) 71 | 72 | (check-f FC (literal-function 'x)) 73 | 74 | (define GC-properties 75 | (let ((GC0 (lambda (local) 76 | (* -1 77 | (coordinate local) 78 | (sin (time local))))) 79 | (GC1 (lambda (local) 80 | (cos (time local))))) 81 | (G-properties GC0 GC1 (literal-function 'x)))) 82 | 83 | 84 | ;; Boom, the second and third entries are equal, as we'd expect. 85 | 86 | 87 | (se GC-properties) 88 | ;; Part D 89 | 90 | ;; This is NOT a total time derivative; you can tell by taking the partials 91 | ;; of each side, G0 and G1, as we'll see here. 92 | 93 | 94 | (define GD-properties 95 | (let ((GD0 (lambda (local) 96 | (* (coordinate local) 97 | (sin (time local))))) 98 | (GD1 (lambda (local) 99 | (cos (time local))))) 100 | (G-properties GD0 GD1 (literal-function 'x)))) 101 | 102 | 103 | ;; The partials for each side don't match. 104 | 105 | 106 | (se GD-properties) 107 | ;; Part E 108 | 109 | ;; This is strange to me, because I thought that this thing had to produce a tuple. 110 | 111 | ;; OH, but the secret is that Qdot is also a tuple, so you contract them together. 112 | 113 | ;; Here's the function F that we can use to derive it: 114 | 115 | 116 | (define (FE local) 117 | (let* ((t (time local)) 118 | (q (coordinate local)) 119 | (x (ref q 0)) 120 | (y (ref q 1))) 121 | (* (+ (square x) (square y)) 122 | (cos t)))) 123 | 124 | 125 | ;; Boom, total time derivative! 126 | 127 | 128 | (check-f FE (up (literal-function 'x) 129 | (literal-function 'y))) 130 | 131 | 132 | ;; And let's show that we pass the tests by decomposing this into G0 and G1: 133 | 134 | 135 | (define GE-properties 136 | (let ( 137 | ;; any piece of the function without a velocity multiplied. 138 | (GE0 (lambda (local) 139 | (let* ((t (time local)) 140 | (q (coordinate local)) 141 | (x (ref q 0)) 142 | (y (ref q 1))) 143 | (* -1 144 | (+ (square x) (square y)) 145 | (sin t))))) 146 | 147 | ;; The pieces multiplied by velocities, split into a down tuple of 148 | ;; components, one for each of the coordinate components. 149 | (GE1 (lambda (local) 150 | (let* ((t (time local)) 151 | (q (coordinate local)) 152 | (x (ref q 0)) 153 | (y (ref q 1))) 154 | (down 155 | (* 2 x (cos t)) 156 | (* 2 y (cos t))))))) 157 | (G-properties GE0 GE1 (up (literal-function 'x) 158 | (literal-function 'y))))) 159 | 160 | 161 | ;; BOOM! 162 | 163 | ;; We've recovered F; the partials are equal, and the final matrix is symmetric. 164 | 165 | 166 | (se GE-properties) 167 | ;; Part F 168 | 169 | ;; This one is interesting, since the second partial is a tuple. This is not so 170 | ;; obvious to me, so first let's check the properties: 171 | 172 | 173 | (define GF-properties 174 | (let ( 175 | ;; any piece of the function without a velocity multiplied. 176 | (GF0 (lambda (local) 177 | (let* ((t (time local)) 178 | (q (coordinate local)) 179 | (x (ref q 0)) 180 | (y (ref q 1))) 181 | (* -1 182 | (+ (square x) (square y)) 183 | (sin t))))) 184 | 185 | ;; The pieces multiplied by velocities, split into a down tuple of 186 | ;; components, one for each of the coordinate components. 187 | (GF1 (lambda (local) 188 | (let* ((t (time local)) 189 | (q (coordinate local)) 190 | (x (ref q 0)) 191 | (y (ref q 1))) 192 | (down 193 | (+ (cube y) (* 2 x (cos t))) 194 | (+ x (* 2 y (cos t)))))))) 195 | (G-properties GF0 GF1 (up (literal-function 'x) 196 | (literal-function 'y))))) 197 | 198 | 199 | ;; AND it looks like we DO have a total time derivative, maybe. We certainly pass 200 | ;; the first test here, since the second and third tuple entries are equal. 201 | 202 | ;; BUT we fail the second test; the hessian that we get from ((partial 1) G1) is 203 | ;; not symmetric. 204 | 205 | 206 | (se GF-properties) 207 | -------------------------------------------------------------------------------- /ch1/ex1-29.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.29: Galilean Invariance 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-29.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | 9 | 10 | ;; #+RESULTS: 11 | ;; : ;Loading "ch1/utils.scm"... 12 | ;; : ; Loading "ch1/exdisplay.scm"... done 13 | ;; : ;... done 14 | ;; : #| check-f |# 15 | 16 | ;; I'll do this for a single particle, since it's annoying to get the sum going 17 | ;; for many; and the lagrangian is additive, so no problem. 18 | 19 | 20 | (define (uniform-translate-shift->rect local) 21 | (let* ((t (time local)) 22 | (q (coordinate local)) 23 | (xprime (ref q 0)) 24 | (delta_x (ref q 1)) 25 | (delta_v (ref q 2))) 26 | (+ xprime delta_x (* t delta_v)))) 27 | 28 | (define (L-translate-shift m) 29 | (compose (L-free-particle m) 30 | (F->C uniform-translate-shift->rect))) 31 | 32 | 33 | ;; #+RESULTS: 34 | ;; : #| uniform-translate-shift->rect |# 35 | ;; : 36 | ;; : #| L-translate-shift |# 37 | 38 | ;; First, confirm that if we have a constant, we get what we expected from paper. 39 | 40 | 41 | (let* ((q (up (literal-function 'xprime) 42 | (lambda (t) 'Delta_x) 43 | (lambda (t) 'Delta_v))) 44 | (f (compose (L-translate-shift 'm) (Gamma q)))) 45 | (->tex-equation (f 't))) 46 | 47 | 48 | ;; #+RESULTS[5d2b4de08cfab4779bf7cdab31d518191b40a4d2]: 49 | ;; \[\begin{equation} 50 | ;; {{1}\over {2}} {{\Delta}_{v}}^{2} m + {\Delta}_{v} m D{x}^\prime\left( t \right) + {{1}\over {2}} m {\left( D{x}^\prime\left( t \right) \right)}^{2} 51 | ;; \end{equation}\] 52 | 53 | ;; We can change this a little to see the extra terms; substract off the free 54 | ;; particle lagrangian, to see the extra stuff. 55 | 56 | 57 | (let* ((q (up (literal-function 'xprime) 58 | (lambda (t) 'Delta_x) 59 | (lambda (t) 'Delta_v))) 60 | (L (- (L-translate-shift 'm) 61 | (L-free-particle 'm))) 62 | (f (compose L (Gamma q)))) 63 | (->tex-equation (f 't))) 64 | 65 | 66 | ;; #+RESULTS[c17004e61fec7edb3835203cdc99c562940bee7c]: 67 | ;; \[\begin{equation} 68 | ;; {{1}\over {2}} {{\Delta}_{v}}^{2} m + {\Delta}_{v} m D{x}^\prime\left( t \right) 69 | ;; \end{equation}\] 70 | 71 | ;; Here's the gnarly version with both entries as actual functions. Can this be a 72 | ;; total time derivative? It CANNOT be, because we have a $(D \Delta_v(t))^2$ term 73 | ;; in there, and we know that total time derivatives have to be linear in the 74 | ;; velocities. The function $F$ would have had to have a velocity in it, which is 75 | ;; not allowed. 76 | 77 | 78 | (let* ((q (up (literal-function 'xprime) 79 | (literal-function 'Delta_x) 80 | (literal-function 'Delta_v))) 81 | (L (- (L-translate-shift 'm) 82 | (L-free-particle 'm))) 83 | (f (compose L (Gamma q)))) 84 | (->tex-equation (f 't))) 85 | 86 | 87 | ;; #+RESULTS[ded4f6dec25954c9b7536153e1db8db0315cb399]: 88 | ;; \[ \begin{equation} 89 | ;; {{1}\over {2}} m {t}^{2} {\left( D{\Delta}_{v}\left( t \right) \right)}^{2} + m t D{x}^\prime\left( t \right) D{\Delta}_{v}\left( t \right) + m t D{\Delta}_{v}\left( t \right) {\Delta}_{v}\left( t \right) + m t D{\Delta}_{v}\left( t \right) D{\Delta}_{x}\left( t \right) + m D{x}^\prime\left( t \right) {\Delta}_{v}\left( t \right) + m D{x}^\prime\left( t \right) D{\Delta}_{x}\left( t \right) - {{1}\over {2}} m {\left( D{\Delta}_{v}\left( t \right) \right)}^{2} + {{1}\over {2}} m {\left( {\Delta}_{v}\left( t \right) \right)}^{2} + m {\Delta}_{v}\left( t \right) D{\Delta}_{x}\left( t \right) 90 | ;; \end{equation} \] 91 | 92 | ;; Let's simplify by making the $\Delta_v$ constant and see if there's anything so 93 | ;; obvious about $\Delta_x$. 94 | 95 | ;; We know that we have a total derivative when $\Delta_x$ is constant, and we know 96 | ;; that total time derivatives are linear, so let's substract off the total time 97 | ;; derivative and see what happens: 98 | 99 | 100 | (let* ((q (lambda (dx) 101 | (up (literal-function 'xprime) 102 | dx 103 | (lambda (t) 'Delta_v)))) 104 | (L (- (L-translate-shift 'm) 105 | (L-free-particle 'm))) 106 | (f (lambda (dx) 107 | (compose L (Gamma (q dx)))))) 108 | (->tex-equation 109 | ((- (f (literal-function 'Delta_x)) 110 | (f (lambda (t) 'Delta_x))) 111 | 't))) 112 | -------------------------------------------------------------------------------- /ch1/ex1-3.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.3: Fermat optics 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-3.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | ;; Calculus 9 | 10 | ;; We can also solve this with calculus. Because the beam doesn't change media, its 11 | ;; speed $v$ stays constant, so minimizing the total distance $d$ is equivalent to 12 | ;; minimizing the time $t = {d \over v}$. 13 | 14 | ;; Set $x_1 = 0$ for convenience, and write the total distance the light travels as 15 | ;; a function of $x_p$: 16 | 17 | ;; \begin{equation} 18 | ;; d(x_p) = \sqrt{y_1^2 + x_p^2} + \sqrt{(x_2 - x_p)^2 + y_2^2} 19 | ;; \end{equation} 20 | 21 | ;; For practice, we can also define this function in Scheme. 22 | 23 | 24 | (define ((total-distance x1 y1 x2 y2) xp) 25 | (+ (sqrt (+ (square (+ x1 xp)) 26 | (square y1))) 27 | (sqrt (+ (square (- x2 (+ x1 xp))) 28 | (square y2))))) 29 | 30 | 31 | ;; #+RESULTS: 32 | ;; : #| total-distance |# 33 | 34 | ;; Here's the function again, generated from code, with general $t_1$: 35 | 36 | 37 | (->tex-equation 38 | ((total-distance 'x_1 'y_1 'x_2 'y_2) 'x_p)) 39 | 40 | 41 | ;; #+RESULTS[084acf42d4fe771c97db9cf39e92c75383662d30]: 42 | ;; \begin{equation} 43 | ;; \sqrt{{{x}_{1}}^{2} + 2 {x}_{1} {x}_{p} + {{x}_{p}}^{2} + {{y}_{1}}^{2}} + \sqrt{{{x}_{1}}^{2} - 2 {x}_{1} {x}_{2} + 2 {x}_{1} {x}_{p} + {{x}_{2}}^{2} - 2 {x}_{2} {x}_{p} + {{x}_{p}}^{2} + {{y}_{2}}^{2}} 44 | ;; \end{equation} 45 | 46 | ;; To find the $x_p$ that minimizes the total distance, 47 | 48 | ;; - take the derivative with respect to $x_p$, 49 | ;; - set it equal to 0 and 50 | ;; - solve for $x_p$. 51 | 52 | ;; The derivative will look cleaner in code if we keep the components of the sum 53 | ;; separate and prevent Scheme from "simplifying". Redefine the function to return 54 | ;; a tuple: 55 | 56 | 57 | (define ((total-distance* x1 y1 x2 y2) xp) 58 | (up (sqrt (+ (square (+ x1 xp)) 59 | (square y1))) 60 | (sqrt (+ (square (- x2 (+ x1 xp))) 61 | (square y2))))) 62 | 63 | 64 | ;; #+RESULTS: 65 | ;; : #| total-distance* |# 66 | 67 | ;; Here are the sum components: 68 | 69 | 70 | (->tex-equation 71 | ((total-distance* 0 'y_1 'x_2 'y_2) 'x_p)) 72 | 73 | 74 | ;; #+RESULTS[8080e49ee342b7a2a69c9c84337c37bc473a3c58]: 75 | ;; \begin{equation} 76 | ;; \begin{pmatrix} \displaystyle{ \sqrt{{{x}_{p}}^{2} + {{y}_{1}}^{2}}} \cr \cr \displaystyle{ \sqrt{{{x}_{2}}^{2} - 2 {x}_{2} {x}_{p} + {{x}_{p}}^{2} + {{y}_{2}}^{2}}}\end{pmatrix} 77 | ;; \end{equation} 78 | 79 | ;; Taking a derivative is easy with =scmutils=. Just wrap the function in =D=: 80 | 81 | 82 | (let* ((distance-fn (total-distance* 0 'y_1 'x_2 'y_2)) 83 | (derivative (D distance-fn))) 84 | (->tex-equation 85 | (derivative 'x_p))) 86 | 87 | 88 | ;; #+RESULTS[5bbf36ca4a362ee2f2d2423071a6f818c8c93cab]: 89 | ;; \begin{equation} 90 | ;; \begin{pmatrix} \displaystyle{ {{{x}_{p}}\over {\sqrt{{{x}_{p}}^{2} + {{y}_{1}}^{2}}}}} \cr \cr \displaystyle{ {{ - {x}_{2} + {x}_{p}}\over {\sqrt{{{x}_{2}}^{2} - 2 {x}_{2} {x}_{p} + {{x}_{p}}^{2} + {{y}_{2}}^{2}}}}}\end{pmatrix} 91 | ;; \end{equation} 92 | 93 | ;; The first component is the base of base $x_p$ of the left triangle over the 94 | ;; total length. This ratio is equal to $\cos \theta_1$: 95 | 96 | ;; #+DOWNLOADED: screenshot @ 2020-06-10 10:36:53 97 | ;; #+attr_org: :width 400px 98 | ;; #+attr_html: :width 80% :align center 99 | ;; #+attr_latex: :width 8cm 100 | ;; [[file:images/Lagrangian_Mechanics/2020-06-10_10-36-53_screenshot.png]] 101 | 102 | ;; The bottom component is $-\cos \theta_2$, or ${- (x_2 - x_p)}$ over the length 103 | ;; of the right segment. Add these terms together, set them equal to 0 and 104 | ;; rearrange: 105 | 106 | ;; \begin{equation} 107 | ;; \label{eq:reflect-laws} 108 | ;; \cos \theta_1 = \cos \theta_2 \implies \theta_1 = \theta_2 109 | ;; \end{equation} 110 | 111 | ;; This description in terms of the two incident angles isn't so obvious from the 112 | ;; Scheme code. Still, you can use Scheme to check this result. 113 | 114 | ;; If the two angles are equal, then the left and right triangles are similar, and 115 | ;; the ratio of each base to height is equal: 116 | 117 | ;; \begin{equation} 118 | ;; \label{eq:reflect-ratio} 119 | ;; {x_p \over y_1} = {{x_2 - x_p} \over y_2} 120 | ;; \end{equation} 121 | 122 | ;; Solve for $x_p$ and rearrange: 123 | 124 | ;; \begin{equation} 125 | ;; \label{eq:reflect-ratio2} 126 | ;; x_p = {{y_1 x_2} \over {y_1 + y_2}} 127 | ;; \end{equation} 128 | 129 | ;; Plug this in to the derivative of the original =total-distance= function, and we 130 | ;; find that the derivative equals 0, as expected: 131 | 132 | 133 | (let* ((distance-fn (total-distance 0 'y_1 'x_2 'y_2)) 134 | (derivative (D distance-fn))) 135 | (->tex-equation 136 | (derivative (/ (* 'y_1 'x_2) (+ 'y_1 'y_2))))) 137 | -------------------------------------------------------------------------------- /ch1/ex1-30.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.30: Orbits in a central potential 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-30.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-31.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.31: Foucault pendulum evolution 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-31.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-32.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.32: Time-dependent constraints 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-32.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-33.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.33: Falling off a log 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-33.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-34.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.34: Driven spherical pendulum 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-34.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-35.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.35: Restricted equations of motion 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-35.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-36.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.36: Noether integral 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-36.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-37.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.37: Velocity transformation 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-37.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-38.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.38: Properties of $E$ 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-38.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-39.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.39: Combining Lagrangians 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-39.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-40.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.40: Bead on a triaxial surface 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-40.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-41.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.41: Motion of a tiny golf ball 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-41.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-42.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.42: Augmented Lagrangian 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-42.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-43.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.43: A numerical investigation 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-43.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-44.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.44: Double pendulum behavior 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-44.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | -------------------------------------------------------------------------------- /ch1/ex1-5.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.5: Solution process 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-5.scm :comments org 4 | ;; :END: 5 | 6 | ;; The goal of this The goal of this exercise is to watch the minimization process 7 | ;; that we just discussed proceed, from the initial guess of a straight-line path 8 | ;; to the final, natural looking harmonic oscillation. 9 | 10 | 11 | (load "ch1/utils.scm") 12 | 13 | 14 | ;; #+RESULTS: 15 | ;; : ;Loading "ch1/utils.scm"... 16 | ;; : ; Loading "ch1/exdisplay.scm"... done 17 | ;; : ;... done 18 | ;; : #| check-f |# 19 | 20 | ;; The exercise states: 21 | 22 | ;; #+begin_quote 23 | ;; We can watch the progress of the minimization by modifying the procedure 24 | ;; parametric-path-action to plot the path each time the action is computed. 25 | ;; #+end_quote 26 | 27 | ;; The functions the authors provide in the exercise define a window, and then a 28 | ;; version of =parametric-path-action= that updates the graph as it minimizes: 29 | 30 | 31 | (define win2 (frame 0.0 :pi/2 0.0 1.2)) 32 | 33 | (define ((L-harmonic m k) local) 34 | (let ((q (coordinate local)) 35 | (v (velocity local))) 36 | (- (* 1/2 m (square v)) 37 | (* 1/2 k (square q))))) 38 | 39 | (define ((parametric-path-action Lagrangian t0 q0 t1 q1) 40 | intermediate-qs) 41 | (let ((path (make-path t0 q0 t1 q1 intermediate-qs))) 42 | ;; display path 43 | (graphics-clear win2) 44 | (plot-function win2 path t0 t1 (/ (- t1 t0) 100)) 45 | ;; compute action 46 | (Lagrangian-action Lagrangian path t0 t1))) 47 | 48 | 49 | ;; #+RESULTS: 50 | ;; : #| win2 |# 51 | ;; : 52 | ;; : #| L-harmonic |# 53 | ;; : 54 | ;; : #| parametric-path-action |# 55 | 56 | ;; Run the minimization with the same parameters as in the previous section: 57 | 58 | 59 | (find-path (L-harmonic 1.0 1.0) 0.0 1.0 :pi/2 0.0 2) 60 | -------------------------------------------------------------------------------- /ch1/ex1-6.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.6: Minimizing action 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-6.scm :comments org 4 | ;; :END: 5 | 6 | ;; The authors have lightly demonstrated that plausible-looking paths have 7 | ;; stationary action between fixed endpoints. What happens if we overconstrain the 8 | ;; problem? 9 | 10 | ;; The exercise asks: 11 | 12 | ;; #+begin_quote 13 | ;; Suppose we try to obtain a path by minimizing an action for an impossible 14 | ;; problem. For example, suppose we have a free particle and we impose endpoint 15 | ;; conditions on the velocities as well as the positions that are inconsistent with 16 | ;; the particle being free. Does the formalism protect itself from such an 17 | ;; unpleasant attack? You may find it illuminating to program it and see what 18 | ;; happens. 19 | ;; #+end_quote 20 | 21 | 22 | (load "ch1/utils.scm") 23 | ;; Implementation 24 | 25 | ;; Here's the implementation of the modification described earlier: 26 | 27 | 28 | (define (((parametric-path-action* win) 29 | Lagrangian t0 q0 offset0 t1 q1 offset1) 30 | intermediate-qs) 31 | ;; See the two new points? 32 | (let ((intermediate-qs* (append (list (+ q0 offset0)) 33 | intermediate-qs 34 | (list (+ q1 offset1))))) 35 | (let ((path (make-path t0 q0 t1 q1 intermediate-qs*))) 36 | ;; display path 37 | (graphics-clear win) 38 | (plot-function win path t0 t1 (/ (- t1 t0) 100)) 39 | ;; compute action 40 | (Lagrangian-action Lagrangian path t0 t1)))) 41 | 42 | 43 | ;; #+RESULTS: 44 | ;; : #| parametric-path-action* |# 45 | 46 | ;; You might try a similar trick by modifying the first and last entries of 47 | ;; =intermediate-qs= instead of appending a point, but I suspect that the optimizer 48 | ;; would be able to figure out how to undo your offset. (Try this as an exercise.) 49 | 50 | ;; Next, a new version of =find-path= that passes the offsets through to the new 51 | ;; =parametric-path-action*=: 52 | 53 | 54 | (define ((find-path* win) L t0 q0 offset0 t1 q1 offset1 n) 55 | (let ((initial-qs (linear-interpolants q0 q1 n))) 56 | (let* ((action (parametric-path-action* win)) 57 | (minimizing-qs 58 | (multidimensional-minimize 59 | (action L t0 q0 offset0 t1 q1 offset1) 60 | initial-qs))) 61 | (make-path t0 q0 t1 q1 minimizing-qs)))) 62 | 63 | 64 | ;; #+RESULTS: 65 | ;; : #| find-path* |# 66 | 67 | ;; And finally, a function that can execute runs of our formalism-killing 68 | ;; experiment. 69 | 70 | 71 | (define (one-six offset0 offset1 n) 72 | (let* ((tmax 10) 73 | (win (frame -1 (+ tmax 1) -0.2 (+ 1.2 offset0 offset1))) 74 | (find (find-path* win)) 75 | (L (L-free-particle 3.0)) 76 | (path (find L 77 | 0. 1. offset0 78 | tmax 0. offset1 79 | n))) 80 | (Lagrangian-action L path 0 tmax))) 81 | ;; Execution 82 | 83 | ;; Let's run the code with 0 offsets and 3 interpolation points. Note that this 84 | ;; should /still/ distort the path, since we now have two fixed points at the start 85 | ;; and end. This is effectively imposing a 0 velocity constraint at the beginning 86 | ;; and end. 87 | 88 | ;; Here's the code, and its output: 89 | 90 | 91 | (one-six 0 0 3) 92 | 93 | 94 | ;; #+DOWNLOADED: file:///Users/samritchie/Desktop/ex1_6_nooffset.gif @ 2020-06-10 15:10:46 95 | ;; #+attr_org: :width 400px 96 | ;; #+attr_html: :width 80% :align center 97 | ;; #+attr_latex: :width 8cm 98 | ;; [[file:images/Lagrangian_Mechanics/2020-06-10_15-10-46_ex1_6_nooffset.gif]] 99 | 100 | 101 | ;; The path ends up looking almost sinusoidal, and takes a while to converge. This 102 | ;; is the best polynomial that the system can come up with that matches the 7 103 | ;; points (3 interpolated, 2 offsets, 1 start and 1 end). 104 | 105 | ;; The actual realizable path should be a straight line between the two points. The 106 | ;; initial velocity of 107 | 108 | ;; Here's a small positive velocity imposed at the beginning, and 0 at the end: 109 | 110 | 111 | (one-six 0.2 0 3) 112 | 113 | 114 | ;; #+DOWNLOADED: file:///Users/samritchie/Desktop/ex1_6_02offset.gif @ 2020-06-10 15:10:53 115 | ;; #+attr_org: :width 400px 116 | ;; #+attr_html: :width 80% :align center 117 | ;; #+attr_latex: :width 8cm 118 | ;; [[file:images/Lagrangian_Mechanics/2020-06-10_15-10-53_ex1_6_02offset.gif]] 119 | 120 | ;; The system takes longer to converge. Here's a larger impulse of 0.5 at the 121 | ;; beginning: 122 | 123 | 124 | (one-six 0.5 0 3) 125 | 126 | 127 | ;; #+DOWNLOADED: file:///Users/samritchie/Desktop/ex1_6_05offset.gif @ 2020-06-10 15:11:10 128 | ;; #+attr_org: :width 400px 129 | ;; #+attr_html: :width 80% :align center 130 | ;; #+attr_latex: :width 8cm 131 | ;; [[file:images/Lagrangian_Mechanics/2020-06-10_15-11-10_ex1_6_05offset.gif]] 132 | 133 | 134 | ;; And a moderate negative velocity, just for fun: 135 | 136 | 137 | (one-six -0.5 0 3) 138 | 139 | 140 | ;; #+DOWNLOADED: file:///Users/samritchie/Desktop/ex1_6_neg5offset.gif @ 2020-06-10 15:11:27 141 | ;; #+attr_org: :width 400px 142 | ;; #+attr_html: :width 80% :align center 143 | ;; #+attr_latex: :width 8cm 144 | ;; [[file:images/Lagrangian_Mechanics/2020-06-10_15-11-27_ex1_6_neg5offset.gif]] 145 | 146 | 147 | ;; The process __does__ converge, but this is only because we only used 3 148 | ;; intermediate points. If you bump up to 10 points, with this code: 149 | 150 | 151 | (one-six -0.5 0 10) 152 | -------------------------------------------------------------------------------- /ch1/ex1-8.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 1.8: Implementation of $\delta$ 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/ex1-8.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | ;; Part A: Implement $\delta_\eta$ 9 | 10 | ;; The goal here is to implement $\delta_\eta$ as a procedure. Explicitly: 11 | 12 | ;; #+begin_quote 13 | ;; Suppose we have a procedure =f= that implements a path-dependent function: for 14 | ;; path =q= and time =t= it has the value =((f q) t)=. The procedure delta computes 15 | ;; the variation $\delta_\eta f[q](t)$ as the value of the expression =((((delta 16 | ;; eta) f) q) t)=. Complete the definition of =delta=: 17 | ;; #+end_quote 18 | 19 | ;; After laboriously proving all of the properties above, the actual implementation 20 | ;; feels so simple. 21 | 22 | ;; The key is equation 1.22 in the book: 23 | 24 | ;; \begin{equation} 25 | ;; \label{eq:1-22} 26 | ;; \delta_\eta f[q] = \lim_{\epsilon \to 0} \left( {g(\epsilon) - g(0)} \over \epsilon \right) = Dg(0) 27 | ;; \end{equation} 28 | 29 | ;; Given $g(\epsilon) = f[q + \epsilon \eta]$. Through the magic of automatic 30 | ;; differentiation we can simply write: 31 | 32 | 33 | (define (((delta eta) f) q) 34 | (let ((g (lambda (eps) 35 | (f (+ q (* eps eta)))))) 36 | ((D g) 0))) 37 | ;; Part B: Check $\delta_\eta$'s properties 38 | 39 | ;; Part B's problem description gave us a path-dependent function similar to this 40 | ;; one: 41 | 42 | 43 | (define ((fn sym) q) 44 | (let* ((Local (UP Real (UP* Real) (UP* Real))) 45 | (F (literal-function sym (-> Local Real)))) 46 | (compose F (Gamma q)))) 47 | 48 | 49 | ;; #+RESULTS: 50 | ;; : #| fn |# 51 | 52 | ;; I've modified it slightly to take in a symbol, since we'll need to generate 53 | ;; multiple functions for a few of the rules. 54 | 55 | ;; $fn$ takes a symbol like $F$ and a path function -- a function from $t$ to any 56 | ;; number of coordinates (see the =UP*=?) -- and returns a generic expression for a 57 | ;; path dependent function $F$ that acts via $F \circ \Gamma[q]$. $F$ might be a 58 | ;; Lagrangian, for example. 59 | 60 | ;; The textbook also gives us this function from $t \to (x, y)$ to test out the 61 | ;; properties above. I've added an $\eta$ of the same type signature that we can 62 | ;; use to add variation to the path. 63 | 64 | 65 | (define q (literal-function 'q (-> Real (UP Real Real)))) 66 | (define eta (literal-function 'eta (-> Real (UP Real Real)))) 67 | ;; Variation Product Rule 68 | 69 | ;; Equation \eqref{eq:var-prod} states the product rule for variations. Here it is 70 | ;; in code. I've implemented the right and left sides and subtracted them. As 71 | ;; expected, the result is 0: 72 | 73 | 74 | (let* ((f (fn 'f)) 75 | (g (fn 'g)) 76 | (de (delta eta))) 77 | (let ((left ((de (* f g)) q)) 78 | (right (+ (* (g q) ((de f) q)) 79 | (* (f q) ((de g) q))))) 80 | (->tex-equation 81 | ((- left right) 't)))) 82 | ;; Variation Sum Rule 83 | 84 | ;; The sum rule is similar. Here's the Scheme implementation of equation 85 | ;; \eqref{eq:var-sum}: 86 | 87 | 88 | (let* ((f (fn 'f)) 89 | (g (fn 'g)) 90 | (de (delta eta))) 91 | (let ((left ((de (+ f g)) q)) 92 | (right (+ ((de f) q) 93 | ((de g) q)))) 94 | (->tex-equation 95 | ((- left right) 't)))) 96 | ;; Variation Scalar Multiplication 97 | 98 | ;; Here's equation \eqref{eq:var-scalar} in code. The sides are equal, so their 99 | ;; difference is 0: 100 | 101 | 102 | (let* ((g (fn 'g)) 103 | (de (delta eta))) 104 | (let ((left ((de (* 'c g)) q)) 105 | (right (* 'c ((de g) q)))) 106 | (->tex-equation 107 | ((- left right) 't)))) 108 | ;; Chain Rule for Variations 109 | 110 | ;; To compute the chain rule we'll need a version of =fn= that takes the derivative 111 | ;; of the inner function: 112 | 113 | 114 | (define ((Dfn sym) q) 115 | (let* ((Local (UP Real (UP* Real) (UP* Real))) 116 | (F (literal-function sym (-> Local Real)))) 117 | (compose (D F) (Gamma q)))) 118 | 119 | 120 | ;; For the Scheme implementation, remember that both =fn= and =Dfn= have $\Gamma$ 121 | ;; baked in. The $g$ in equation \eqref{eq:var-chain} is hardcoded to $\Gamma$ in 122 | ;; the function below. 123 | 124 | ;; Here's a check that the two sides of equation \eqref{eq:var-chain} are equal: 125 | 126 | 127 | (let* ((h (fn 'F)) 128 | (dh (Dfn 'F)) 129 | (de (delta eta))) 130 | (let ((left (de h)) 131 | (right (* dh (de Gamma)))) 132 | (->tex-equation 133 | (((- left right) q) 't)))) 134 | ;; $\delta_\eta$ commutes with $D$ 135 | 136 | ;; Our final test. Here's equation \eqref{eq:var-commute} in code, showing that the 137 | ;; derivative commutes with the variation operator: 138 | 139 | 140 | (let* ((f (fn 'f)) 141 | (g (compose D f)) 142 | (de (delta eta))) 143 | (let ((left (D ((de f) q))) 144 | (right ((de g) q))) 145 | (->tex-equation 146 | ((- left right) 't)))) 147 | -------------------------------------------------------------------------------- /ch1/min-action-paths.scm: -------------------------------------------------------------------------------- 1 | ;; Paths of Minimum Action 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/min-action-paths.scm :comments org 4 | ;; :END: 5 | 6 | ;; This section takes us through an example action calculation on a path with an 7 | ;; adjustable "variation", or wiggle. We should see that, if we consider a 8 | ;; "realizable path", then any wiggle we add will increase the calculated action. 9 | 10 | 11 | (load "ch1/utils.scm") 12 | 13 | 14 | ;; #+RESULTS: 15 | ;; : ;Loading "ch1/utils.scm"... 16 | ;; : ; Loading "ch1/exdisplay.scm"... done 17 | ;; : ;... done 18 | ;; : #| check-f |# 19 | 20 | ;; The only restriction on a variation is that it can't affect the endpoints of the 21 | ;; realizable path. the times and positions of the start and end of the path are 22 | ;; pinned. 23 | 24 | ;; =make-eta= takes some path $\nu$ and returns a function that wiggles in some 25 | ;; similar way to $\nu$, but equals 0 at $t_1$ and $t_2$: 26 | 27 | 28 | (define ((make-eta nu t1 t2) t) 29 | (* (- t t1) (- t t2) (nu t))) 30 | 31 | 32 | ;; #+RESULTS: 33 | ;; : #| make-eta |# 34 | 35 | ;; Next, define a function that calculates the Lagrangian for a free particle, like 36 | ;; before, but adds in the path variation $\eta$ multiplied by some small scaling factor 37 | ;; $\epsilon$: 38 | 39 | 40 | (define ((varied-free-particle-action mass q nu t1 t2) epsilon) 41 | (let ((eta (make-eta nu t1 t2))) 42 | (Lagrangian-action (L-free-particle mass) 43 | (+ q (* epsilon eta)) 44 | t1 45 | t2))) 46 | 47 | 48 | ;; #+RESULTS: 49 | ;; : #| varied-free-particle-action |# 50 | 51 | ;; Consider some variation like $v(t) = (\sin(t), \cos(t), t^2)$. The action of the 52 | ;; path with this small wiggle (processed through =make-eta= to pin its endpoints) 53 | ;; is larger (top entry) than the action of the non-varied path (bottom entry), as 54 | ;; expected: 55 | 56 | 57 | (define (test-path t) 58 | (up (+ (* 4 t) 7) 59 | (+ (* 3 t) 5) 60 | (+ (* 2 t) 1))) 61 | 62 | (let ((action-fn (varied-free-particle-action 3.0 test-path 63 | (up sin cos square) 64 | 0.0 10.0))) 65 | (->tex-equation 66 | (up (action-fn 0.001) 67 | (action-fn 0)))) 68 | 69 | 70 | ;; #+RESULTS[10c4c8e6a40701b7176b4b1b2e9dd30b80185e6f]: 71 | ;; #| test-path |# 72 | 73 | ;; \begin{equation} 74 | ;; \begin{pmatrix} \displaystyle{ 436.2912142857153} \cr \cr \displaystyle{ 435.}\end{pmatrix} 75 | ;; \end{equation} 76 | 77 | ;; What value of $\epsilon$ minimizes the action for the test path? 78 | 79 | ;; We can search over values of $\epsilon$ from $-2.0$ to $1.0$ using the built-in 80 | ;; =minimize= function: 81 | 82 | 83 | (let ((action-fn (varied-free-particle-action 84 | 3.0 test-path 85 | (up sin cos square) 86 | 0.0 10.0))) 87 | (->tex-equation 88 | (car (minimize action-fn -2.0 1.0)))) 89 | ;; Finding trajectories that minimize the action 90 | 91 | ;; Is it possible to use this principle to actually /find/ a path, instead of 92 | ;; simply checking it? 93 | 94 | ;; First we need a function that builds a path. This version generates a path of 95 | ;; individual points, bracketed by the supplied start and end points $(t_0, q_0)$ 96 | ;; and $(t_1, q_1)$. $qs$ is a list of intermediate points. 97 | 98 | 99 | (define (make-path t0 q0 t1 q1 qs) 100 | (let ((n (length qs))) 101 | (let ((ts (linear-interpolants t0 t1 n))) 102 | (Lagrange-interpolation-function 103 | (append (list q0) qs (list q1)) 104 | (append (list t0) ts (list t1)))))) 105 | 106 | 107 | ;; #+RESULTS: 108 | ;; : #| make-path |# 109 | 110 | ;; The next function sort-of-composes =make-path= and =Lagrangian-action= into a 111 | ;; function that takes $L$ and the endpoints, and returns the total action along 112 | ;; the path. 113 | 114 | 115 | (define ((parametric-path-action L t0 q0 t1 q1) qs) 116 | (let ((path (make-path t0 q0 t1 q1 qs))) 117 | (Lagrangian-action L path t0 t1))) 118 | 119 | 120 | ;; #+RESULTS: 121 | ;; : #| parametric-path-action |# 122 | 123 | ;; Finally, =find-path= takes the previous function's arguments, plus a parameter 124 | ;; $n$. $n$ controls how many intermediate points the optimizer will inject and 125 | ;; modify in its attempt to find an action-minimizing path. The more points you 126 | ;; specify, the longer minimization will take, but the more accurate the final path 127 | ;; will be. 128 | 129 | 130 | (define (find-path L t0 q0 t1 q1 n) 131 | (let ((initial-qs (linear-interpolants q0 q1 n))) 132 | (let ((minimizing-qs 133 | (multidimensional-minimize 134 | (parametric-path-action L t0 q0 t1 q1) 135 | initial-qs))) 136 | (make-path t0 q0 t1 q1 minimizing-qs)))) 137 | 138 | 139 | ;; #+RESULTS: 140 | ;; : #| find-path |# 141 | 142 | ;; Let's test it out with a Lagrangian for a one dimensional harmonic oscillator 143 | ;; with spring constant $k$. Here is the Lagrangian, equal to the kinetic energy 144 | ;; minus the potential from the spring: 145 | 146 | ;; #+name: L-harmonic 147 | 148 | (define ((L-harmonic m k) local) 149 | (let ((q (coordinate local)) 150 | (v (velocity local))) 151 | (- (* 1/2 m (square v)) 152 | (* 1/2 k (square q))))) 153 | 154 | 155 | ;; #+RESULTS: 156 | ;; : #| L-harmonic |# 157 | 158 | ;; Now we invoke the procedures we've built, and plot the final, path-minimizing 159 | ;; trajectory. 160 | 161 | 162 | (define harmonic-path 163 | (find-path (L-harmonic 1.0 1.0) 0.0 1.0 :pi/2 0.0 3)) 164 | 165 | (define win2 (frame 0.0 :pi/2 0 1)) 166 | 167 | (plot-function win2 harmonic-path 0 :pi (/ :pi 100)) 168 | -------------------------------------------------------------------------------- /ch1/orbital-motion.scm: -------------------------------------------------------------------------------- 1 | ;; Orbital Motion 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/orbital-motion.scm :comments org 4 | ;; :END: 5 | 6 | ;; Page 31. 7 | 8 | 9 | (load "ch1/utils.scm") 10 | (define ((L-orbital mass mu) local) 11 | (let ((q (coordinate local)) 12 | (qdot (velocity local))) 13 | (+ (* 1/2 mass (square qdot)) 14 | (/ mu (sqrt (square q)))))) 15 | 16 | (define q2 17 | (up (literal-function 'xi) 18 | (literal-function 'eta))) 19 | 20 | 21 | ;; To test: 22 | 23 | 24 | ((compose ((partial 1) (L-orbital 'm 'mu)) (Gamma q2)) 't) 25 | -------------------------------------------------------------------------------- /ch1/scratch.scm: -------------------------------------------------------------------------------- 1 | (define cake 10) 2 | -------------------------------------------------------------------------------- /ch1/sec1-4.scm: -------------------------------------------------------------------------------- 1 | ;; Section 1.4: Computing Actions 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch1/sec1-4.scm :comments org 4 | ;; :END: 5 | 6 | ;; I don't plan on doing this for every section in the book, but section 1.4 is the 7 | ;; first place where we're introduced to Scheme, so I followed along and made a few 8 | ;; notes. 9 | 10 | 11 | (load "ch1/utils.scm") 12 | 13 | 14 | ;; #+RESULTS: 15 | ;; : ;Loading "ch1/utils.scm"... 16 | ;; : ; Loading "ch1/exdisplay.scm"... done 17 | ;; : ;... done 18 | ;; : #| check-f |# 19 | 20 | ;; This is the first demo of how any of this stuff works, starting on page 15. 21 | ;; Here's our first Lagrangian, super simple. 22 | 23 | ;; #+name: L-free-particle 24 | 25 | (define ((L-free-particle mass) local) 26 | (let ((v (velocity local))) 27 | (* 1/2 mass (dot-product v v)))) 28 | 29 | 30 | ;; #+RESULTS: L-free-particle 31 | ;; : #| L-free-particle |# 32 | 33 | ;; =L-free-particle= is a function that takes some =mass= and returns a /new/ 34 | ;; function. The new function takes an instance of a "local tuple" and returns the 35 | ;; value of the "Lagrangian". This is the function that you query at every point 36 | ;; along some evolving path in configuration space. For realizable physical paths, 37 | ;; the integral of this function should by minimized, or stationary. 38 | 39 | ;; Why? That's what we're trying to develop here. 40 | 41 | ;; Suppose we let $q$ denote a coordinate path function that maps time to position 42 | ;; components: 43 | 44 | 45 | (define q 46 | (up (literal-function 'x) 47 | (literal-function 'y) 48 | (literal-function 'z))) 49 | 50 | 51 | ;; #+RESULTS: 52 | ;; : #| q |# 53 | 54 | ;; $\Gamma$ is a function that takes a coordinate path and returns a function of 55 | ;; time that gives the local tuple. 56 | 57 | ;; The value $\Gamma$ returns is called the "local tuple": 58 | 59 | 60 | (->tex-equation 61 | ((Gamma q) 't)) 62 | 63 | 64 | ;; #+RESULTS[1f4aaac455bf48bd20965b4268009969bd7fd58e]: 65 | ;; \begin{equation} 66 | ;; \begin{pmatrix} \displaystyle{ t} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ x\left( t \right)} \cr \cr \displaystyle{ y\left( t \right)} \cr \cr \displaystyle{ z\left( t \right)}\end{pmatrix}} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ Dx\left( t \right)} \cr \cr \displaystyle{ Dy\left( t \right)} \cr \cr \displaystyle{ Dz\left( t \right)}\end{pmatrix}}\end{pmatrix} 67 | ;; \end{equation} 68 | 69 | ;; This is just $(t, q(t), (Dq)(t), ....)$ Where $D$ is the derivative. (Preview: 70 | ;; can a component of the coordinate path depend on the others? YES, and that would 71 | ;; impose constraints beyond the degrees of freedom you'd guess by just counting 72 | ;; the coordinates.) 73 | 74 | ;; Composing the Langrangian with $\Gamma[q]$ gives you a function that computes the 75 | ;; Lagrangian at some instant: 76 | 77 | 78 | (->tex-equation 79 | ((compose (L-free-particle 'm) (Gamma q)) 't)) 80 | 81 | 82 | ;; #+RESULTS[49b01dd30b3d679e70016f72a5e51c78ecbf6c38]: 83 | ;; \begin{equation} 84 | ;; {{1}\over {2}} m {\left( Dz\left( t \right) \right)}^{2} + {{1}\over {2}} m {\left( Dy\left( t \right) \right)}^{2} + {{1}\over {2}} m {\left( Dx\left( t \right) \right)}^{2} 85 | ;; \end{equation} 86 | 87 | ;; This particular formula is written in terms of $x, y, z$ coordinates, but that 88 | ;; only came from the definition of $q$. As we'll see later, you could write a 89 | ;; coordinate transformation from some other totally different style of coordinates 90 | ;; (called "generalized coordinates") and the Lagrangian would look different, but 91 | ;; return the same value. 92 | 93 | ;; This function calculates the action $S[q](t_1, t_2)$: 94 | 95 | 96 | (define (Lagrangian-action L q t1 t2) 97 | (definite-integral (compose L (Gamma q)) t1 t2)) 98 | 99 | 100 | ;; #+RESULTS: 101 | ;; : #| Lagrangian-action |# 102 | 103 | ;; Here's an example path that a particle might take, moving along a straight line 104 | ;; as a function of $t$. 105 | 106 | ;; #+name: test-path 107 | 108 | (define (test-path t) 109 | (up (+ (* 4 t) 7) 110 | (+ (* 3 t) 5) 111 | (+ (* 2 t) 1))) 112 | 113 | 114 | ;; #+RESULTS: test-path 115 | ;; : #| test-path |# 116 | 117 | ;; Calculate the action for a particle of mass 3, between $t_1 = 0$ and $t_2 = 10$: 118 | 119 | 120 | (Lagrangian-action (L-free-particle 3) test-path 0.0 10.0) 121 | -------------------------------------------------------------------------------- /ch1/utils.scm: -------------------------------------------------------------------------------- 1 | ;; Utilities I want to share between exercises. 2 | 3 | ;; Printing 4 | 5 | (load "ch1/exdisplay.scm") 6 | 7 | ;; string utilities! can't believe I have to write this. 8 | 9 | (define (replace-all haystack needle replacement) 10 | (let ((haystack (string->list haystack)) 11 | (replacement (reverse 12 | (string->list replacement))) 13 | (needle-len (string-length needle))) 14 | (let loop ((haystack haystack) (acc '())) 15 | (cond ((null? haystack) 16 | (list->string (reverse acc))) 17 | 18 | ((string-prefix? needle (list->string haystack)) 19 | (loop (list-tail haystack needle-len) 20 | (append replacement acc))) 21 | 22 | (else 23 | (loop (cdr haystack) (cons (car haystack) acc))))))) 24 | 25 | ;; Generates a properly formatted string of LaTeX. 26 | (define (->tex* expr) 27 | (let* ((tex-string (expression->tex-string 28 | ((prepare-for-printing expr simplify)))) 29 | (len (string-length tex-string))) 30 | (substring tex-string 10 (- len 3)))) 31 | 32 | ;; Prints the string as a LaTeX code block. 33 | (define (->write-tex tex-string) 34 | (write-string 35 | (string-append "\\[ " tex-string " \\]"))) 36 | 37 | ;; Prints the TeX representation of the supplied expression to the screen. 38 | (define (->tex expr) 39 | (->write-tex (->tex* expr))) 40 | 41 | ;; Prints an equation code block containing the expression as LaTeX. 42 | (define (->tex-equation* expr #!optional label) 43 | (string-append 44 | "\\begin{equation}\n" 45 | (->tex* expr) 46 | (if (default-object? label) 47 | "" 48 | (string-append "\n\\label{" label "}")) 49 | "\n\\end{equation}")) 50 | 51 | (define (->tex-equation expr #!optional label) 52 | (write-string (->tex-equation* expr label))) 53 | 54 | ;; Lagrangian helpers 55 | 56 | (define ((L-free-particle mass) local) 57 | (let ((v (velocity local))) 58 | (* 1/2 mass (dot-product v v)))) 59 | 60 | ;; This function lets us change a function that only transforms coordinates into 61 | ;; a function that can transform an entire path of (up t, q, Dq). 62 | ;; 63 | ;; I THINK this overrides an internal definition, so we may want to delete it. 64 | ;; We'll see. 65 | (define ((F->C-limited F) local) 66 | (up (time local) 67 | (F local) 68 | (+ (((partial 0) F) local) 69 | (* (((partial 1) F) local) 70 | (velocity local))))) 71 | 72 | ;; Total time derivatives! 73 | ;; 74 | ;; These came from exercise 1.28. 75 | 76 | ;; Let's make a function that can make a G, so we can confirm that we've got the 77 | ;; right equation at all. 78 | (define (G G0 G1) 79 | (+ G0 (* G1 Qdot))) 80 | 81 | ;; And another here, to show off the properties G is supposed to have, so we can 82 | ;; compare. 83 | (define (G-properties G0 G1 q) 84 | (let ((full-G (G G0 G1)) 85 | (path (lambda (G) 86 | (let ((f (compose G (Gamma q)))) 87 | (f 't))))) 88 | (up (path full-G) 89 | (path ((partial 0) G1)) 90 | (path ((partial 1) G0)) 91 | (path ((partial 1) G1))))) 92 | 93 | ;; Then, some functions to generate a G from the book, given an F. 94 | (define (check-f1 F q) 95 | ((D (compose F (Gamma q))) 't)) 96 | 97 | ;; And an alternative way to calculate the same thing. 98 | (define (check-f2 F q) 99 | (let ((DtF (+ ((partial 0) F) 100 | (* ((partial 1) F) Qdot)))) 101 | ((compose DtF (Gamma q)) 't))) 102 | 103 | (define (check-f F q) 104 | (se (up (check-f1 F q) 105 | (check-f2 F q)))) 106 | -------------------------------------------------------------------------------- /ch9/ex9-1.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 9.1 Chain Rule 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch9/ex9-1.scm :comments org 4 | ;; :END: 5 | 6 | ;; You're supposed to do these by hand, so I'll do that in the textbook. But here, 7 | ;; let's redo them on the machine. 8 | 9 | 10 | (load "ch1/utils.scm") 11 | 12 | ;; Compute $\partial_0 F(x, y)$ and $\partial_1 F(x, y)$ 13 | 14 | ;; First, let's define the functions we need. 15 | 16 | 17 | (define (F x y) 18 | (* (square x) 19 | (cube y))) 20 | 21 | (define (G x y) 22 | (up (F x y) y)) 23 | 24 | (define (H x y) 25 | (F (F x y) y)) 26 | 27 | 28 | 29 | ;; #+RESULTS: 30 | ;; : #| F |# 31 | ;; : 32 | ;; : #| G |# 33 | ;; : 34 | ;; : #| H |# 35 | 36 | ;; You can do this with explicit partials: 37 | 38 | 39 | (let ((f (down ((partial 0) F) ((partial 1) F)))) 40 | (->tex-equation 41 | (f 'x 'y))) 42 | 43 | 44 | 45 | ;; #+RESULTS[b8eaf52d98e5903b52306509dcdc8f8eeb97144c]: 46 | ;; \begin{equation} 47 | ;; \begin{bmatrix} \displaystyle{ 2 x {y}^{3}} \cr \cr \displaystyle{ 3 {x}^{2} {y}^{2}}\end{bmatrix} 48 | ;; \end{equation} 49 | 50 | ;; Or with the $D$ symbol: 51 | 52 | 53 | (->tex-equation 54 | ((D F) 'x 'y)) 55 | 56 | 57 | 58 | ;; #+RESULTS[f3fba605ac97a3ebd30b4a96aca31eed921e2e93]: 59 | ;; \begin{equation} 60 | ;; \begin{bmatrix} \displaystyle{ 2 x {y}^{3}} \cr \cr \displaystyle{ 3 {x}^{2} {y}^{2}}\end{bmatrix} 61 | ;; \end{equation} 62 | 63 | ;; Or, we could show that they're equivalent this way: 64 | 65 | 66 | (let ((f (down ((partial 0) F) ((partial 1) F)))) 67 | (->tex-equation 68 | (- ((D F) 'x 'y) 69 | (f 'x 'y)))) 70 | 71 | ;; Compute $\partial_0 F(F(x, y), y)$ and $\partial_1 F(F(x, y), y)$ 72 | 73 | ;; $H$ is already that composition, so: 74 | 75 | 76 | (->tex-equation 77 | ((D H) 'x 'y)) 78 | 79 | ;; Compute $\partial_0 G(x, y)$ and $\partial_1 G(x, y)$ 80 | 81 | 82 | (->tex-equation 83 | ((D G) 'x 'y)) 84 | 85 | ;; Compute $DF(a, b)$, $DG(3, 5)$ and $DH(3a^2, 5b^3)$ 86 | 87 | 88 | (->tex-equation 89 | (up ((D F) 'a 'b) 90 | ((D G) 3 5) 91 | ((D H) (* 3 (square 'a)) (* 5 (cube 'b))))) 92 | -------------------------------------------------------------------------------- /ch9/ex9-2.scm: -------------------------------------------------------------------------------- 1 | ;; Exercise 9.2: Computing Derivatives 2 | ;; :PROPERTIES: 3 | ;; :header-args+: :tangle ch9/ex9-2.scm :comments org 4 | ;; :END: 5 | 6 | 7 | (load "ch1/utils.scm") 8 | 9 | 10 | 11 | ;; A further exercise is to try defining the functions so that they use explicit 12 | ;; tuples, so you can compose them: 13 | 14 | 15 | (define (F* v) 16 | (let ((x (ref v 0)) 17 | (y (ref v 1))) 18 | (* (square x) (cube y)))) 19 | 20 | (define (G* v) 21 | (let ((x (ref v 0)) 22 | (y (ref v 1))) 23 | (up (F* v) y))) 24 | 25 | (define H* (compose F* G*)) 26 | 27 | 28 | 29 | ;; #+RESULTS: 30 | ;; : #| F* |# 31 | ;; : 32 | ;; : #| G* |# 33 | ;; : 34 | ;; : #| H* |# 35 | 36 | ;; to be really pro, I'd make a function that takes these as arguments and prints a 37 | ;; nice formatted exercise output. Let's do the final exercise, for fun: 38 | 39 | 40 | (->tex-equation 41 | (up ((D F*) (up 'a 'b)) 42 | ((D G*) (up 3 5)) 43 | ((D H*) (up (* 3 (square 'a)) (* 5 (cube 'b)))))) 44 | -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-05-29_10-12-19_AJBpDgU.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-05-29_10-12-19_AJBpDgU.gif -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-05-29_10-14-10_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-05-29_10-14-10_screenshot.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-08_11-47-37_imgs%2Fapp%2Fsritchie%2FVqfQv6wgb-.png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-08_11-47-37_imgs%2Fapp%2Fsritchie%2FVqfQv6wgb-.png.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_10-31-24_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_10-31-24_screenshot.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_10-36-53_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_10-36-53_screenshot.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_12-03-11_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_12-03-11_screenshot.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_14-24-14_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_14-24-14_screenshot.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_15-10-46_ex1_6_nooffset.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_15-10-46_ex1_6_nooffset.gif -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_15-10-53_ex1_6_02offset.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_15-10-53_ex1_6_02offset.gif -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_15-11-10_ex1_6_05offset.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_15-11-10_ex1_6_05offset.gif -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-10_15-11-27_ex1_6_neg5offset.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-10_15-11-27_ex1_6_neg5offset.gif -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-23_14-48-36_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-23_14-48-36_screenshot.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-25_11-03-55_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-25_11-03-55_screenshot.png -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-29_05-39-01_Art_P146.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-29_05-39-01_Art_P146.jpg -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-29_05-39-33_Art_P147.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-29_05-39-33_Art_P147.jpg -------------------------------------------------------------------------------- /images/Lagrangian_Mechanics/2020-06-29_05-40-00_Art_P166.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frogrocketlabs/sicm-scheme-exercises/323300c252641add067f266e23427afd0bb34d8a/images/Lagrangian_Mechanics/2020-06-29_05-40-00_Art_P166.jpg -------------------------------------------------------------------------------- /md/2_rigid_bodies.md: -------------------------------------------------------------------------------- 1 | - [Exercise 2.1](#sec-1) 2 | - [Exercise 2.2](#sec-2) 3 | - [Exercise 2.3](#sec-3) 4 | - [Exercise 2.4](#sec-4) 5 | - [Exercise 2.5](#sec-5) 6 | - [Exercise 2.6](#sec-6) 7 | - [Exercise 2.7](#sec-7) 8 | - [Exercise 2.8](#sec-8) 9 | - [Exercise 2.9](#sec-9) 10 | - [Exercise 2.10](#sec-10) 11 | - [Exercise 2.11](#sec-11) 12 | - [Exercise 2.12](#sec-12) 13 | - [Exercise 2.13](#sec-13) 14 | - [Exercise 2.14](#sec-14) 15 | - [Exercise 2.15](#sec-15) 16 | - [Exercise 2.16](#sec-16) 17 | - [Exercise 2.17](#sec-17) 18 | - [Exercise 2.18](#sec-18) 19 | - [Exercise 2.19](#sec-19) 20 | - [Exercise 2.20](#sec-20) 21 | 22 | # Exercise 2.1 23 | 24 | # Exercise 2.2 25 | 26 | # Exercise 2.3 27 | 28 | # Exercise 2.4 29 | 30 | # Exercise 2.5 31 | 32 | # Exercise 2.6 33 | 34 | # Exercise 2.7 35 | 36 | # Exercise 2.8 37 | 38 | # Exercise 2.9 39 | 40 | # Exercise 2.10 41 | 42 | # Exercise 2.11 43 | 44 | # Exercise 2.12 45 | 46 | # Exercise 2.13 47 | 48 | # Exercise 2.14 49 | 50 | # Exercise 2.15 51 | 52 | # Exercise 2.16 53 | 54 | # Exercise 2.17 55 | 56 | # Exercise 2.18 57 | 58 | # Exercise 2.19 59 | 60 | # Exercise 2.20 61 | -------------------------------------------------------------------------------- /md/3_hamiltonian_mechanics.md: -------------------------------------------------------------------------------- 1 | - [Exercise 3.1](#sec-1) 2 | - [Exercise 3.2](#sec-2) 3 | - [Exercise 3.3](#sec-3) 4 | - [Exercise 3.4](#sec-4) 5 | - [Exercise 3.5](#sec-5) 6 | - [Exercise 3.6](#sec-6) 7 | - [Exercise 3.7](#sec-7) 8 | - [Exercise 3.8](#sec-8) 9 | - [Exercise 3.9](#sec-9) 10 | - [Exercise 3.10](#sec-10) 11 | - [Exercise 3.11](#sec-11) 12 | - [Exercise 3.12](#sec-12) 13 | - [Exercise 3.13](#sec-13) 14 | - [Exercise 3.14](#sec-14) 15 | - [Exercise 3.15](#sec-15) 16 | - [Exercise 3.16](#sec-16) 17 | 18 | # Exercise 3.1 19 | 20 | # Exercise 3.2 21 | 22 | # Exercise 3.3 23 | 24 | # Exercise 3.4 25 | 26 | # Exercise 3.5 27 | 28 | # Exercise 3.6 29 | 30 | # Exercise 3.7 31 | 32 | # Exercise 3.8 33 | 34 | # Exercise 3.9 35 | 36 | # Exercise 3.10 37 | 38 | # Exercise 3.11 39 | 40 | # Exercise 3.12 41 | 42 | # Exercise 3.13 43 | 44 | # Exercise 3.14 45 | 46 | # Exercise 3.15 47 | 48 | # Exercise 3.16 49 | -------------------------------------------------------------------------------- /md/4_phase_space_structure.md: -------------------------------------------------------------------------------- 1 | - [Exercise 4.0](#sec-1) 2 | - [Exercise 4.1](#sec-2) 3 | - [Exercise 4.2](#sec-3) 4 | - [Exercise 4.3](#sec-4) 5 | - [Exercise 4.4](#sec-5) 6 | - [Exercise 4.5](#sec-6) 7 | - [Exercise 4.6](#sec-7) 8 | - [Exercise 4.7](#sec-8) 9 | - [Exercise 4.8](#sec-9) 10 | - [Exercise 4.9](#sec-10) 11 | - [Exercise 4.10](#sec-11) 12 | 13 | # Exercise 4.0 14 | 15 | # Exercise 4.1 16 | 17 | # Exercise 4.2 18 | 19 | # Exercise 4.3 20 | 21 | # Exercise 4.4 22 | 23 | # Exercise 4.5 24 | 25 | # Exercise 4.6 26 | 27 | # Exercise 4.7 28 | 29 | # Exercise 4.8 30 | 31 | # Exercise 4.9 32 | 33 | # Exercise 4.10 34 | -------------------------------------------------------------------------------- /md/5_canonical_transformations.md: -------------------------------------------------------------------------------- 1 | - [Exercise 5.1](#sec-1) 2 | - [Exercise 5.2](#sec-2) 3 | - [Exercise 5.3](#sec-3) 4 | - [Exercise 5.4](#sec-4) 5 | - [Exercise 5.5](#sec-5) 6 | - [Exercise 5.6](#sec-6) 7 | - [Exercise 5.7](#sec-7) 8 | - [Exercise 5.8](#sec-8) 9 | - [Exercise 5.9](#sec-9) 10 | - [Exercise 5.10](#sec-10) 11 | - [Exercise 5.11](#sec-11) 12 | - [Exercise 5.12](#sec-12) 13 | - [Exercise 5.13](#sec-13) 14 | - [Exercise 5.14](#sec-14) 15 | - [Exercise 5.15](#sec-15) 16 | - [Exercise 5.16](#sec-16) 17 | - [Exercise 5.17](#sec-17) 18 | - [Exercise 5.18](#sec-18) 19 | - [Exercise 5.19](#sec-19) 20 | - [Exercise 5.20](#sec-20) 21 | 22 | # Exercise 5.1 23 | 24 | # Exercise 5.2 25 | 26 | # Exercise 5.3 27 | 28 | # Exercise 5.4 29 | 30 | # Exercise 5.5 31 | 32 | # Exercise 5.6 33 | 34 | # Exercise 5.7 35 | 36 | # Exercise 5.8 37 | 38 | # Exercise 5.9 39 | 40 | # Exercise 5.10 41 | 42 | # Exercise 5.11 43 | 44 | # Exercise 5.12 45 | 46 | # Exercise 5.13 47 | 48 | # Exercise 5.14 49 | 50 | # Exercise 5.15 51 | 52 | # Exercise 5.16 53 | 54 | # Exercise 5.17 55 | 56 | # Exercise 5.18 57 | 58 | # Exercise 5.19 59 | 60 | # Exercise 5.20 61 | -------------------------------------------------------------------------------- /md/6_canonical_evolution.md: -------------------------------------------------------------------------------- 1 | - [Exercise 6.1](#sec-1) 2 | - [Exercise 6.2](#sec-2) 3 | - [Exercise 6.3](#sec-3) 4 | - [Exercise 6.4](#sec-4) 5 | - [Exercise 6.5](#sec-5) 6 | - [Exercise 6.6](#sec-6) 7 | - [Exercise 6.7](#sec-7) 8 | - [Exercise 6.8](#sec-8) 9 | - [Exercise 6.9](#sec-9) 10 | - [Exercise 6.10](#sec-10) 11 | - [Exercise 6.11](#sec-11) 12 | - [Exercise 6.12](#sec-12) 13 | 14 | # Exercise 6.1 15 | 16 | # Exercise 6.2 17 | 18 | # Exercise 6.3 19 | 20 | # Exercise 6.4 21 | 22 | # Exercise 6.5 23 | 24 | # Exercise 6.6 25 | 26 | # Exercise 6.7 27 | 28 | # Exercise 6.8 29 | 30 | # Exercise 6.9 31 | 32 | # Exercise 6.10 33 | 34 | # Exercise 6.11 35 | 36 | # Exercise 6.12 37 | -------------------------------------------------------------------------------- /md/7_canonical_perturbation_theory.md: -------------------------------------------------------------------------------- 1 | - [Exercise 7.1](#sec-1) 2 | - [Exercise 7.2](#sec-2) 3 | - [Exercise 7.3](#sec-3) 4 | - [Exercise 7.4](#sec-4) 5 | - [Exercise 7.5](#sec-5) 6 | 7 | # Exercise 7.1 8 | 9 | # Exercise 7.2 10 | 11 | # Exercise 7.3 12 | 13 | # Exercise 7.4 14 | 15 | # Exercise 7.5 16 | -------------------------------------------------------------------------------- /md/8_our_notation.md: -------------------------------------------------------------------------------- 1 | - [Exercise 9.1 Chain Rule](#sec-1) 2 | - [Exercise 9.2: Computing Derivatives](#sec-2) 3 | 4 | Notation Appendix. This is all about getting cozy with scheme, and with the various idiosyncracies of the tuple and functional notation. 5 | 6 | # Exercise 9.1 Chain Rule 7 | 8 | You're supposed to do these by hand, so I'll do that in the textbook. But here, let's redo them on the machine. 9 | 10 | 1. Compute \\(\partial\_0 F(x, y)\\) and \\(\partial\_1 F(x, y)\\) 11 | 12 | First, let's define the functions we need. 13 | 14 | ```scheme 15 | (define (F x y) 16 | (* (square x) 17 | (cube y))) 18 | 19 | (define (G x y) 20 | (up (F x y) y)) 21 | 22 | (define (H x y) 23 | (F (F x y) y)) 24 | ``` 25 | 26 | You can do this with explicit partials: 27 | 28 | ```scheme 29 | (let ((f (down ((partial 0) F) ((partial 1) F)))) 30 | (->tex-equation 31 | (f 'x 'y))) 32 | ``` 33 | 34 | \begin{equation} 35 | \begin{bmatrix} \displaystyle{ 2 x {y}^{3}} \cr \cr \displaystyle{ 3 {x}^{2} {y}^{2}}\end{bmatrix} 36 | \end{equation} 37 | 38 | Or with the \\(D\\) symbol: 39 | 40 | ```scheme 41 | (->tex-equation 42 | ((D F) 'x 'y)) 43 | ``` 44 | 45 | \begin{equation} 46 | \begin{bmatrix} \displaystyle{ 2 x {y}^{3}} \cr \cr \displaystyle{ 3 {x}^{2} {y}^{2}}\end{bmatrix} 47 | \end{equation} 48 | 49 | Or, we could show that they're equivalent this way: 50 | 51 | ```scheme 52 | (let ((f (down ((partial 0) F) ((partial 1) F)))) 53 | (->tex-equation 54 | (- ((D F) 'x 'y) 55 | (f 'x 'y)))) 56 | ``` 57 | 58 | \begin{equation} 59 | \begin{bmatrix} \displaystyle{ 0} \cr \cr \displaystyle{ 0}\end{bmatrix} 60 | \end{equation} 61 | 62 | 2. Compute \\(\partial\_0 F(F(x, y), y)\\) and \\(\partial\_1 F(F(x, y), y)\\) 63 | 64 | \\(H\\) is already that composition, so: 65 | 66 | ```scheme 67 | (->tex-equation 68 | ((D H) 'x 'y)) 69 | ``` 70 | 71 | \begin{equation} 72 | \begin{bmatrix} \displaystyle{ 4 {x}^{3} {y}^{9}} \cr \cr \displaystyle{ 9 {x}^{4} {y}^{8}}\end{bmatrix} 73 | \end{equation} 74 | 75 | 3. Compute \\(\partial\_0 G(x, y)\\) and \\(\partial\_1 G(x, y)\\) 76 | 77 | ```scheme 78 | (->tex-equation 79 | ((D G) 'x 'y)) 80 | ``` 81 | 82 | \begin{equation} 83 | \begin{bmatrix} \displaystyle{ \begin{pmatrix} \displaystyle{ 2 x {y}^{3}} \cr \cr \displaystyle{ 0}\end{pmatrix}} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ 3 {x}^{2} {y}^{2}} \cr \cr \displaystyle{ 1}\end{pmatrix}}\end{bmatrix} 84 | \end{equation} 85 | 86 | 4. Compute \\(DF(a, b)\\), \\(DG(3, 5)\\) and \\(DH(3a^2, 5b^3)\\) 87 | 88 | ```scheme 89 | (->tex-equation 90 | (up ((D F) 'a 'b) 91 | ((D G) 3 5) 92 | ((D H) (* 3 (square 'a)) (* 5 (cube 'b))))) 93 | ``` 94 | 95 | \begin{equation} 96 | \begin{pmatrix} \displaystyle{ \begin{bmatrix} \displaystyle{ 2 a {b}^{3}} \cr \cr \displaystyle{ 3 {a}^{2} {b}^{2}}\end{bmatrix}} \cr \cr \displaystyle{ \begin{bmatrix} \displaystyle{ \begin{pmatrix} \displaystyle{ 750} \cr \cr \displaystyle{ 0}\end{pmatrix}} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ 675} \cr \cr \displaystyle{ 1}\end{pmatrix}}\end{bmatrix}} \cr \cr \displaystyle{ \begin{bmatrix} \displaystyle{ 210937500 {a}^{6} {b}^{27}} \cr \cr \displaystyle{ 284765625 {a}^{8} {b}^{24}}\end{bmatrix}}\end{pmatrix} 97 | \end{equation} 98 | 99 | # Exercise 9.2: Computing Derivatives 100 | 101 | A further exercise is to try defining the functions so that they use explicit tuples, so you can compose them: 102 | 103 | ```scheme 104 | (define (F* v) 105 | (let ((x (ref v 0)) 106 | (y (ref v 1))) 107 | (* (square x) (cube y)))) 108 | 109 | (define (G* v) 110 | (let ((x (ref v 0)) 111 | (y (ref v 1))) 112 | (up (F* v) y))) 113 | 114 | (define H* (compose F* G*)) 115 | ``` 116 | 117 | to be really pro, I'd make a function that takes these as arguments and prints a nice formatted exercise output. Let's do the final exercise, for fun: 118 | 119 | ```scheme 120 | (->tex-equation 121 | (up ((D F*) (up 'a 'b)) 122 | ((D G*) (up 3 5)) 123 | ((D H*) (up (* 3 (square 'a)) (* 5 (cube 'b)))))) 124 | ``` 125 | 126 | \begin{equation} 127 | \begin{pmatrix} \displaystyle{ \begin{bmatrix} \displaystyle{ 2 a {b}^{3}} \cr \cr \displaystyle{ 3 {a}^{2} {b}^{2}}\end{bmatrix}} \cr \cr \displaystyle{ \begin{bmatrix} \displaystyle{ \begin{pmatrix} \displaystyle{ 750} \cr \cr \displaystyle{ 0}\end{pmatrix}} \cr \cr \displaystyle{ \begin{pmatrix} \displaystyle{ 675} \cr \cr \displaystyle{ 1}\end{pmatrix}}\end{bmatrix}} \cr \cr \displaystyle{ \begin{bmatrix} \displaystyle{ 210937500 {a}^{6} {b}^{27}} \cr \cr \displaystyle{ 284765625 {a}^{8} {b}^{24}}\end{bmatrix}}\end{pmatrix} 128 | \end{equation} 129 | -------------------------------------------------------------------------------- /md/9_org-mode_demo.md: -------------------------------------------------------------------------------- 1 | - [Equations](#sec-1) 2 | 3 | This is an example of how we might structure an org-mode file that can export out to Github flavored Markdown, or to a PDF. 4 | 5 | First, let's get some code loaded up and written. Here's a block that converts polar coordinates to rectangular coordinates. 6 | 7 | ```scheme 8 | (define (p->r local) 9 | (let* ((polar-tuple (coordinate local)) 10 | (r (ref polar-tuple 0)) 11 | (phi (ref polar-tuple 1)) 12 | (x (* r (cos phi))) 13 | (y (* r (sin phi)))) 14 | (up x y))) 15 | ``` 16 | 17 | This is some good stuff. 18 | 19 | ```scheme 20 | (load "ch1/utils.scm") 21 | 22 | (define (p->r local) 23 | (let* ((polar-tuple (coordinate local)) 24 | (r (ref polar-tuple 0)) 25 | (phi (ref polar-tuple 1)) 26 | (x (* r (cos phi))) 27 | (y (* r (sin phi)))) 28 | (up x y))) 29 | 30 | (define (spherical->rect local) 31 | (let* ((spherical-tuple (coordinate local)) 32 | (r (ref spherical-tuple 0)) 33 | (theta (ref spherical-tuple 1)) 34 | (phi (ref spherical-tuple 2))) 35 | (up (* r (sin theta) (cos phi)) 36 | (* r (sin theta) (sin phi)) 37 | (* r (cos theta))))) 38 | ``` 39 | 40 | And another, that gets us from spherical to rectangular. 41 | 42 | ```scheme 43 | (define (spherical->rect local) 44 | (let* ((spherical-tuple (coordinate local)) 45 | (r (ref spherical-tuple 0)) 46 | (theta (ref spherical-tuple 1)) 47 | (phi (ref spherical-tuple 2))) 48 | (up (* r (sin theta) (cos phi)) 49 | (* r (sin theta) (sin phi)) 50 | (* r (cos theta))))) 51 | ``` 52 | 53 | ;Loading "ch1/utils.scm"... done 54 | #| "" |# 55 | 56 | This block will generate a LaTeX version of the code I've supplied: 57 | 58 | ```scheme 59 | (->tex-equation 60 | ((+ (literal-function 'c) 61 | (D (literal-function 'z))) 62 | 't) 63 | "eq:masterpiece") 64 | ``` 65 | 66 | \begin{equation} 67 | c\left( t \right) + Dz\left( t \right) 68 | \label{eq:masterpiece} 69 | \end{equation} 70 | 71 | You can even reference these with equation numbers, like Equation \eqref{eq:masterpiece} above. 72 | 73 | ```scheme 74 | (up 1 2 't) 75 | ``` 76 | 77 | #| 78 | (up 1 2 t) 79 | |# 80 | 81 | # Equations 82 | 83 | Here's (a test) of \\(a = bc\\) and more \\[ \alpha\_t \\] equations: 84 | 85 | And again this is a thing: 86 | 87 | \\[ e^{i\pi} = -1 \\] 88 | 89 | \\[ \int\_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} \\] 90 | 91 | \\(\vec{x} \dot (\vec{x} \times \vec{v}) = \vec{v} \dot (\vec{x} \times \vec{v}) = 0\\) 92 | 93 | \\(\vec{x} \cdot (\vec{x} \times \vec{v}) = \vec{v} \dot (\vec{x} \times \vec{b}) = 0\\) 94 | -------------------------------------------------------------------------------- /md/preface.md: -------------------------------------------------------------------------------- 1 | The preface is already intriguing. A tour through the new notation, plus some discussion of why a programming language is the best route in to this stuff. Both of these are extremely powerful ideas, and why I was pulled to this book in the first place. 2 | 3 | The functional notation is: 4 | 5 | \begin{equation} 6 | D (\partial\_2 L \circ \Gamma[q]) - (\partial\_1 L \circ \Gamma[q]) = 0 7 | \end{equation} 8 | 9 | Compare that to the traditional notation: 10 | 11 | \begin{equation} 12 | \frac{d}{dt} \frac{\partial L}{\partial \dot q^i} -\frac{\partial L}{\partial q^i}= 0 13 | \end{equation} 14 | 15 | They have a nice riff on how this is totally ambiguous. \\(\Gamma\\) is not a great way to go. 16 | --------------------------------------------------------------------------------