Advertisement
Guest User

sin equation solver python

a guest
Sep 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. graph1: 1  sin(x +  0 ) +  0
  2. graph2: 2  sin(x +  0 ) +  0
  3. graph3: 1 sin(x +  0 ) +  3
  4. graph4: 1 sin(x +  180 ) +  0
  5.  
  6. def most_frequent(List):
  7.     counter = 0
  8.     num = List[0]
  9.      
  10.     for i in List:
  11.         curr_frequency = List.count(i)
  12.         if(curr_frequency> counter):
  13.             counter = curr_frequency
  14.             num = i
  15.  
  16.     return num
  17.  
  18.  
  19. def find_equation(graph):
  20.     min_value = 10000
  21.     max_value = 1
  22.     values = []
  23.    
  24.     for coord in graph:
  25.         #we dont need to find the min value, as it'll be the max value but with a changed sign
  26.         if max_value < coord[1]:
  27.             max_value = coord[1]
  28.         if min_value > coord[1]:
  29.             min_value = coord[1]
  30.         values.append(coord[1])
  31.     normal = int((min_value + max_value)/2)
  32.   #  print("Normal: ", normal)
  33.     coef = max_value - normal
  34.  #   print("Max_value: ", max_value)
  35.  #   print("Coef:", coef)
  36.  
  37.     step = values[1] - values[0]
  38.  #   print("Step:", step)
  39.  
  40.    
  41.     if step != 1:
  42.         values = list(map(lambda x: int(x/step), values))
  43.     if normal != 0:
  44.         values = list(map(lambda x: x-normal, values))
  45.        
  46.    
  47. #    print("Values:", values)
  48.    
  49.     real_values = [0, 1, 0, -1, 0]
  50.     counter = 0
  51.     if real_values != values:
  52.         for value in values:
  53.             counter += 1
  54.             if value == 0:
  55.                 break
  56.        # print("move by", counter)
  57. #    print(values)
  58.    
  59.     print(coef, "sin(x + ", 90*counter, ") + ", normal)
  60.        
  61.  
  62. graph1 = [(0, 0), (90, 1), (180, 0), (270, -1), (360, 0)]
  63. graph2 = [(0, 0), (90, 2), (180, 0), (270, -2), (360, 0)]
  64. graph3 = [(0, 3), (90, 4), (180, 3), (270, 2), (360, 3)]
  65. graph4 = [(0, 1), (90, 0), (180, -1), (270, 0), (360, 1)]
  66.  
  67.  
  68. find_equation(graph1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement