Skip to content

create function to solve derivative

5 messages · e-letter, Rolf Turner, Berend Hasselman +1 more

#
Readers,

A data set comprises

A	B	C
10	6	.2
20	7	.4
30	8	.16
40	9	.0256

My requirement is to obtain the derivative for values of A with
respect to B, create a function in R and plot this derivative against
another variable (e.g. values in column C).

Have searched the mailing list and found reference to a function 'D',
but the help accessed via '?D' and '?deriv' does not explain how to
write a derivative function.

Could someone please direct me to the relevant parts of the manual to begin?

--
R2151
#
On 16/11/12 02:40, e-letter wrote:
Your question makes little sense.  Functions have derivatives --- at
least some of them do.  Data sets do not have derivatives.  The
functions D(), deriv() etc. work on specified analytic expressions
for functions --- data sets do not come into the picture.

What you might possibly want to do is to fit a spline to your data
and take the derivative of the spline.  The function splinefun()
could be what you need.

     cheers,

         Rolf Turner
#
On 16/11/2012, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
Is the following procedure correct:

Plot data from data set.

Suppose the resultant graph was linear. The function could be y=mx+c,
so the R function 'lm' could be applied to fit a linear line.

The example in the manual for the help file '?D' shows:

dx2x <- deriv(~ x^2, "x") ; dx2x

So for this example it would be correct to write:

functionname<-deriv(~mx+c,"x");dx2x

What is the significance of ';dx2x'? It would be appreciated to be
referred to the relevant manual sections, thanks.
#
On 16-11-2012, at 09:43, e-letter wrote:

            
Manual "Introduction to R" (http://cran.r-project.org/doc/manuals/r-release/R-intro.html) 
section 2.1 "Vectors and assignment"
in particular the sentence:  "If an expression is used as a complete command, the value is printed and lost"

Berend
#
On 2012-11-16 01:30, Berend Hasselman wrote:
I believe that e-letter is confused by the space-saving
use of the semicolon to place two R expressions on one line.
He neither needs nor wants the ';dx2dx' in his own
expressions.

Peter Ehlers