Giải tích là một nhánh của toán học tập trung vào giới hạn, hàm số, đạo hàm, tích phân và chuỗi vô hạn. Chúng tôi sẽ sử dụng thư viện SymPy để tính toán với python. SymPy là một thư viện Python cho toán học tượng trưng. Nó nhằm mục đích trở thành một hệ thống đại số máy tính (CAS) đầy đủ tính năng trong khi vẫn giữ mã đơn giản nhất có thể để dễ hiểu và dễ mở rộng. SymPy được viết hoàn toàn bằng Python Show Cài đặt pip install sympy Nếu chúng ta muốn viết bất kỳ biểu thức sympy nào, trước tiên chúng ta phải khai báo các biến biểu tượng của nó. Để làm điều này, chúng ta có thể sử dụng hai chức năng sau
khác biệt hóaChúng ta có thể phân biệt bất kỳ biểu thức sympy nào bằng cách sử dụng phương thức diff(func, var). Tham số func biểu thị biểu thức sympy được phân biệt và var biểu thị biến mà chúng ta phải phân biệt ví dụ 1 Python3
derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**20 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**21 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**22 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**23 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**24
derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**25 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**26 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**21 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**28 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**29 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**29 second derivative w.r.t. x: 6*x*y second derivative w.r.t. y: 6*y1 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**29 second derivative w.r.t. x: 6*x*y second derivative w.r.t. y: 6*y3 second derivative w.r.t. x: 6*x*y second derivative w.r.t. y: 6*y4 second derivative w.r.t. x: 6*x*y second derivative w.r.t. y: 6*y3 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**29 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**29 second derivative w.r.t. x: 6*x*y second derivative w.r.t. y: 6*y1 second derivative w.r.t. x: 6*x*y second derivative w.r.t. y: 6*y4 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 10
indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 11 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 12_______1_______1 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 14 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 16 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 17 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 19 oo 0 10
oo 0 11 oo 0 12_______1_______1 oo 0 14 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 16 oo 0 17 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 19 1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)0 đầu ra. derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**2 Chúng ta cũng có thể tìm các dẫn xuất cao hơn bằng cách sử dụng phương pháp diff(func, var, n). Ở đây, tham số n biểu thị đạo hàm thứ n được tìm thấy ví dụ 2. Python31 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)1 1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)2 1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)3 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**21 1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)5 1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)6_______1_______4 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 16 # Importing library 0indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 19 # Importing library 3
1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)1
1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4)6 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**24 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 16 import 3indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 19 import 6đầu ra. second derivative w.r.t. x: 6*x*y second derivative w.r.t. y: 6*y Hội nhậpBạn có thể thực hiện tích hợp xác định và vô thời hạn của các hàm cơ bản và hàm đặc biệt siêu việt thông qua hàm integration().
Tham số func biểu thị biểu thức sympy cần lấy vi phân, var biểu thị biến mà chúng ta phải lấy vi phân, Lower_limit biểu thị giới hạn dưới của tích phân xác định và upper_limit biểu thị giới hạn trên của tích phân xác định Ghi chú. ∞ trong SymPy là oo ví dụ 1. Python3
indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 16 sympy as sym 3indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 19 sympy as sym 6
derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**21 # Declaring variables 0# Declaring variables 1# Declaring variables 2indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 # Declaring variables 2# Declaring variables 5indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 16 # Declaring variables 8indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 19_______1_______01
derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**202 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**203_______1_______1 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**205 # Declaring variables 1_______1_______07derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**208 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**209 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 16 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**212 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 19_______1_______15 đầu ra. indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 1 Hạn mứcBạn có thể tính giới hạn của hàm bằng cách sử dụng giới hạn(hàm, biến, điểm). Vì vậy, nếu bạn muốn tính giới hạn của f(x) là x->0, bạn sẽ đưa ra giới hạn (f, x, 0) Thí dụ. Python3derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**216 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**217_______1_______1 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**219 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**221
derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**222 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**223 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**21 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**225 # Declaring variables 2_______1_______27derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**228 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**230
derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**231 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**232_______1_______1 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**234 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**227_______1_______36 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**208 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**24 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**240 đầu ra. oo 0 1 Mở rộng sê-riChúng ta cũng có thể tính toán khai triển chuỗi Taylor của các hàm xung quanh một điểm. Để tính toán khai triển của f(x) xung quanh điểm x=x0 theo thứ tự xn, hãy sử dụng sympy. chuỗi(f, x, x0, n). x0 và n có thể được bỏ qua, trong trường hợp đó, giá trị mặc định x0=0 và n=6 sẽ được sử dụng Thí dụ. Python3derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**241 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**242______1_______1 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**244 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**246
derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**241 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**248 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**21 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**250 # Declaring variables 2_______1_______27derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**253 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**208 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 18 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**256 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**24 indefinite integral of cos(x): sin(x) definite integral of cos(x) between -1 to 1: 2*sin(1) definite integral of exp(-x) between 0 to ∞: 15 derivative w.r.t x: 3*x**2*y derivative w.r.t y: x**3 + 3*y**259 đầu ra. 1 - x**2/2 + x**4/24 + O(x**6) 1 + x**2/2 + O(x**4) Số hạng O(x4) hoặc O(x6) ở cuối có nghĩa là tất cả các số hạng x có lũy thừa lớn hơn hoặc bằng x4 hoặc x6 đều bị bỏ qua Trăn Cumtrapz() là gì?cumtrapz(), chúng ta có thể lấy giá trị tích phân tích lũy của y(x) bằng cách sử dụng quy tắc hình thang tổng hợp bằng cách sử dụng scipy. tích hợp. phương thức cumtrapz(). cú pháp. scipy. tích hợp. cumtrapz() Trả về. Trả về giá trị tích phân tích lũy của y(x).
Tích hợp quad hoạt động như thế nào?Hàm quad trả về hai giá trị, trong đó số đầu tiên là giá trị của tích phân và giá trị thứ hai là ước tính của sai số tuyệt đối trong giá trị của tích phân . Lưu ý - Vì quad yêu cầu hàm làm đối số đầu tiên nên chúng ta không thể chuyển trực tiếp exp làm đối số.
Sự khác biệt giữa quad và quadrature trong Scipy là gì?quad nhận một hàm có đối số vô hướng trong khi bậc hai nhận một hàm nhận đối số vectơ (nhiều đánh giá khác nhau của hàm đồng thời). Thích ứng chỉ có nghĩa là nó lấy nhiều mẫu hơn (hiệu quả) cho đến khi sai số cận biên giảm xuống dưới một số dung sai.
Tích hợp quad trở lại là gì?quad(), chúng ta có thể lấy tích phân của một hàm đã cho từ giới hạn a đến b bằng cách sử dụng scipy. tích hợp. phương thức quad(). Trở lại. Trả về tích phân của một đa thức . |