[R] Derivative of a function

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Jul 5 13:57:01 CEST 2005


Gabriel Rodrigues Alves Margarido wrote:

> Suppose I have a simple function that returns a matrix, such as:
> 
> test <- function(x){ return(matrix(c(x,x^2,x^3,x^4),2,2)) }
> 
> so that test returns:
> [ x      x^3 ]
> [ x^2    x^4 ]
> 
> Is it possible for me to get the derivative of an expression such as:
> 
> c(1,0) %*% test() %*% c(0,1)
> 
> The vectors are used just to "index" the matrix.
> I don't want a value, but the expression to work with (in that case,
> the expected expression would be 3*x^2)...
> 
> Tried functions D and deriv in many ways, but no success.
> I will be grateful if anyone can help.
>

I think you cannot easily handle expressions like this.
Perhaps you better look for some algebra system such as Mathematica and 
friends.

Uwe Ligges


> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list