二次方程式のさまざまな y 値の根を計算したいと思います。しかし、次のコードを実行すると、理解できないエラーが発生します。y がベクトル c(0.6,0.4,0.9) の代わりに 1 つの数値である場合、それは機能します。私は sapply を間違って使用していますか、それとも関数への変数の受け渡しが間違っていますか?
# Paramters for quadratic poly
a<-0.875
b<-0.3779
c<-0.098
y<- c(0.6,0.4,0.9)
# quadratic function
fun<-function(x) c-y+b*x+a*x^2
# Finding root in specific interval function
root<- function (x) uniroot(fun,c(0,2))$root
# Finding roots for a list of y values
res<-sapply(y,root)