Skip to content

Commit

Permalink
updates to book and added bas code for 5-1
Browse files Browse the repository at this point in the history
  • Loading branch information
torimcd committed Aug 4, 2020
1 parent ee0cb16 commit 29aeff3
Show file tree
Hide file tree
Showing 37 changed files with 419,226 additions and 90 deletions.
48 changes: 48 additions & 0 deletions GW-BASIC/5-1.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
25000 'Exercise 5-1: Three surfaces of revol**
25010 'Indices (1) simple harmonic motion
25011 '(2) paraboloid
25012 '(3) concave up hemisphere
25020 SCREEN 1: COLOR 0,2: KEY OFF: CLS
25030 DT = .04: G=1: D=1
25040 K=1: K2=K^2: C=K2/2: A=K2/G
25050 MU = 0.2
25055 GOSUB 25500: GOSUB 25600
25060 FOR I=1 TO 3: R(I)=0.5: NEXT
25070 FOR I=1 TO 3: RD(I)=0: NEXT
25090 RDD(1)=MU^2/(R(1)^3)-K^2*R(1)
25091 AAA=(1+(2*C*R(2))^2)
25092 CCC=MU^2/(R(2)^3)
25093 BBB=-2*G*R(2)-R(2)*(2*C*RD(2))^2
25100 RDD(2)=(BBB+CCC)/AAA
25105 AA=-G*R(3)/(SQR(A^2-R(3)^2))
25106 CC=-RD(3)^2*(A^2*R(3)/((A^2-R(3)^2)^2))
25107 DD=1+R(3)^2/(A^2*R(3)^2)
25108 BB=MU^2/(R(3)^3)
25110 RDD(3)=(AA+BB+CC)/DD
25140 FOR I=1 TO 3: RD(I)=RDD(I)*DT+RD(I)
25141 R(I)=RD(I)*DT+R(I): NEXT
25150 FOR I=1 TO 3: PD(I)=MU/(R(I)^2)
25151 P(I)=PD(I)*DT+P(I): NEXT
25160 FOR I=1 TO 3: X(I)=R(I)*COS(P(I))
25161 Y(I)=R(I)*SIN(P(I)): NEXT
25170 FOR I=1 TO 3
25171 PSET (50*X(I)+70+80*(I-1),60-50*Y(I)),I
25172 NEXT
25180 GOTO 25090
25500 FOR I=0 TO 2: CIRCLE(70+80*I,60),30,1
25501 NEXT
25505 LOCATE 23,5
25506 PRINT " plane parabol sphere";
25507 LOCATE 1,6
25508 PRINT "Three surfaces of revolution ";
25510 RETURN
25600 FOR I=-0.7 to 0.7 STEP 0.02:'side view
25610 L(1)=50*I+70+80*0: M(1)=170
25620 L(2)=50*I+70+80*1: M(2)=170-50*C*I^2
25625 IF (A^2-I^2)=<0 THEN GOTO 25700
25630 L(3)=50*I+70+80*2
25631 M(3)=170-50*(A-SQR(A^2-I^2))
25700 PSET(L(1),M(1)),1
25701 PSET(L(2),M(2)),1: PSET (L(3),M(3)),1
25725 NEXT
25750 RETURN
48 changes: 48 additions & 0 deletions GW-BASIC/CORIOLIS.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,54 @@
5140 GOSUB 60000
5150 IF X^2+Y^2 > 10000 THEN CLS: GOTO 5020
5160 GOTO 5050
25000 'Exercise 5-1: Three surfaces of revol**
25010 'Indices (1) simple harmonic motion
25011 '(2) paraboloid
25012 '(3) concave up hemisphere
25020 SCREEN 1: COLOR 0,2: KEY OFF: CLS
25030 DT = .04: G=1: D=1
25040 K=1: K2=K^2: C=K2/2: A=K2/G
25050 MU = 0.2
25055 GOSUB 25500: GOSUB 25600
25060 FOR I=1 TO 3: R(I)=0.5: NEXT
25070 FOR I=1 TO 3: RD(I)=0: NEXT
25090 RDD(1)=MU^2/(R(1)^3)-K^2*R(1)
25091 AAA=(1+(2*C*R(2))^2)
25092 CCC=MU^2/(R(2)^3)
25093 BBB=-2*G*R(2)-R(2)*(2*C*RD(2))^2
25100 RDD(2)=(BBB+CCC)/AAA
25105 AA=-G*R(3)/(SQR(A^2-R(3)^2))
25106 CC=-RD(3)^2*(A^2*R(3)/((A^2-R(3)^2)^2))
25107 DD=1+R(3)^2/(A^2*R(3)^2)
25108 BB=MU^2/(R(3)^3)
25110 RDD(3)=(AA+BB+CC)/DD
25140 FOR I=1 TO 3: RD(I)=RDD(I)*DT+RD(I)
25141 R(I)=RD(I)*DT+R(I): NEXT
25150 FOR I=1 TO 3: PD(I)=MU/(R(I)^2)
25151 P(I)=PD(I)*DT+P(I): NEXT
25160 FOR I=1 TO 3: X(I)=R(I)*COS(P(I))
25161 Y(I)=R(I)*SIN(P(I)): NEXT
25170 FOR I=1 TO 3
25171 PSET (50*X(I)+70+80*(I-1),60-50*Y(I)),I
25172 NEXT
25180 GOTO 25090
25500 FOR I=0 TO 2: CIRCLE(70+80*I,60),30,1
25501 NEXT
25505 LOCATE 23,5
25506 PRINT " plane parabol sphere";
25507 LOCATE 1,6
25508 PRINT "Three surfaces of revolution ";
25510 RETURN
25600 FOR I=-0.7 to 0.7 STEP 0.02:'side view
25610 L(1)=50*I+70+80*0: M(1)=170
25620 L(2)=50*I+70+80*1: M(2)=170-50*C*I^2
25625 IF (A^2-I^2)=<0 THEN GOTO 25700
25630 L(3)=50*I+70+80*2
25631 M(3)=170-50*(A-SQR(A^2-I^2))
25700 PSET(L(1),M(1)),1
25701 PSET(L(2),M(2)),1: PSET (L(3),M(3)),1
25725 NEXT
25750 RETURN
30000 'Exer 7-1; particle on spheroid earth **
30010 SCREEN 1: COLOR 0,2: KEY OFF: CLS
30020 'absolute 1 and 2, relative 3 and 4
Expand Down
Binary file modified docs/coriolis-force-code/_build/.doctrees/7_1.doctree
Binary file not shown.
Binary file modified docs/coriolis-force-code/_build/.doctrees/ch1.doctree
Binary file not shown.
Binary file modified docs/coriolis-force-code/_build/.doctrees/ch7.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified docs/coriolis-force-code/_build/.doctrees/intro.doctree
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions docs/coriolis-force-code/_build/html/_sources/exer1-1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercise 1-1: Particle accelerating under suddenly turned-on force"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Particle accelerating under suddenly turned-on force\n",
"\n",
"\"\"\" \n",
"This program shows the paths of a particle starting at the origin and travelling in a random direction. After 10 timesteps a force with a random \n",
"magnitude turns on and the particle accelerates in the direction of the force. The force magnitude and direction is shown by a yellow arrow.\n",
"\n",
"Code translated from GW-BASIC provided in Exercise 1.1 of Stommel and Moore (1989)\n",
"\n",
"author: Victoria McDonald\n",
"email: [email protected]\n",
"website: https://github.com/torimcd/coriolis-sm\n",
"\n",
"\"\"\"\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.animation import FuncAnimation\n",
"from IPython.display import HTML\n",
"import random\n",
"%matplotlib inline\n",
"\n",
"def rnd():\n",
" ''' Helper function returns a random number between 0 and 1 '''\n",
" rand = random.uniform(0,1)\n",
" return rand\n",
"\n",
"# Create new Figure and an Axes which fills it.\n",
"fig = plt.figure(figsize=(7, 7))\n",
"ax = fig.add_axes([0, 0, 1, 1], frameon=False)\n",
"ax.set_xlim(-100, 100), ax.set_xticks([])\n",
"ax.set_ylim(-100, 100), ax.set_yticks([])\n",
"\n",
"force_scale_factor = 10\n",
"arrow_scale_factor = 10\n",
"trajectory_scale_factor = 10\n",
"\n",
"# Initialize the particles at 0,0 with random velocity\n",
"x = 0\n",
"y = 0\n",
"\n",
"dx = trajectory_scale_factor*(rnd()-0.5)\n",
"dy = trajectory_scale_factor*(rnd()-0.5)\n",
"\n",
"ddx = 0\n",
"ddy = 0\n",
"\n",
"# set the force magnitude\n",
"force_x_direction = force_scale_factor*(rnd()-0.5)\n",
"force_y_direction = force_scale_factor*(rnd()-0.5)\n",
"\n",
"# set arrow parameters\n",
"arrow_x = 1\n",
"arrow_y = -1\n",
"arrow_dx = arrow_scale_factor*force_x_direction\n",
"arrow_dy = arrow_scale_factor*force_y_direction\n",
"\n",
"# Construct the splot to update as the particle moves\n",
"pos, = ax.plot([], [], 'ro', ms=2)\n",
"\n",
"# function to animate the particle\n",
"def update(frame):\n",
" global ddx \n",
" global ddy\n",
" global dx\n",
" global dy\n",
" global x\n",
" global y\n",
"\n",
" # draw the arrow showing the force\n",
" arrow = ax.arrow(arrow_x, arrow_y, arrow_dx, arrow_dy, color='y', width=0.5, shape='full', visible=True)\n",
" \n",
" # for first 10 steps, force is zero and arrow is not visible\n",
" if frame < 10:\n",
" force_x = 0\n",
" force_y = 0\n",
" arrow.remove()\n",
" else:\n",
" # after 10 steps force turns on\n",
" force_x = force_x_direction\n",
" force_y = force_y_direction\n",
"\n",
" # update value of second dervatives\n",
" ddx = force_x\n",
" ddy = force_y\n",
"\n",
" # update value of first derivative\n",
" dx = ddx + dx\n",
" dy = ddy + dy\n",
"\n",
" # update position of x and y\n",
" x = dx + x\n",
" y = dy + y\n",
"\n",
" # set the new position of the particle to x, y\n",
" pos.set_data(x, y)\n",
"\n",
" # plot it again so it persists\n",
" ax.plot(x, y, 'ro', ms=2)\n",
"\n",
" return pos\n",
"\n",
"def init():\n",
" pos.set_data([], [])\n",
" return pos\n",
"\n",
"# Construct the animation, using the update function as the animation director.\n",
"animation = FuncAnimation(fig, update, init_func=init, frames=20, interval=500, repeat=False, blit=False)\n",
"\n",
"# convert to a video to be embedded in web page\n",
"HTML(animation.to_html5_video())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
File renamed without changes.
13 changes: 8 additions & 5 deletions docs/coriolis-force-code/_build/html/_sources/intro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Welcome to your Jupyter Book
============================
Introduction
=============

