[R] deriv() to take vector of expressions as 1st arg?

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 30 00:29:44 CET 2009


OK. Try this:

sapply(expression(x^2+y^3, x^5+y^6), deriv, c("x", "y"))


On Thu, Oct 29, 2009 at 7:11 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>
> On 30/10/2009, at 11:35 AM, Gabor Grothendieck wrote:
>
>> Try this:
>>
>> deriv(expression(x^2+y^3, x^5+y^6), c("x","y"))
>
> Did *you* try it Gabor?  I did just now and it returns only
> the gradient of the first component:
>
>  > deriv(expression(x^2+y^3, x^5+y^6), c("x","y"))
> expression({
>    .value <- x^2 + y^3
>    .grad <- array(0, c(length(.value), 2L), list(NULL, c("x",
>        "y")))
>    .grad[, "x"] <- 2 * x
>    .grad[, "y"] <- 3 * y^2
>    attr(.value, "gradient") <- .grad
>    .value
> })
>
>        cheers,
>
>                Rolf Turner
>
> ######################################################################
> Attention: This e-mail message is privileged and confidential. If you are
> not the intended recipient please delete the message and notify the sender.
> Any views or opinions presented are solely those of the author.
>
> This e-mail has been scanned and cleared by MailMarshal
> www.marshalsoftware.com
> ######################################################################
>




More information about the R-help mailing list