F = m * a(9.81m/s^2)
x(t) = v(t)
v(t) = a(t) = F/m
small time steps of size h
x(h) = x(0) + hv(0)
v(h) = v(0) + h F/m
from xxxplots import def forward_euler(): h = 0.1 g = 9.81 num_steps = 50 t = numpy.zeros(num_steps + 1) x = numpy.zeros(num_steps + 1) v = numpy.zeros(num_steps + 1) for step in range(num_steps): t[step + 1] = h * (step + 1) x[step + 1] = x[step] + h * v[step] v[step + 1] = v[step] - h * g return t, x, v t, x, v = forward_euler() @show_plot def plot_me(): axes_height = matplotlib.pyplot.subplot(211) matplotlib.pyplot.plot(t, x) axes_velocity = matplotlib.pyplot.subplot(212) matplotlib.pyplot.plot(t, v) axes_height.set_ylabel('Height in m') axes_velocity.set_ylabel('Velocity in m/s') axes_velocity.set_xlabel('Time in s') # Uncomment the line below when running locally. # matplotlib.pyplot.show() plot_me()
import numpy import matplotlib.pyplot def forward_euler(): h = 0.1 g = 9.81 num_steps = 50 t = numpy.zeros(num_steps + 1) x = numpy.zeros(num_steps + 1) v = numpy.zeros(num_steps + 1) for step in range(num_steps): t[step + 1] = h * (step + 1) x[step + 1] = x[step] + h * v[step] v[step + 1] = v[step] - h * g return t, x, v t, x, v = froward_euler()