Solving equations

Derivatives

Derivatives by smp.diff(f, x, n), where f is a function of variable x, f(x), and n is the order of derivatives

Example 1:

Example 2

Example 3

Example 4

Example 5: $$f(x) = e^{-a\sin(x^2)}\cdot \sin(b^x) \cdot \ln(c\sin^2(x)/x)$$

Finding an analytical expression for the derivative after substituting the values of x, a, b, and c into the derivative expression

Evaluating the derivatives numerically to find the final value

Making ready the numerical derivatives function for plotting

Numerical Case

1) The basic way, which works fine if the data is smooth but not if the data is noisy

For the noisey data, this method does not work, beacuse noises are amplified in the derivative.

Thus, let us introduce the second method:

2. The Clever Way

Smooth data then take derivative. Consider the following new covid cases per day data

Taking the derivative naively gives a bad result

Smooth the data by convolving it with a rectangle

Plot

Quasi-Symbolic Case

In this case you know your function $f(x) = ...$ but the function is not given by a typical expression. For example.

$$f(u) = \text{max} \left\{ \left|e^{-x_iu^2} - y_i\right| \right\} $$

for some array of $x_i$'s and $y_i$'s

Define function

Compute the function values

Plot

You could always just take the derivative of the numerical array f_u, but there is a specific derivative function better assigned for this

Compute derivative

Plot

Vectorized

Non-vectorized

The vectorized function evaluates pyfunc over successive tuples of the input arrays like the python map function, except it uses the broadcasting rules of numpy.

The data type of the output of vectorized is determined by calling the function with the first element of the input. This can be avoided by specifying the otypes argument.