# Re: [R] Substituting inside expression

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 28 Feb 2011 09:47:22 -0500

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
```
Received on Mon 28 Feb 2011 - 15:08:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Feb 2011 - 15:40:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.