Reputation: 4704
say I am taking the derivative of an expression in R
:
D(expression((x^3)/(2*(x+1))),"x")
The output is:
3 * x^2/(2 * (x + 1)) - (x^3) * 2/(2 * (x + 1))^2
I was wondering if this output can be shown on the screen in TeX form, which is easier to read.
Thanks.
Upvotes: 2
Views: 266
Reputation: 269905
Check out Ryacas:
> library(Ryacas)
> yacas("TeXForm(3 * x^2/(2 * (x + 1)) - (x^3) * 2/(2 * (x + 1))^2)",
+ retclass = "unquote")
$\frac{3 x ^{2}}{2 \left( x + 1\right) } - \frac{2 x ^{3}}{\left( 2 \left( x + 1\right) \right) ^{2}} $
EDIT: or
> library(Ryacas)
> x <- Sym("x")
> y <- (x^3)/(2*(x+1))
> dy <- deriv(y, x)
> dy <- Simplify(dy)
> fmt <- sprintf("TeXForm(%s)", dy)
> yacas(fmt, retclass = "unquote")
$\frac{\left( 2 x + 3\right) x ^{2}}{2 \left( x ^{2} + 2 x + 1\right) } $
Upvotes: 5
Reputation: 9324
Well, standard text-plotting routines accept the arguments of type 'expression' and interpret them via TeX-like rules. See ?plotmath for more information. In your case you can use something like this:
plot(1:10, 1:10, type = "n")
text(5, 5, D(expression((x^3)/(2*(x+1))),"x"))
Upvotes: 2