I need to construct a function with x values coming from the first column of this matrix below and y values coming from the second column from the same matrix, with the purpose
When I looked at you provide matrix (better use variable mat
not matrix
for it), I found that your x
samples are evenly spaced, and y
values are monotone and smooth against x
. So a simple linear interpolation would be sufficiently good to model those data.
## read `?approx`
f <- approxfun(mat[, 1], mat[, 2])
Then you can do
integrate (f, lower = 0.08, upper = 0.15)
# -0.2343698 with absolute error < 1.3e-05