Hi guys
Thanks for all the fantastic suggestions! I didnt realise you could extract
the body of a function in that manner. It looks like R always has many ways
to solve a particular problem.
Cheers
Rory
On 9/4/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
>
> And if f has brace brackets surr
And if f has brace brackets surrounding the body then do this:
f <- function(x) { x*x }
deriv(body(f)[[2]], "x", func = TRUE)
If you are writing a general function you can do this:
e <- if (identical(body(f)[[1]], as.name("{"))) body(f)[[2]] else body(f)
deriv(e, "x", func = TRUE)
On 9/3/07, G
One improvement. This returns a function directly without having
to create a template and filling in its body:
deriv(body(f), "x", func = TRUE)
On 9/3/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> The problem is that brace brackets are not in the derivatives table.
> Make sure you don't ha
On 03-Sep-07 21:45:40, Alberto Monteiro wrote:
> Rory Winston wrote:
>>
>> I am currently (for pedagogical purposes) writing a simple numerical
>> analysis library in R. I have come unstuck when writing a simple
>> Newton-Raphson implementation, that looks like this:
>>
>> f <- function(x) { 2*co
The problem is that brace brackets are not in the derivatives table.
Make sure you don't have any.
On 9/3/07, Alberto Vieira Ferreira Monteiro <[EMAIL PROTECTED]> wrote:
> Gabor Grothendieck wrote:
> >
> > Actually in thinking about this its pretty easy to do it without Ryacas
> > too:
> >
> > Df
Gabor Grothendieck wrote:
>
> Actually in thinking about this its pretty easy to do it without Ryacas
> too:
>
> Df <- f
> body(Df) <- deriv(body(f), "x")
> Df
>
This is weird.
f <- function(x) { x^2 + 2*x+1 }
Df <- f
body(Df) <- deriv(body(f), "x") # error
Also:
f <- function(x) x^2 + 2 * x + 1
Actually in thinking about this its pretty easy to do it without Ryacas too:
Df <- f
body(Df) <- deriv(body(f), "x")
Df
On 9/3/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> The Ryacas package can do that (but the function must be one line
> and it can't have brace brackets). The first yac
The Ryacas package can do that (but the function must be one line
and it can't have brace brackets). The first yacas call below registers f with
yacas, then we set up a function to act as a template to hold the
derivative and then we set its body calling yacas again to take the
derivative.
librar
Rory Winston wrote:
>
> I am currently (for pedagogical purposes) writing a simple numerical
> analysis library in R. I have come unstuck when writing a simple
> Newton-Raphson implementation, that looks like this:
>
> f <- function(x) { 2*cos(x)^2 + 3*sin(x) + 0.5 }
>
> root <- newton(f, tol=
Hi
I am currently (for pedagogical purposes) writing a simple numerical
analysis library in R. I have come unstuck when writing a simple
Newton-Raphson implementation, that looks like this:
f <- function(x) { 2*cos(x)^2 + 3*sin(x) + 0.5 }
root <- newton(f, tol=0.0001, N=20, a=1)
My issue is c
> "Gabor" == Gabor Grothendieck <[EMAIL PROTECTED]>
> on Tue, 5 Jul 2005 09:14:20 -0400 writes:
Gabor> On 7/4/05, Gabriel Rodrigues Alves Margarido
Gabor> <[EMAIL PROTECTED]> wrote:
>> Suppose I have a simple function that returns a matrix, such as:
>>
>> test <- f
On 7/5/05, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> On 7/4/05, Gabriel Rodrigues Alves Margarido
> <[EMAIL PROTECTED]> 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:
On 7/4/05, Gabriel Rodrigues Alves Margarido
<[EMAIL PROTECTED]> 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^2x^4 ]
>
> Is it possible for me to get
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^2x^4 ]
>
> Is it possible for me to get the derivative of an expressio
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^2x^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 us
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^2x^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 us
16 matches
Mail list logo