[R] Substituting inside expression

Gabor Grothendieck ggrothendieck at gmail.com
Mon Feb 28 15:47:22 CET 2011


On Mon, Feb 28, 2011 at 5:03 AM, zbynek.janoska at gmail.com
<zbynek.janoska at centrum.cz> wrote:
> Thanks,
> Your advice solved the problem for one substitution, but I needed to
> substitute twice: first s = (a+b+c)/2
> and than c = sqrt(a^2 + b^2 -2*a*b*cos(gamma)) and I hoped I can do it
> simultaneously

There is no limitation to the number of substitutions using Ryacas:

> library(Ryacas)
> a <- Sym("a"); b <- Sym("b"); gamma <- Sym("gamma")
> c <- sqrt(a^2 + b^2 -2*a*b*cos(gamma))
> s <- (a+b+c)/2
> deriv(s, a)
[1] "Starting Yacas!"
expression(2 * ((2 * a - 2 * b * cos(gamma))/(2 * root(a^2 +
    b^2 - 2 * a * b * cos(gamma), 2)) + 1)/4)

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list