I want to plot a self-defined function in R using two vectors and an unknown variable. I thought about something like this:
# Define parameters
b<-c(1.70,4.70,7.60)
w<-c(0.38,0.44,0.50)
# Define function
k<-function(x){0.07*(w*(1-(x/-33)^(1/b)))^4}
# Plot
plot(k)
The goal is to plot the function, getting three lines. One line should contain the first pair of the b-vector/w-vector, the second line should contain the second pair and the third line should contain the last pair of the vectors. When I compile the code I get an error message:
1: In (x/-33)^(1/b) : longer object length is not a multiple of shorter object length 2: In w * (1 - (x/-33)^(1/b)) : longer object length is not a multiple of shorter object length
My idea was, that R wants to combine all the values from each vector with each other, which leads to the error message. Is there a way around the error?
(x/-33)^(1/b)
is going to give youNaN
for x > 0 and your values ofb
. Sinceplot.function
plots values for x in [0, 1] by default, you're not going to see anything on your plot. - Weihuang Wong