首页 > 解决方案 > 在数学函数中插入数学函数

问题描述

我想要:

  1. 将(函数)参数插入到数学函数中
  2. 以代数方式简化结果表达式

例子

func1 <-function(x,y) {
   return((x^3-3*x*y))
}

#input x=1/n and y=1/n
#the desired result should be
#1st: (1/n)^3-3*(1/n)*(1/n)
#2nd: 1/n^3 - 3/n^2 = 1/n^2*(1/n - 3)

有任何想法吗?

标签: rfunctionmath

解决方案


尝试这个:

library(Ryacas)

n <- ysym("n")
x <- 1/n
y <- 1/n
simplify(x^3-3*x*y)
## y: ((-3)*n^3+n^2)/n^5

推荐阅读