Skip to content

How to calculate the derivatives at each data point?

7 messages · konstantinos christodoulou, PIKAL Petr, Ivan Krylov +1 more

#
Hi everyone,

I have a vector with atmospheric measurements (x-axis) that is
obtained/calculated at different altitudes (y-axis). The altitude is
uniformly distributed every 7 meters.
For example my dataframe is:
df <- dataframe(
*altitude* = c(1005, 1012, 1019, 1026, 1033, 1040, 1047, 1054, 1061, 1068),
*atm_values* = c(1.41, 1.40, 1.39, 1.38, 1.37, 1.37, 1.38, 1.36, 1.33, 1.31)
                         )

How can I find the derivatives of the atmospheric measurements at each
altitude?

I look forward to hearing from you!

Thanks,
Kostas
#
Hi Konstantinos

Not exactly derivative but
[1] -0.01 -0.01 -0.01 -0.01  0.00  0.01 -0.02 -0.03 -0.02

May be enaough for you.

Cheers
Petr
uniformly
1068),
1.31)
http://www.R-project.org/posting-guide.html
#
? Tue, 31 Jan 2023 11:16:21 +0200
konstantinos christodoulou <konstantinos.christodoulou1 at gmail.com>
?????:
Welcome to the world of finite difference methods! If you can find a
good textbook on them, it may be a good idea to skim it.

pracma::fornberg() will give you a numerically stable approximation
(otherwise the Vandermonde matrix required to obtain the Taylor series
coefficients may get hard to solve) to the derivative values you're
interested in, but do note that they are only approximations. In
particular, there's less information for the values at the ends of
the altitude range than for the points in the middle.
P.S. Please compose your messages to R-help in plain text:
https://www.r-project.org/posting-guide.html
https://stat.ethz.ch/pipermail/r-help/2023-January/476845.html
#
Try something like

with(df, predict(smooth.spline(x = altitude, y = atm_values), deriv = 1))

Cheers,

Andrew

--
Andrew Robinson
Chief Executive Officer, CEBRA and Professor of Biosecurity,
School/s of BioSciences and Mathematics & Statistics
University of Melbourne, VIC 3010 Australia
Tel: (+61) 0403 138 955
Email: apro at unimelb.edu.au
Website: https://researchers.ms.unimelb.edu.au/~apro at unimelb/

I acknowledge the Traditional Owners of the land I inhabit, and pay my respects to their Elders.
On 31 Jan 2023 at 8:17 PM +1100, konstantinos christodoulou <konstantinos.christodoulou1 at gmail.com>, wrote:
External email: Please exercise caution

Hi everyone,

I have a vector with atmospheric measurements (x-axis) that is
obtained/calculated at different altitudes (y-axis). The altitude is
uniformly distributed every 7 meters.
For example my dataframe is:
df <- dataframe(
*altitude* = c(1005, 1012, 1019, 1026, 1033, 1040, 1047, 1054, 1061, 1068),
*atm_values* = c(1.41, 1.40, 1.39, 1.38, 1.37, 1.37, 1.38, 1.36, 1.33, 1.31)
)

How can I find the derivatives of the atmospheric measurements at each
altitude?

I look forward to hearing from you!

Thanks,
Kostas


______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
#
Hi Andrew,

I applied your command in another dataset with known derivative values and
it gave me very satisfactory results!
Therefore, I will use it on my dataset. Thank you so much!

Kostas



On Tue, Jan 31, 2023 at 12:22 PM Andrew Robinson <apro at unimelb.edu.au>
wrote:

  
  
#
Hi Ivan!

Thank you for your valuable insights! I look forward to learning more about
numerical differentiation and about this subject.

The pracma package and the fornberg() function is impressive. I got some
really good approximations on my derivatives.

Thank you!
Kostas
On Tue, Jan 31, 2023 at 12:18 PM Ivan Krylov <krylov.r00t at gmail.com> wrote:

            

  
  
#
Thank you Petr!
On Tue, Jan 31, 2023 at 11:58 AM PIKAL Petr <petr.pikal at precheza.cz> wrote: