plot v = 4*sin(2*t) against t in [0,10] with 0.01 time increments in python

Here's the Python code to plot the function v(t) = 4*sin(2*t) against t in the time interval from 0 to 10 with 0.01 time increments:

main.py
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0, 10, 0.01)
v = 4*np.sin(2*t)

plt.plot(t, v)
plt.xlabel("Time (s)")
plt.ylabel("v(t)")
plt.title("v(t) = 4*sin(2*t)")
plt.show()
197 chars
12 lines

This code uses NumPy to create a range of values for t from 0 to 10 with 0.01 time increments, and then calculates the corresponding values of v using the formula v(t) = 4*sin(2*t). Finally, it uses Matplotlib to plot v against t and add axis labels and a title to the plot. Running this code produces a graph of the function v(t) over the time interval from 0 to 10.

related categories

gistlibby LogSnag