From: Estee on
Hi,

I have an array of numbers, for example x = [1 2 3 4 5].
I want to find the (approximate) derivative for array x.
On the MatLab site, a suggestion to approximate the derivative looks like this:
y = diff(x);
derivative = diff(y) ./ diff(x)
However, since diff(array) shortens the length by 1, the top and bottom are of different sizes and causes an error.

Does anyone know how to fix this, or know a better way to approximate derivatives of an array of numbers?

Thanks! =]

Estee
From: dpb on
Estee wrote:
> Hi,
> I have an array of numbers, for example x = [1 2 3 4 5].
> I want to find the (approximate) derivative for array x. On the MatLab
> site, a suggestion to approximate the derivative looks like this:
> y = diff(x);
> derivative = diff(y) ./ diff(x) However, since diff(array) shortens the
> length by 1, the top and bottom are of different sizes and causes an error.
>
> Does anyone know how to fix this, or know a better way to approximate
> derivatives of an array of numbers?
....

You can fit some functional form and analytically differentiate that
function.

doc polyfit

for one choice...

--