# import the Lib from sympy import * import matplotlib.pyplot as plt
# define a function to caculate # we can use the function to derivative the # function what you want to solve defderivative(draw = False): """ derivate @para draw: Bool,plot function or not """ x,f = symbols("x,f") dx = 1 # define a function which will be derivatived f = log(1+exp(x**2)) print("the derivative of function :",diff(f,x)) if dx != None: print("the value of derivative in xo (xo = {}):{}".format(dx,f.evalf(subs ={'x':dx}))) if draw: ezplot = lambda expr:plot_implicit(sympify(expr)) ezplot(f)
# import the Lib from sympy import * import matplotlib.pyplot as plt
# define a function to caculate # we can use the function to derivative the # function what you want to solve defderivative(draw = False): """ derivate @para draw: Bool,plot function or not """ x,f = symbols("x,f") dx = 1 # define a function which will be derivatived n = 2 f = x**3 print("the derivative ({}) of function :{}".format(n,diff(f,x,n))) if dx != None: print("the value of derivative in xo (xo = {}):{}".format(dx,f.evalf(subs ={'x':dx}))) if draw: ezplot = lambda expr:plot_implicit(sympify(expr)) ezplot(f)
for example, We will take the second derivative of function: y = x^3 :
(4)Confusing Things
我试图在 Sympy 代码中显示求导后的函数图,但失败了。
1 2 3
if draw: ezplot = lambda expr:plot_implicit(sympify(expr)) ezplot(f)