_interpnd_info.py 869 B

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