I am defining a function and trying to plot it for x > max{b1,b2}
:
b1<-1
b2<-2
b<-1
l<-1
fn <- function(x,b1,b2,b,l){
result <- b/x * ((1-(sqrt(1-(b1/x)^l)*sqrt(1-(b2/x)^l)))^(- 1/l))
return(result)
}
fn1 <- fn(x,b1,b2,b,l)
x<-seq(3,20,0.1)
plot(x,fn1,type="l")
It's working for these values but when I am changing x as follows x<-seq(3,100,0.1), it's showing an error:
Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
Can you suggest what is the mistake here? How it can be removed?
Not sure what operation do you want after the b/x term, but It reads the [ ] as an index, try:
fn <- function(x,b1,b2,b,l){
result <- b/x * (1-(sqrt(1-(b1/x)^l)*sqrt(1-(b2/x)^l)))**(- 1/l)
return(result)
}
the results line in your function has improper syntax. it should be as follows
result <- b/x*(1-(sqrt(1-(b1/x)^l)*sqrt(1-(b2/x)^l)))*(- 1/l)
Note the differences:
[ ]
are used as they have a different meaning than ( )
in R.*
have been fixed throughout
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.