R plotting integral

痴心易碎 提交于 2019-11-29 15:34:30

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!