# Derivative of a list of data values

**URL:** <https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343>\
**Category:** Questions\
**Tags:** mathematica, calculus, numerical-computation\
**Created:** [June 10, 2014, 1:43am UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343 "2014-06-10T01:43:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![intansupraba](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@intansupraba](https://community.wolfram.com/u/intansupraba)\
**Post date:** [June 10, 2014, 1:43am UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343/1 "2014-06-10T01:43:43Z")

</div>

Dear All,

I want to ask your advise. I have a variable q as a function of time but I already have the values of q for each time step.  
So do you know any command in Mathematica for getting the derivative values of q?  
There are some commands such as:  
dq/dt = D[q[t],t] or dq/dt = q’[t] but I think I can use that command if I have q as an equation but I have q as values.

So I used the below method to calculate the derivative:

```
dqdt = Table[(q[t + 1] - q[t - 1])/2, {t, 1, 99}]

```

Please refer to attach. titled “Derivative.nb” for the script.  
So may I know if the above method is correct? And may I know the alternative ways for calculating derivative like in this case?  
Thanks a lot for your kind attention.

Best Regards,  
Intan

---

<div class="post-metadata">

**Author:** ![nma](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@nma](https://community.wolfram.com/u/nma)\
**Post date:** [June 10, 2014, 3:48am UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343/2 "2014-06-10T03:48:27Z")

</div>

had quick look. You already found an interpolation function called q. There nothing more to do. In Mathematica, you can differentiate and integration these interpolation functions like any other function. So all you have to do is

D[q[t], t]

to obtain the derivative. This will give you another interpolation function which is the derivative of q.

---

<div class="post-metadata">

**Author:** ![intansupraba](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@intansupraba](https://community.wolfram.com/u/intansupraba)\
**Post date:** [June 11, 2014, 12:45am UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343/3 "2014-06-11T00:45:39Z")

</div>

Dear Nasser,

Thanks a lot for your response. But sorry as I am still confused. Yes I already have an interpolation function called q. Then I use the derivative command: dqdt = Do[Print[D[q[t], t]], {t, 0, 100}] and I got the another interpolation like what you said. But the results of the derivative is not as per expected (please refer to attach. “Derivative\_1.nb”).

So do you know what went wrong? Or did I use the wrong command to list the output of that derivative (dq/dt)? Thanks in advance for your reply.

Best Regards,  
Intan

---

<div class="post-metadata">

**Author:** ![nma](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@nma](https://community.wolfram.com/u/nma)\
**Post date:** [June 11, 2014, 1:33am UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343/4 "2014-06-11T01:33:12Z")

</div>

What you had is this

```
dqdt = Do[Print[D[q[t], t]], {t, 0, 100}]

```

Which does not work, since “t” becomes a number, and one can’t take derivative with respect to a number. You could write

```
dqdt = Do[Print@Evaluate[D[q[t], t] /. t -> i], {i, 0, 100}]

```

But it is easier to write

```
lst = (D[q[t], t] /. t -> #) & /@ Range[0, 100]

```

Or just take the derivative outside once, and evaluate it

```
D[q[t], t];
lst = (% /. t -> #) & /@ Range[0, 100]

```

---

<div class="post-metadata">

**Author:** ![intansupraba](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@intansupraba](https://community.wolfram.com/u/intansupraba)\
**Post date:** [June 11, 2014, 2:36am UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343/5 "2014-06-11T02:36:41Z")

</div>

Dear Nasser,

Yes, it works:). Thanks a lot for your help!

Best Regards,  
Intan

---

<div class="post-metadata">

**Author:** ![shenghuiy](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/shenghuiy/32/36073_2.png) [@shenghuiy](https://community.wolfram.com/u/shenghuiy)\
**Post date:** [June 13, 2014, 6:18pm UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343/6 "2014-06-13T18:18:31Z")

</div>

Also you can use the hardcore table like function to find the derivative if you do not use the interpolation function:

```
(*[[All, 2]]* takes all rows and pick up the second column only/ time step = 1*)
ListConvolve[{1, -1}, data[[All, 2]]] 

```

assuming data is

```
data = {{0, 0.1425`}, {1, 0.1425`}, {2, 0.1425`}, ..., {99, 0.523363636`}}

```

---

<div class="post-metadata">

**Author:** ![anon21378091](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@anon21378091](https://community.wolfram.com/u/anon21378091)\
**Post date:** [January 10, 2020, 12:57am UTC](https://community.wolfram.com/t/derivative-of-a-list-of-data-values/2343/7 "2020-01-10T00:57:14Z")

</div>

Shenghui, you make a good suggestion, but I believe the 3 point formula is better implemented as:  
ListConvolve[{1, 0, -1}, data[[All, 2]]] / ListConvolve[{1, 0, -1}, data[[All, 1]]]
