Trapezoidal rule to approximate an integral.
integrate_trapeze(x, y)
a numerical vector, the discretization of the domain.
a numerical value, the discretization of the function to integrate.
a numerical value, the approximation.
x <- seq(0,1,le=1e2)
integrate_trapeze(x,x^2)
#> [1] 0.3333503
integrate_trapeze(data1$grids[[1]],t(data1$x[[1]]))
#> [1] 0.765079346 -0.523121394 0.110162421 0.511359289 -0.076194125
#> [6] 0.447061420 1.195513927 -0.714186172 0.108260962 -0.453690367
#> [11] 0.444751285 0.932100611 0.484307967 0.559383181 0.747189010
#> [16] 0.130294931 0.742418349 -0.367985937 0.585063522 0.047428909
#> [21] 0.833092171 0.699780729 0.204685357 -0.181267655 -0.405452489
#> [26] -0.116764670 -0.338860486 0.723251161 0.151995527 -0.085662035
#> [31] 0.135661583 0.751428785 1.236231229 -0.091728601 1.326770124
#> [36] 0.807169443 0.651132111 0.471232361 0.743546958 -0.095618061
#> [41] -0.350846179 0.526363005 -0.119156655 0.759310899 0.594419369
#> [46] 0.394152962 0.043590128 0.118649164 0.039093021 0.953720396
#> [51] 0.419098166 0.048841866 0.815175917 0.475707916 1.565346201
#> [56] 0.247705062 0.716300292 -0.002235022 -0.117133144 -0.364707069
#> [61] 0.341318004 -0.755102928 -0.018109197 0.030548350 0.465919302
#> [66] -0.585647073 0.236361198 0.424777787 -0.019647527 1.126328518
#> [71] -0.018765451 0.360326074 0.523242926 0.515121445 0.970761443
#> [76] -0.214991107 0.723206670 0.914546246 0.475460418 0.115811401
#> [81] 0.949779314 0.804449487 0.914315265 -0.009495039 -0.220266642
#> [86] 0.782648023 0.419840231 0.487560509 0.552263538 0.473403065
#> [91] 0.807408627 0.553560418 0.621720805 1.662158676 -0.183335683
#> [96] 0.999037788 0.425226621 0.642306066 0.046729330 0.667871861