how can we take the derivative of a function by Python?
(1)Background And Introduction
How do you prove that the derivative of your function is correct?
You can’t know for sure if the derivative is correct by hand, but we can write a math library in Python to verify it
(2)Derivative
This is some mindmaps about how to derivative the function (by the way,the language of these images is Chinese):
(3)Ex.
(3.1)Ex. 1
Let’s derivative this function and caculate the value of derivative while the xo equals to one.
What does this function look like?
Let’s draw it( You can learn how to plot a function by this passage which I writen if you don’t how to plot a function in Python):
We can caculate it to the result like this:
Ok, now we will use the Lib which named Sympy of Mathematics in Python,, to solve it:
1 | #!usr/bin/env python |
Calling derivative function: derivative(False)
and we will take the derivative of it. Now we got the result:
the function of derivative like this:
(3.2)Ex. 2
We can get first derivative in default solution.
When we need to find the higher derivative, we can get the higher derivative through the following code:
1 | #!usr/bin/env python |
for example, We will take the second derivative of function: y = x^3
:
(4)Confusing Things
I try to show the function figure in Sympy code but failed.
1 | if draw: |
You can find that the canvas have nothing on it.
Obviously, there are many problems with my code, so you can commit your correct code to me in comments if you are willing to help me and other learners!