interpnd_info.py 935 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. """
  2. Here we perform some symbolic computations required for the N-D
  3. interpolation routines in `interpnd.pyx`.
  4. """
  5. from __future__ import division, print_function, absolute_import
  6. from sympy import symbols, binomial, Matrix
  7. def _estimate_gradients_2d_global():
  8. #
  9. # Compute
  10. #
  11. #
  12. f1, f2, df1, df2, x = symbols(['f1', 'f2', 'df1', 'df2', 'x'])
  13. c = [f1, (df1 + 3*f1)/3, (df2 + 3*f2)/3, f2]
  14. w = 0
  15. for k in range(4):
  16. w += binomial(3, k) * c[k] * x**k*(1-x)**(3-k)
  17. wpp = w.diff(x, 2).expand()
  18. intwpp2 = (wpp**2).integrate((x, 0, 1)).expand()
  19. A = Matrix([[intwpp2.coeff(df1**2), intwpp2.coeff(df1*df2)/2],
  20. [intwpp2.coeff(df1*df2)/2, intwpp2.coeff(df2**2)]])
  21. B = Matrix([[intwpp2.coeff(df1).subs(df2, 0)],
  22. [intwpp2.coeff(df2).subs(df1, 0)]]) / 2
  23. print("A")
  24. print(A)
  25. print("B")
  26. print(B)
  27. print("solution")
  28. print(A.inv() * B)