我试图运行包"rootSolve“的"uniroot”函数,以找到两个函数的交点。我的代码如下:
g1 <- function(x,y){x^2/y^2}
f1 <- function(x, y){ x^2-3*y+g1(x)}
f2 <- function(x, z){ 4*z-x^2 }
f <- function(x, y, z){
x^2-3*y-(4*z-x^2)
}
z <- 5;
y <- 3
rr=uniroot(f=f, y=y, z=z, interval=c(0,10))$root
rr问题是,当z和y是具有多个元素的向量时,例如:
z <- c(1, 2, 3)
y <- c(3, 4, 5)
rr=uniroot(f=f, y=y, z=z, interval=c(0,10))$root 计算显示以下消息:
f() values at end points not of opposite sign
In addition: Warning messages:
1: In if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
the condition has length > 1 and only the first element will be used
2: In if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
the condition has length > 1 and only the first element will be used 如何解决这个问题?
发布于 2015-10-01 09:23:08
尝试在包uniroot.all中使用rootSolve。它的方法论可以给你一个以上的答案。然后求解你的方程,以确保你得到了好的值。
https://stackoverflow.com/questions/26478504
复制相似问题