[R] equalize function with zero and convert it

Immanuel Seeger jimmy-seeger at web.de
Thu Aug 26 15:45:03 CEST 2010


Thanks, but my problem is that I have my formulas in functions.
How can I do that for functions or e.g. for the body(Df) below?
And: How can I refer to the first solution of expression?
Thanks a lot!

-----Ursprüngliche Nachricht-----
Von: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] 
Gesendet: Donnerstag, 26. August 2010 14:56
An: Immanuel Seeger
Cc: r-help at r-project.org
Betreff: Re: [R] equalize function with zero and convert it

On Thu, Aug 26, 2010 at 6:57 AM, Immanuel Seeger <jimmy-seeger at web.de>
wrote:
> Dear all,
> I want to equalize a symbolic derivative (of a function with two
> variables) with zero and convert it to a variable, e.g. x.
>
> I'm computing the derivative by: (found it in the archive)
> library(Ryacas)
> f <- function(x,y) (100-x-y)*x-10*x
> yacas(f) # register f with yacas
> Df <- f
> body(Df) <- yacas(expression(deriv(f(x,y),x)))[[1]]
> Df
>
> R-Output:
> function (x, y)
> 100 - x - y - x - 10
>
> Questions :
> 1.      How can I equalize the derivative(140-x-y-x-20) with zero?
> 2.      How can I convert it to x?
>
> I want something like:
> 45-0.5*y=x
>
> With only one variable or two non-symbolic variables it's working with
> uniroot(f, c(-10, 10))$root.
>

This solves for x:

> library(Ryacas)
Loading required package: XML
> x <- Sym("x")
> y <- Sym("y")
> Solve((100-x-y)*x-10*x == 0, "x")
[1] "Starting Yacas!"
expression(list(x == -((10 - (100 - y) + root((100 - y - 10)^2,
    2))/2), x == -((10 - (100 - y) - root((100 - y - 10)^2, 2))/2)))

-- 
GKX Group
GKX Associates Inc.
1-877-GKX-GROUP
ggrothendieck at gmail.com



More information about the R-help mailing list