Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

How to compute the derivative of a function?

For example:

y=x^2+1

using NumPy?

Now, I need the value of the derivative at x=6..

1 Answer

0 votes
by (26.4k points)

Actually, You have 4 options

  1. Finite Differences
  2. Symbolic Differentiation
  3. Automatic Derivatives 
  4. Compute derivatives by hand

Look at the example using SymPy

In [1]: from sympy import *

In [2]: import numpy as np

In [3]: x = Symbol('x')

In [4]: y = x**2 + 1

In [5]: yprime = y.diff(x)

In [6]: yprime

Out[6]: 2⋅x

In [7]: f = lambdify(x, yprime, 'numpy')

In [8]: f(np.ones(5))

Out[8]: [ 2.  2.  2.  2.  2.]

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...