Message Boards Message Boards

0
|
25528 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Derivative of a list of data values

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

Attachments:
POSTED BY: INTAN SUPRABA
6 Replies
Posted 4 years ago

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]]]

POSTED BY: Updating Name

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`}}
POSTED BY: Shenghui Yang

Dear Nasser,

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

Best Regards, Intan

POSTED BY: INTAN SUPRABA

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]
POSTED BY: Nasser M. Abbasi

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

Attachments:
POSTED BY: INTAN SUPRABA

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.

POSTED BY: Nasser M. Abbasi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract