Derivatives of delta

Question:

I want to calculate E by this equation. But I am not sure if I can obtain results with numpy.diff module. It exports 4 points only.

enter image description here

from numpy import diff

x = [395.33, 472.12, 560.45, 652.72, 732.55]
y = [0.17, 0.22, 0.28, 0.34, 0.41]
E = diff(y) / diff(x)

print(E)

Output:

[0.00065113 0.00067927 0.00065027 0.00087686]
Asked By: Binh Thien

||

Answers:

It is expected that the derivative is computed only on the intermediates segments between successive points, thus having one less value than the number of points.

What you expect is unclear, do you want to compute the gradient?

import numpy as np

E = np.gradient(y, x)

Output:

array([0.00065113, 0.00066422, 0.00066508, 0.00077175, 0.00087686])

Differences between diff and gradient:

enter image description here

More complex example:

Observe how the green curve is exactly the derivative of each segment (=slope), while the gradient is smoother (depends on points before and after)

enter image description here

Answered By: mozway
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.