Q0.
Use variable "my_name" and "stud_id" to print your name and your student id using "print" function in the following format:
Your Name - Your Student ID
For example:
Ali bin Abu - 2000123456
In [ ]:
In [1]:
%pylab inline
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
Example: Graph the curve $x = \sin{t}$, $y = \cos{t}$, $0 \le t \le \pi$.
Read Scipy Lecture Notes (http://www.scipy-lectures.org/) pg. 45 for creating arrays and pg. 83 for plotting.
In [2]:
# define array from 0 to pi with interval size 0.1
t = np.arange(0, np.pi, 0.1)
#define x and y
x = np.sin(t)
y = np.cos(t)
# plot the graph
plt.plot(x, y)
plt.show()
Q1. Graph the curve $x= 26 \sin^3{t}$, $y = 13\cos{t} - 5\cos{2t} - 2\cos{4t}$, $0 \le t \le 2\pi.$
In [ ]:
Q2. Graph the curve $x=\mathrm{e}^t \cos{t} - \mathrm{e}^t \sin{t}$, $y = \mathrm{e}^t \sin{t}$, $0 \le t \le \pi.$ Hint: Use np.exp(t) for $\mathrm{e}^t$.
In [ ]:
Example: Sketch the curve $r = 1 + \sin{\theta}$.
In [3]:
# define array from 0 to pi 100 elements
theta = np.linspace(0, 2*np.pi, 100)
# define $r = 1 + \sin{\theta}$
r = 1 + np.sin(theta)
# add subplot in polar coordinates
ax = plt.subplot(111, polar=True)
# plot the graph
ax.plot(theta, r)
plt.show()
Q3. Sketch the curve $r = 1 + \cos{\theta}$.
In [ ]:
Q4. Sketch the curve $r = 1 - \cos{\theta}$.
In [ ]:
Example: Sketch the graph of the surface $z = x^2$.
In [4]:
x = np.arange(-2, 2, 0.25) # points in the x axis
y = np.arange(-2, 2, 0.25) # points in the y axis
X, Y = np.meshgrid(x, y) # create the "base grid"
Z = X**2 # points in the z axis
fig = plt.figure()
ax = fig.gca(projection='3d') # 3d axes instance
surf = ax.plot_surface(X, Y, Z,
rstride=2, # row step size
cstride=2, # column step size
linewidth=1, # wireframe line width
cmap=cm.RdPu, # colour map
antialiased=True)
Q5. Sketch the graph of the surface $z = x^2 - y^2$.
In [ ]:
Q6. Sketch the graph of the surface $z = x^2 + y^2$.
In [ ]:
Q7. Sketch the graph of the surface $z = y^2 - x^2$.
In [ ]:
End of question.