Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. def f(t):
  2.     (x, y, z, w) = t
  3.     return x * y + z - w
  4.  
  5. def specialiser(f, constantes, positions):
  6.    
  7.     v = [0]*(len(t) + len(constantes))
  8.     for i,c in zip(positions, constantes):
  9.         v[i] = c
  10.     variables_pos = [i for i in range(len(v)) if i not in positions]
  11.    
  12.     def specialisee(t):
  13.         for i,p in enumerate(variables_pos):
  14.             v[p] = t[i]
  15.         return f(tuple(v))
  16.  
  17.     return specialisee
  18.  
  19.  
  20. # On specialise f sur x et y (position 0 et 1) aux valeurs 5 et 6
  21. g = specialiser(f, (5, 6), (0, 1))
  22. optimise.minimize(g, [12.1, 121.5])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement