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.547721807 0.099520043 0.505518020 0.195295165 0.424793603
#> [6] 0.624717457 1.014509316 0.813836611 0.813254488 0.537444952
#> [11] 0.757721865 0.057386286 0.182606180 -0.096805128 -0.262871251
#> [16] -0.256740518 0.610016295 -0.428789489 0.815336843 0.906808065
#> [21] 0.464712498 0.323848343 -0.657137383 -0.257045899 0.034814972
#> [26] 0.602140478 -0.507064503 1.049243411 0.006896857 0.662123837
#> [31] 0.035230835 0.573031549 0.349087211 1.320197289 0.689315970
#> [36] 0.661211245 -0.102108143 -0.069421185 0.126074593 -0.209900358
#> [41] 1.188188480 -0.554438444 0.135302739 0.775521751 0.944766280
#> [46] 0.256649385 0.880902474 0.109384966 -0.083368429 -0.465541345
#> [51] 0.532344444 0.783668169 1.248926295 -0.036863707 0.539209673
#> [56] -0.728781075 0.464149910 0.694788239 0.610791219 0.438468563
#> [61] -0.344864101 0.359066984 -0.167017707 0.348046637 0.708258682
#> [66] 0.036942743 0.684083720 -0.102977174 0.265929499 0.627021477
#> [71] 0.095540883 1.386270390 1.669082941 0.810259042 -1.176032069
#> [76] 0.021341073 0.522922726 0.361280415 1.025656374 -0.370658312
#> [81] 0.361378803 0.620399500 -0.448308300 -0.158783769 0.412226706
#> [86] 0.201762355 1.072767473 -0.070422105 0.993813141 1.153086598
#> [91] 0.040532625 0.063419534 0.294521455 0.192872306 1.325262959
#> [96] -0.216470391 -0.059902599 -0.686754466 -0.597232936 -0.179523357