0

So I am relatively new to R and wanted to know if there is any way to get a result expressed in terms of exp(x). For example: I have the following code:

library(calculus)

f <- function(x, y) 2*exp(5*x+1*y)
taylor(f, var = c(x = 3, y = 6), order = 2)

Now the result of this looks something like:

$f
'(2637631468.96643) * 1 + (2637631469.04) * (y-6)^1 + (13188157344.5581) * (x-3)^1 + (1318815733.78693) * (y-6)^2 + (32970392681.9538) * (x-3)^2 + (13188156507.7521) * (x-3)^1*(y-6)^1'

Is there any way to get the result in the form of:

(294e30) * (x - 3) + (35e30) * y + ...

, i.e., in terms of e (Euler)?

Flash1232
  • 384
  • 1
  • 3
  • 18

1 Answers1

0

You can do the following:

library(calculus)

f <- function(x, y) 2*exp(5*x+1*y)
tlr <- taylor(f, var = c(x = 3, y = 6), order = 2)
trms <- tlr$terms
trms$coef <- signif(trms$coef, digits = 3)
temp <- paste(formatC(trms$coef), '*', trms$var)
tlr$terms <- trms
tlr$f <- paste(temp, collapse = " + ")
tlr
Recap_Hessian
  • 368
  • 1
  • 10
  • Although I appreciate your constructive answer, this is not what I want. I am talking about the Euler base, not the scientific notation (e+xxx). You may as well replace it with Pi. So then you would get `14π^30` or something... – Flash1232 May 12 '21 at 13:07
  • @Flash1232 Not sure I understand. Euler's e _is_ exp(1). Do you also want to have it in any custom basis such as $\pi$? – Recap_Hessian May 12 '21 at 13:30
  • Using python, you get the desired output using the sympy series().removeO() function. It will output a fully factored and simple term that has no decimals in it. It expresses the term in terms of e^x instead of the raw values. – Flash1232 May 12 '21 at 14:01
  • @Flash1232 I am not aware of that, but the reason this here is more appropriate is because we control the number of significant digits. Your desired representation looks nice but may not be consistent across different terms. – Recap_Hessian May 12 '21 at 14:06