2016-07-15 68 views
0

我想知道是否有一種方法來執行積分在數組中的R. 我有數組SR。我想將它們整合在壓力水平(P)從1000到850之間。我該怎麼做?如何計算一個數組的積分

enter image description here

SRP數據是

S<-structure(c(0.0011979939772106, 0.0011979939772106, 0.0011979939772106, 
0.00122851820731487, 0.00122654890214685, 0.00122457959697883, 
0.00124164690843498, 0.0, 0.0, 
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. 

回答

0

我不完全確定你在問什麼,但是在處理數組和集成時有兩個常見的答案。第一個是一個矢量化問題,它可以用以下方法處理:

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

​​