This is a companion site to the 1989 classic text *An Introduction to the Coriolis Force* by Henry M. Stommel and Dennis W. Moore. All of the code for the exercises in the book originally were written in GW-BASIC. Here, the exercises have been rewritten in Python.

The repository for the code is located at [https://github.com/torimcd/coriolis-sm](https://github.com/torimcd/coriolis-sm), and students are encouraged to fork the repository and play with the code. This site serves as documentation for the programs, and notes where changes have been made in the algorithms and variable names from what appears in the text.

The repository also contains copies of the original programs in GW-BASIC, along with instructions on how to run them in the PC-BASIC emulator, which is available for Windows, Mac OSX, and Linux.

This is a small sample book to give you a feel for how book content is
structured.

Check out the content pages bundled with this sample book to get started.
13 changes: 11 additions & 2 deletions docs/coriolis-force-code/_build/html/ch1.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<script async="async" src="_static/sphinx-thebe.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Chapter 2: Velocity and Acceleration in Plane Polar Coordinates" href="ch2.html" />
<link rel="next" title="Exercise 1-1: Particle accelerating under suddenly turned-on force" href="exer1-1.html" />
<link rel="prev" title="Welcome to your Jupyter Book" href="intro.html" />

<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down Expand Up @@ -85,6 +85,13 @@ <h1 class="site-logo" id="site-title">Coriolis Force Code</h1>
<a class="current reference internal" href="#">
Chapter 1: Real and Apparent Force
</a>
<ul>
<li class="toctree-l2">
<a class="reference internal" href="exer1-1.html">
Exercise 1-1: Particle accelerating under suddenly turned-on force
</a>
</li>
</ul>
</li>
<li class="toctree-l1">
<a class="reference internal" href="ch2.html">
Expand Down Expand Up @@ -218,6 +225,8 @@ <h1 class="site-logo" id="site-title">Coriolis Force Code</h1>
<h1>Chapter 1: Real and Apparent Force<a class="headerlink" href="#chapter-1-real-and-apparent-force" title="Permalink to this headline"></a></h1>
<p>There are many ways to write content in Jupyter Book. This short section
covers a few tips for how to do so.</p>
<div class="toctree-wrapper compound">
</div>
</div>

<script type="text/x-thebe-config">
Expand Down Expand Up @@ -249,7 +258,7 @@ <h1>Chapter 1: Real and Apparent Force<a class="headerlink" href="#chapter-1-rea
<div class='prev-next-bottom'>

<a class='left-prev' id="prev-link" href="intro.html" title="previous page">Welcome to your Jupyter Book</a>
<a class='right-next' id="next-link" href="ch2.html" title="next page">Chapter 2: Velocity and Acceleration in Plane Polar Coordinates</a>
<a class='right-next' id="next-link" href="exer1-1.html" title="next page">Exercise 1-1: Particle accelerating under suddenly turned-on force</a>

</div>
<footer class="footer mt-5 mt-md-0">
Expand Down
4 changes: 2 additions & 2 deletions docs/coriolis-force-code/_build/html/ch2.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Chapter 3: Rotating Coordinate Frames" href="ch3.html" />
<link rel="prev" title="Chapter 1: Real and Apparent Force" href="ch1.html" />
<link rel="prev" title="Exercise 1-1: Particle accelerating under suddenly turned-on force" href="exer1-1.html" />

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="docsearch:language" content="en">
Expand Down Expand Up @@ -248,7 +248,7 @@ <h1>Chapter 2: Velocity and Acceleration in Plane Polar Coordinates<a class="hea

<div class='prev-next-bottom'>

<a class='left-prev' id="prev-link" href="ch1.html" title="previous page">Chapter 1: Real and Apparent Force</a>
<a class='left-prev' id="prev-link" href="exer1-1.html" title="previous page">Exercise 1-1: Particle accelerating under suddenly turned-on force</a>
<a class='right-next' id="next-link" href="ch3.html" title="next page">Chapter 3: Rotating Coordinate Frames</a>

</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/coriolis-force-code/_build/html/ch7.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<script async="async" src="_static/sphinx-thebe.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Exericse 7-1: Particle on a Spheroid Earth" href="8-1.html" />
<link rel="next" title="Exericse 7-1: Particle on a Spheroid Earth" href="exer7-1.html" />
<link rel="prev" title="Chapter 6: Velocity and Acceleration in Spherical Coordinates" href="ch6.html" />

<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down Expand Up @@ -117,7 +117,7 @@ <h1 class="site-logo" id="site-title">Coriolis Force Code</h1>
</a>
<ul>
<li class="toctree-l2">
<a class="reference internal" href="8-1.html">
<a class="reference internal" href="exer7-1.html">
Exericse 7-1: Particle on a Spheroid Earth
</a>
</li>
Expand Down Expand Up @@ -258,7 +258,7 @@ <h1>Chapter 7: Huygen’s Rotating Oblate Earth<a class="headerlink" href="#chap
<div class='prev-next-bottom'>

<a class='left-prev' id="prev-link" href="ch6.html" title="previous page">Chapter 6: Velocity and Acceleration in Spherical Coordinates</a>
<a class='right-next' id="next-link" href="8-1.html" title="next page">Exericse 7-1: Particle on a Spheroid Earth</a>
<a class='right-next' id="next-link" href="exer7-1.html" title="next page">Exericse 7-1: Particle on a Spheroid Earth</a>

</div>
<footer class="footer mt-5 mt-md-0">
Expand Down
4 changes: 2 additions & 2 deletions docs/coriolis-force-code/_build/html/ch8.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Chapter 9: Refining the Eath’s Platform" href="ch9.html" />
<link rel="prev" title="Content with notebooks" href="8-1.html" />
<link rel="prev" title="Exericse 7-1: Particle on a Spheroid Earth" href="exer7-1.html" />

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="docsearch:language" content="en">
Expand Down Expand Up @@ -248,7 +248,7 @@ <h1>Chapter 8: Forced Motion<a class="headerlink" href="#chapter-8-forced-motion

<div class='prev-next-bottom'>

<a class='left-prev' id="prev-link" href="8-1.html" title="previous page">Content with notebooks</a>
<a class='left-prev' id="prev-link" href="exer7-1.html" title="previous page">Exericse 7-1: Particle on a Spheroid Earth</a>
<a class='right-next' id="next-link" href="ch9.html" title="next page">Chapter 9: Refining the Eath’s Platform</a>

</div>
Expand Down
Loading

0 comments on commit 29aeff3

Please sign in to comment.