Advertisement
mikhail_dvorkin

SciPy linear algebra and integrating

Apr 14th, 2016
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import numpy as np
  2. from scipy import linalg
  3. from scipy import matrix
  4.  
  5. a = np.array([[1, 2], [3, 4]])
  6.  
  7. d = linalg.det(a)
  8. print(a.dtype)
  9. b = linalg.inv(a)
  10. print(linalg.inv(a))
  11. print(np.dot(a, b))
  12. print(b[1][1])
  13. c = np.array([[-2.,  1.], [ 1.5, -0.5]])
  14. print(b - c)
  15. print(np.dot(a, c))
  16.  
  17. #a = np.array([[1, 2], [2, 4]])
  18. #print(linalg.inv(a))
  19.  
  20. print(matrix.trace(a))
  21. print(matrix.transpose(a))
  22. print(linalg.eig(a)[1])
  23.  
  24. a = np.array([[1, 2, 3], [1, 5, 6], [0, 0, 4]])
  25. b = np.array([0, 0, 1])
  26. c = linalg.solve_triangular(a, b)
  27. print(np.dot(a, c))
  28.  
  29. from scipy.integrate import *
  30.  
  31. print(quad(np.sin, 0, np.pi / 2))
  32. print(quad(lambda x : x * x, 0, 1))
  33. print(quadrature(np.sin, 0, np.pi/2, tol=0.5e-6))
  34. print(dblquad(lambda x, y: x * y, 0, 1, lambda x: 0, lambda x: x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement