r - How to loop a function with sapply? -


i calculate roots different y-values of quadratic equation. when run following code error not understand. if y 1 numeric value, instead of vector c(0.6,0.4,0.9), works. using sapply wrongly or passing of variables function wrong?

# paramters 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 list of y values res<-sapply(y,root) 

you can example :

 sapply(y,function(y) uniroot(fun,c(0,2),y=y,c=c,a=a,b=b)) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -