我是R编程的新手,我遇到了一个数学问题,我在R中毫无头绪。
该问题要求绘制y=max{g(x),0.5x}
的图形,以获取x
的10001个值(在-10与10之间)
这是我到目前为止从t.f示例中尝试过的内容:
first.func <- function(x) {
if (x < 0){
return(x)
}
else if (x = 0){
return(0)
}
else
return(x)
}
second.func <- function(x) {
return(max(first.func(x), x * sin(1/x)))
}
x <- seq(-10, 10, length=10001)
y <- sapply(0.5 * x, second.func)
plot(y ~ x, type = 'l')
答案 0 :(得分:1)