Advertisement
Guest User

sin equation solver python

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