EWTD

Untitled

Jun 15th, 2021
591
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. def circle_square(external_radius,inner_radius):
  6.         return math.pi*(external_radius*external_radius-inner_radius*inner_radius)
  7.  
  8.  
  9. def main():
  10.     print(f"circle square(10,5): {circle_square(10,5)}")
  11.     x_coords = [-3.14+i*0.02 for i in range(0, 315)]
  12.     function1_y_coords = [2*math.sin(x_coord) for x_coord in x_coords]
  13.     function2_y_coords = [math.cos(2*x_coord) for x_coord in x_coords]
  14.     min_delta = 10.0
  15.     min_coord = -1
  16.     for index in range(0, len(x_coords)):
  17.         current_res = abs(function1_y_coords[index]-function2_y_coords[index])
  18.         if min_delta > current_res:
  19.             min_delta = current_res
  20.             min_coord = index
  21.     print(f"intersect in (x={min_coord*0.02-3.14},y={min_delta})")
  22.     plt.title("y1 = 2sin(x), y2 = cos(2x)")
  23.     plt.xlabel("x")
  24.     plt.ylabel("y1, y2")
  25.     plt.grid()
  26.     plt.plot(x_coords, function1_y_coords,x_coords, function2_y_coords)
  27.     plt.show()
  28.  
  29. main()
RAW Paste Data