-1

I have a question, whether is it possible in R to implement the Excel "search of the decision function"? It is necessary to create a script in R to solve an integral equation.

To solve 4 integrals below manually I just need paper, a pencil and 10 minutes:

Improper:

Double:

Triple:

Definite:

So I don't want solve the integrals like these manually, how can it be solved using R?

LATEX formala editor code:

improper
\int_{2}^{\infty} \frac{1}{\left(x - 1\right)^{2}}\, dx


double integrals
\int_{0}^{1}\int_{\frac{-1 x}{2}}^{\frac{x}{2}} e^{- x - y}\, dy\, dx

triple integrals
\int_{0}^{1}\int_{\frac{-1 x}{2}}^{\frac{x}{2}}\int_{\frac{-1 y}{3}}^{\frac{y}{3}} e^{- z + - x - y}\, dz\, dy\, dx

definite integrals
\int_{0}^{1} x^{2} \sin{\left (x \right )}\, dx
Artem
  • 3,304
  • 3
  • 18
  • 41
psysky
  • 3,037
  • 5
  • 28
  • 64
  • Using something like the `integrate()` function? – user2974951 Sep 25 '18 at 10:34
  • If by "search of the decision" you mean [Goal Seek](https://support.office.com/en-us/article/Use-Goal-Seek-to-find-the-result-you-want-by-adjusting-an-input-value-320cb99e-f4a4-417f-b1c3-4f369d6e66c7), that functionality is (more or less) implemented in the base R functions `uniroot` and `optimize`. For more sophisticated optimization problems (which would require the Solver in Excel), there are [many optimization packages](https://cran.r-project.org/web/views/Optimization.html) which could be used. – John Coleman Sep 25 '18 at 10:53
  • @JohnColeman, yes there is many packages. What of them is for integral task? – psysky Sep 26 '18 at 08:50
  • @G-spot, could you post your integrals in better resolution or post them in text format (difficult to recognize limits). – Artem Sep 29 '18 at 17:44
  • @Artem, i edited post with latex code and link to latex editor. Please check edit. – psysky Oct 04 '18 at 11:08
  • I corrected some formatting and upvoted. – Artem Oct 04 '18 at 18:07
  • @Artem, do you know how to find desicion? If yes can you help me? – psysky Oct 07 '18 at 13:48

1 Answers1

1

You can use rSymPy package to integrate all four expresisions as below:

Improper:

library(rSymPy)

x <- Var("x")

sympy("integrate(1 / (x - 1) ** 2, (x, 2, oo))")
# [1] "1"

Double:

library(rSymPy)

x <- Var("x")
y <- Var("y")

# double
sympy("integrate(exp(-x - y), (y, -x/2, x/2), (x, 0, 1))")
# [1] "4/3 + 2*exp(-3/2)/3 - 2*exp(-1/2)"

Triple:

library(rSymPy)

x <- Var("x")
y <- Var("y")
z <- Var("z")

sympy("integrate(exp(-x - y - z), (z, -y/3, y/3), (y, -x/2, x/2), (x, 0, 1))")
# [1] "-27/40 - 9*exp(-5/3)/20 + 9*exp(-4/3)/8 - 9*exp(-2/3)/4 + 9*exp(-1/3)/4"

Definite:

library(rSymPy)

x <- Var("x")

sympy("integrate(x ** 2 * sin(x), (x, 0, 1))")
# [1] "-2 + 2*sin(1) + cos(1)"
Artem
  • 3,304
  • 3
  • 18
  • 41
  • very great. I am surprised. – psysky Oct 07 '18 at 17:17
  • may i ask you to help with similar question, if it is not so difficulst of course https://stackoverflow.com/questions/52905102/search-desicion-function-for-differential-equations-system – psysky Oct 20 '18 at 11:22
  • @G-spot, no page available. – Artem Oct 21 '18 at 14:18
  • i opened it, but post in put on hold :( https://stackoverflow.com/questions/52905102/search-desicion-function-for-differential-equations-system – psysky Oct 21 '18 at 14:31
  • Can you add answer in here post?, cause it similar – psysky Oct 21 '18 at 14:32
  • @G-spot, I'll have a look at your post during this week. Meanwhile I recommend you to edit your question. You can take as a sample the formatting of your question on integration. – Artem Oct 21 '18 at 22:51