Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
614 views
ubuntu2004
Kernel: Python 3 (system-wide)
# set values of constants v_0 = 5 # initial velocity y_0 = 200 # initial y position g = 9.81 # acceleration due to gravity # calculate y at time t=3 t = 6.385 y = y_0 - 0.5 * g * t ** 2 x = v_0 * t print("t (seconds):", t) print("y (metres):", y) print("x (metres):", x)
t (seconds): 6.385 y (metres): 0.03185637500001803 x (metres): 31.924999999999997
v_0 = 5 # initial velocity y_0 = 200 # initial y position g = 9.81 # acceleration due to gravity t = 6.385 def x_t(t): x = v_0 * t return x def y_t(t): y = y_0 - 0.5 * g * t ** 2 return y print("x_t (metres):", x) print("y_t (metres):", y)
x_t (metres): 31.924999999999997 y_t (metres): 0.03185637500001803
import numpy as np # set values of constants v_0 = 5 # initial velocity y_0 = 200 # initial y position g = 9.81 # acceleration due to gravity # calculate y for integer values of t from 0 to 9 t = np.arange(0, 10) y = y_0 - 0.5 * g * t ** 2 x = v_0 * t print("t (seconds):", t) print("y (metres):", y) print("x (metres):", x) import matplotlib.pyplot as plt plt.figure(figsize=(5,5)) plt.plot(t, y) plt.figure(figsize=(5,5)) plt.plot(t, x) plt.figure(figsize=(5,5)) plt.plot(x, y)
t (seconds): [0 1 2 3 4 5 6 7 8 9] y (metres): [ 200. 195.095 180.38 155.855 121.52 77.375 23.42 -40.345 -113.92 -197.305] x (metres): [ 0 5 10 15 20 25 30 35 40 45]
[<matplotlib.lines.Line2D at 0x7fed36e8bf70>]
Image in a Jupyter notebookImage in a Jupyter notebookImage in a Jupyter notebook
from matplotlib import animation from IPython.display import HTML, display import random filename = "animation.gif" # Number of animation frames equals the length of time array t frames = len(t) interval = 100 def ganimate(frame): plt.cla() plt.scatter(t[frame], y[frame]) plt.xlim(0, 10) plt.ylim(0, 200) fig = plt.figure(figsize=(5, 5)) anim = animation.FuncAnimation(fig, ganimate, frames=frames, interval=interval) anim.save(filename, writer='imagemagick') plt.close() __counter__ = str(random.randint(0,2e9)) display(HTML('<img src="' + filename + '?' + __counter__ + '">'))
from matplotlib import animation from IPython.display import HTML, display import random filename = "animation.gif" # Number of animation frames equals the length of time array t frames = len(x) interval = 100 def ganimate(frame): plt.cla() plt.scatter(x[frame], y[frame]) plt.xlim(0, 40) plt.ylim(0, 300) fig = plt.figure(figsize=(5, 5)) anim = animation.FuncAnimation(fig, ganimate, frames=frames, interval=interval) anim.save(filename, writer='imagemagick') plt.close() __counter__ = str(random.randint(0,2e9)) display(HTML('<img src="' + filename + '?' + __counter__ + '">'))
t = np.arange(0, 365) d = 300000000 p = 365 import numpy as np x = d * np.cos(2 * np.pi * t/p) y = d * np.sin(2 * np.pi * t/p) print("Earth") import matplotlib.pyplot as plt plt.figure(figsize=(5,5)) plt.plot(x, y)
Earth
Image in a Jupyter notebook
t = np.arange(0, 88) d = 70000000 p = 87 import numpy as np x = d * np.cos(2 * np.pi * t/p) y = d * np.sin(2 * np.pi * t/p) print("Mercury") import matplotlib.pyplot as plt plt.figure(figsize=(5,5)) plt.plot(x, y)
Mercury
[<matplotlib.lines.Line2D at 0x7fed36a1d8b0>]
Image in a Jupyter notebook
t = np.arange(0, 225) d = 108000000 p = 224 import numpy as np x = d * np.cos(2 * np.pi * t/p) y = d * np.sin(2 * np.pi * t/p) print("Venus") import matplotlib.pyplot as plt plt.figure(figsize=(5,5)) plt.plot(x, y)
Venus
[<matplotlib.lines.Line2D at 0x7fed366f7ee0>]
Image in a Jupyter notebook