Chandan Chaurasiya
Chandan Chaurasiya

Reputation: 1

Finite Double integration in R- Studio Error

I want to integrate a two variable function in R studio using "cubature" package in R but when submitting code getting the error. I don't know whether the problem is in writing function or using function. I have given the two codes that I am using followed by the error in italic font;

  1. Code:

f10 <- function(x, y) {1/(sqrt(1- x^2) * sqrt(1 - y^2))}

(a10 <- adaptIntegrate(f10, lower = c(0, 0), upper = c(1, 1))$integral)

Error :
Error in f(x, ...) : argument "y" is missing, with no default Called from: f(x, ...)

  1. Code:

f10 <- function(x) {1/(sqrt(1- x^2) * sqrt(1 - y^2))}

(a10 <- adaptIntegrate(f10, lower = c(0, 0), upper = c(1, 1))$integral)

Error:
Error in f(x, ...) : object 'y' not found Called from: f(x, ...)

Please Help!

Upvotes: 0

Views: 75

Answers (1)

user2554330
user2554330

Reputation: 44927

The argument to f10 needs to be a single vector, not two scalars. For example,

library(cubature)
f10 <- function(x) {
  1/(sqrt(1- x[1]^2) * sqrt(1 - x[2]^2))
}
adaptIntegrate(f10, 
               lower = c(0, 0), 
               upper = c(1, 1))$integral
#> [1] 2.467393

Created on 2021-10-24 by the reprex package (v2.0.0)

Upvotes: 0

Related Questions