Reputation: 705
I would like to plot a function several times, each time changing a parameter (a constant) in the function. How can i do this?
fun1 <- function(x, b) abs(x^2 - b^2)
plot(fun1(b=0.1),-1, 1)
plot(fun1(b=0.2),-1, 1, add=TRUE)
Upvotes: 0
Views: 269
Reputation: 121568
Same approach just generalized in a for-loop
:
for (b in c(0.1,0.2))curve(abs(x^2 - b^2),add=TRUE,col='red')
Upvotes: 2
Reputation: 2589
try this:
curve(abs(x^2 - 0.1^2), -1, 1)
curve(abs(x^2 - 0.2^2), -1, 1, add = TRUE)
Upvotes: 1