Skip to content
Advertisement

Derivative using Numpy or Other Library for lambda sin function

So i have this newton optimation problem where i must found the value f'(x) and f”(x) where x = 2.5 and the f = 2 * sin(x) – ((x)**2/10) for calculating, but i tried using sympy and np.diff for the First and Second Derivative but no clue, cause it keep getting error so i go back using manual derivate, Any clue how to derivative the function f with help of other library, Here’s the code

JavaScript

finding first and second derivative without the manual way.

Advertisement

Answer

In your case, the derivates can be calculated using the scipy library as follows:

JavaScript

Here the first and second derivative is calculated for your function at x=2.5.

The same can be done with the sympy library and some may find this easier than the above method.

JavaScript
Advertisement