-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates to book and added bas code for 5-1
- Loading branch information
Showing
37 changed files
with
419,226 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
157
docs/coriolis-force-code/_build/html/_sources/exer1-1.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.