【问题标题】:How to compute integral of an array如何计算数组的积分
【发布时间】:2016-07-15 17:58:36
【问题描述】:

我想知道是否有一种方法可以对 R 中的数组执行积分。 我有数组SR。我想将它们整合到从 1000 到 850 的压力水平 (P)。我该怎么做?

.

SRP 数据是

S<-structure(c(0.0011979939772106, 0.0011979939772106, 0.0011979939772106, 
0.00122851820731487, 0.00122654890214685, 0.00122457959697883, 
0.00124164690843498, 0.00123705186304294, 0.0012324568176509, 
0.00133617355649982, 0.00133617355649982, 0.00133617355649982, 
0.00138048292278021, 0.00137752896502818, 0.00137457500727616, 
0.00140575567243643, 0.00139951953940438, 0.00139328340637232, 
0.00139820666929237, 0.00139820666929237, 0.00139820666929237, 
0.00151308280409338, 0.00150192340814128, 0.00149076401218919, 
0.00155575108273376, 0.00154426346925366, 0.00153277585577356
), .Dim = c(3L, 3L, 3L))
R<-structure(c(-15.1752538162522, -15.1929331135921, -15.2092524649828, 
-16.2142525214608, -16.2400914944961, -16.2604906837345, -17.2355719293295, 
-17.2641307942633, -17.2858899294509, -13.3842050011216, -13.4059641363092, 
-13.4250033795984, -14.3266475439352, -14.3361671655798, -14.3402470034274, 
-15.3466070058547, -15.3398072761085, -15.3262078166163, -10.7132711568418, 
-10.7350302920294, -10.7554294812678, -11.8379464568517, -11.8066677000195, 
-11.7726690512888, -13.8003484615847, -13.7187517046312, -13.6317151638807
), .Dim = c(3L, 3L, 3L))
P<-c(1000,950,900,850)

我尝试了以下方法,但无法弄清楚如何对数组执行积分。

f <- function(x) {x}
inr <- integrate(f,1000,850) #where f would be a function.

【问题讨论】:

    标签: arrays r integral


    【解决方案1】:

    我不完全确定您在问什么,但是在处理数组和集成时有两个常见的答案。第一个是矢量化问题,可以通过以下方式处理:

    IntFunc <- function(x,y) {
      sum(x-y)
    }
    IntFunc(1:5,c(0,0))
    Warning message:
      In x - y : 
      longer object length is not a multiple of shorter object length
    integrate(Vectorize(IntFunc,vectorize.args = 'x'), upper = 1000, lower = 850, y = R)
    3803862 with absolute error < 4.2e-08
    

    此问题已在 StackOverflow 的其他地方得到解答:

    How to pass vector to integrate function

    R, Integrate at each point of array

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多