R plotting integral

后端 未结 1 1272
暗喜
暗喜 2020-12-21 18:00

I\'m having some problems with integration function in R. I\'m trying to plot the integral vo but it seems I\'m not doing correctly.

t <- seq(0, 0.04, 0.0         


        
相关标签:
1条回答
  • 2020-12-21 18:21

    You are already there. Just use plot(t, test_vect(t)). You can't use vo, as integrate is not a vectorized function. There is no problem to evaluate a single point like vo(0.002), but you can not feed it a vector by vo(t). This is why we want Vectorize(vo)(t).

    You said that test_vect is not giving the right plot. Sure? We can analytically compute the integral:

    v <- function (x) (1-cos(100*pi*x)) / (20*pi)
    

    Then let's compare:

    sum(abs(v(t) - test_vect(t)))
    # [1] 2.136499e-15
    

    They are the same!

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