from sympy import*
init_printing()
# 代码2-5
x = Symbol('x')
C = 2
y = C
diff(y,x)
0
# 代码2-6
x = Symbol('x')
mu = Symbol('mu')
y = x**mu
diff(y,x)
# 代码2-7
x = Symbol('x')
a = Symbol('a')
y = a**x
diff(y,x)
# 代码2-8
x = Symbol('x')
a = Symbol('a')
y = log(x,a)
diff(y,x)
# 代码2-9
x = Symbol('x')
y = sin(x)
diff(y,x)
# 代码2-10
x = Symbol('x')
y = asin(x)
diff(y,x)
# 代码2-11
# 函数和的导数
x = Symbol('x')
u = log(x,2)
v = x**2+1
y = u+v
diff(y,x)
# 函数差的导数
y = u-v
diff(y,x)
# 函数积的导数
y = u*v
diff(y,x)
# 函数商的导数
y = u/v
diff(y,x)
# 代码2-12
# 方法一
x = Symbol('x')
u = Symbol('u')
u = x**2
y = sin(u)
diff(y,x)
# 方法二
y = sin(x**2) # 对符合函数的分解比较熟练后,可以不写出中间变量
diff(y,x)
# 代码2-13
x = Symbol('x')
y = log(tan(x))
diff(y,x)
# 代码2-14
# 方法一
x = Symbol('x')
u = Symbol('u')
v = Symbol('v')
v = exp(x)
u = cos(v)
y = log(u)
diff(y,x)
# 方法二
y = log(cos(exp(x))) # 对符合函数的分解比较熟练后,可以不写出中间变量
diff(y,x)
# 代码2-15
x = Symbol('x')
y = sin(2*x+1)
diff(y,x)
# 代码2-16
x = Symbol('x')
y = log(x+sqrt(x**2+1))
diff(y,x)
# 代码2-17
import numpy as np
x = (29/360)*2*np.pi # 设x=29°
y = np.sin(x)
print('29°角的正弦函数值为:',y)
29°角的正弦函数值为: 0.48480962024633706