How to calculate the area under each end of a sine curve

后端 未结 2 736
你的背包
你的背包 2021-01-15 18:27

Given this data set:

y<-c(-13,16,35,40,28,36,43,33,40,33,22,-5,-27,-31,-29,-25,-26,-31,-26,-24,-25,-29,-23,4)
t<-1:24

My goal is to c

2条回答
  •  有刺的猬
    2021-01-15 19:12

    This may not be the solution you are looking for, but you could try this:

    # Create a new t vector but with more subdivisions
    t2 = seq(1,24,length.out = 10000)
    
    # Evaluate your model on this t2
    y2 = predict(reslm2, newdata = data.frame(t = t2))
    
    lines(t2[y2>=0],y2[y2>=0],col="red")
    
    # Estimate the area where the curve is greater than 0 
    sum(diff(t2)[1]*y2[y2>0])
    
    # Estimate the area where the curve is less than 0
    sum(diff(t2)[1]*y2[y2<0])
    

提交回复
热议问题