【问题标题】:Is it possible to have symbolic expressions output in TeX form是否可以以 TeX 形式输出符号表达式
【发布时间】:2011-12-30 07:50:05
【问题描述】:

假设我正在对R 中的表达式求导:

 D(expression((x^3)/(2*(x+1))),"x")

输出是:

3 * x^2/(2 * (x + 1)) - (x^3) * 2/(2 * (x + 1))^2

我想知道这个输出是否可以以更易于阅读的 TeX 形式显示在屏幕上。

谢谢。

【问题讨论】:

    标签: r tex


    【解决方案1】:

    查看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}} $
    

    编辑:或

    > 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) } $
    

    【讨论】:

      【解决方案2】:

      好吧,标准的文本绘图例程接受“表达式”类型的参数并通过类似 TeX 的规则来解释它们。有关更多信息,请参见 ?plotmath。在你的情况下,你可以使用这样的东西:

      plot(1:10, 1:10, type = "n")
      text(5, 5,  D(expression((x^3)/(2*(x+1))),"x"))
      

      【讨论】:

        猜你喜欢
        • 2011-08-25
        • 1970-01-01
        • 2017-04-19
        • 2014-09-12
        • 1970-01-01
        • 1970-01-01
        • 2015-04-20
        • 1970-01-01
        • 2022-07-31
        相关资源
        最近更新 更多