绘制包含积分的函数

Hun*_*ung 1 plot r

我想曲线函数v定义如下:

u<-function(x){log(x^2+1)}

v<-function(x){integrate(v,0,x)}
Run Code Online (Sandbox Code Playgroud)

当我使用该命令时curve(v,1,2,10),结果是

Error in curve(v, 1, 2, 10) : 
  'expr' did not evaluate to an object of length 'n' 
Run Code Online (Sandbox Code Playgroud)

请帮我绘制函数v的曲线.

Rui*_*das 5

你有一个错字,应该是integrate(u, ...),不是v.
你必须有函数v返回一个向量.像这样:

u <- function(x){log(x^2+1)}

v <- function(x){
    sapply(x, function(.x) integrate(u, 0, .x)$value)
}

curve(v, from = 1, to = 2, n = 10)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述