################################################################### # This file is unit04_elliptic_integrand.py. It draws a graph # of a function described in the in-class material: the integrand of a # complete elliptic integral of the second kind. This integral gives # the perimeter of an ellipse with semi-major, minor axes a and b. # George Gollin, University of Illinois, May 26, 2016 ################################################################### # import libraries import numpy as np import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # semimajor and minor axes: axis_a = 2. axis_b = 1.5 # squares: axis_asq = axis_a**2 axis_bsq = axis_b**2 # integral will go from 0 to pi/2. and I want to plot its integrand. define # an array holding theta values. theta_min = 0. theta_max = np.pi / 2 array_length = 100 theta_array = np.linspace(theta_min, theta_max, array_length) # load the array of ordinate (y axis) values: f_of_theta_array = np.sqrt(axis_asq - (axis_asq - axis_bsq) * np.sin(theta_array)**2) # now make the graph. open a new window for the plot we are about to make plt.figure() # now draw the plot plt.plot(theta_array, f_of_theta_array) # now label the axes and give the plot a title. "gca" is "get current axes" ax = plt.gca() ax.set_xlabel("theta (radians)") ax.set_ylabel("integrand") ax.set_title("integrand of the second kind") # now save the plot to a png (portable network graphics) file plt.savefig("unit04_elliptic_integrand.png") print("all done") ###################################