【Sage数学库】符号计算:函数求导、求偏导数、求积分

【Sage数学库】符号计算:函数求导、求偏导数、求积分

帮助链接:  

https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/tests.html

# derivative 求导
print(derivative(arctan(x), x))
# 或者 diff 求导
print(diff(arctan(x), x))

#求导
print(diff(-cos(x), x))
# 不定积分
integral(sin(x),x)
print(integral(sin(x),x))
y = var('y')
print(integral(sin(x),y))

# 定积分
# 定积分(上下限是变量)
var('a, b')
integrate(sin(x), x, a, b)
print(integrate(sin(x), x, a, b))

# 下面的定积分值 是 1 
integrate(sin(x), x, 0, pi/2)
print(integrate(sin(x), x, 0, pi/2))

1/(x^2 + 1)
1/(x^2 + 1)
sin(x)
-cos(x)
y*sin(x)
cos(a) - cos(b)
1

 

下面求函数的偏导数:

参考: https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html

# ★★★★★★★★★★★ 【实际上,diff是用来求偏导数的!】 ★★★★★★★★★★ 
# https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html
f(x,y)=x^2*y+y^2+y
print("二元函数f(x,y):")
print(f)
PianDaoShu_gradient = f.diff() # 偏导数
print("二元函数f(x,y)的【偏导数】:")
print(PianDaoShu_gradient)

二元函数f(x,y):
(x, y) |--> x^2*y + y^2 + y
二元函数f(x,y)的【偏导数】:
(x, y) |--> (2*x*y, x^2 + 2*y + 1)

 

高阶偏导数:

# ★★★★★★★★★★★ 【实际上,diff是用来求偏导数的,而且可用求 高阶偏导数!】 ★★★★★★★★★★ 
# https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html
f(x,y)=x^2*y+y^2+y
print("二元函数f(x,y):")
print(f)
PianDaoShu_gradient = f.diff() # 偏导数
print("二元函数f(x,y)的【偏导数】:")
print(PianDaoShu_gradient)

# 对 x求 二阶偏导数
f_x_2_PianDao = f.diff(x, 2)
print("对 x求 二阶偏导数:")
print(f_x_2_PianDao)

# 对 y求 二阶偏导数
f_y_2_PianDao = f.diff(y, 2)
print("对 y求 二阶偏导数:")
print(f_y_2_PianDao)

二元函数f(x,y):
(x, y) |--> x^2*y + y^2 + y
二元函数f(x,y)的【偏导数】:
(x, y) |--> (2*x*y, x^2 + 2*y + 1)
对 x求 二阶偏导数:
(x, y) |--> 2*y
对 y求 二阶偏导数:
(x, y) |--> 2

 

备忘(有时间再实践):

Sage里面的 泰勒公式? ===>  taylor  ?

https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html

taylor(u(x+h),h,0,4)
1/24*h^4*diff(u(x), x, x, x, x) + 1/6*h^3*diff(u(x), x, x, x) + 1/2*h^2*diff(u(x), x, x) + h*diff(u(x), x) + u(x)

 

你可能感兴趣的:(【Sage数学库】符号计算:函数求导、求偏导数、求积分)