In [1]:
#Import packages.
import numpy as np
import matplotlib.pylab as plt
%matplotlib notebook
In [2]:
#Set folder to save images in.
import os
#os.chdir('Folder/Address/In/Here')
In [3]:
#Rename the function 'figure' from the 'plt' library (a.k.a the 'matplotlib.pylab' library) to make it more convenient to use.
fig = plt.figure()
#Set up axes.
ax = fig.add_subplot(1, 1, 1)
In [6]:
#Define the parameters in the problem. This way, they are located in one place in the code and can be easily changed to test different values.
k = 2
b = 3
v_0 = 15
C = v_0**2 / (v_0**2 + b**2)
#Pretend to plot the function as a smooth curve by plotting a thousand points close together.
t_f = 10
t = np.linspace(0, t_f, 1000)
#Above creates 1000 points at evenly-spaced locations between 0 and some final time, t_f.
#Define the function.
#Assume x > 0. (An 'opposite' graph of the same shape would appear if a minus sign was added. One can try this.)
x = ( abs(b) / ( b**2 * k ) ) * (np.arccos( np.sqrt(C) * np.exp(-b**2 * k * t) ) - np.arccos( np.sqrt(C) ))
#Plot the function.
ax.plot(t, x, 'b-', label = 'Position')
#Label the plot.
fig.suptitle('Position of Object with Decelerating Force $F = -mk(v^3 + a^2v)$')
ax.set_xlabel('Time, t (seconds)')
ax.set_ylabel('Position, x (meters)')
ax.legend(loc = 'upper right', fancybox = False, shadow = False)
Out[6]:
In [7]:
#Extra, not sure whether to include. Plot the horizontal line the graph approaches.
A = np.arccos(0) - np.arccos(np.sqrt(C))
#Plot a line at x = pi/2bk.
plt.axhline(y = np.pi/(2*b*k), color = 'r', linestyle = '--')
plt.axhline(y = A /(b*k), color = 'r', linestyle = '--')
Out[7]: