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