import matplotlib.pyplot as plt import numpy as np def chicken_egg ( B, L, w, x ): # # real B, the maximum breadth of the egg (y direction); # # real L, the maximum length of the egg (x direction). # # real w: the x-distance between the location of the maximum # breadth and the midpoint of the egg's length (x=0). # # real x(*): sample points between -L/2 and +L/2. # # Output: # # real y(*): the height of the egg at each x value. # import numpy as np top = L**2 - 4.0 * x**2 bot = L**2 + 8.0 * w * x + 4.0 * w**2 y = 0.5 * B * np.sqrt ( top / bot ) return y n = 81 B = 1.0 L = 1.5 w = 0.25 x = np.linspace ( -L/2.0, +L/2.0, n ) y = chicken_egg ( B, L, w, x ) plt.plot ( x, y, 'r-', linewidth = 3 ) plt.plot ( x, -y, 'g-', linewidth = 3 ) plt.axis ( 'equal' ) plt.grid ( True ) plt.title ( 'Chicken egg' ) filename = 'chicken_egg.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( )