Building a function by defining X and Y and then Integrating in R

后端 未结 1 324
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 06:58

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

1条回答
  •  终归单人心
    2021-01-24 07:38

    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
    

    0 讨论(0)
提交回复
热议问题