The image illustrates my plotting objective. On this image, ignore the vertical slope on x1. total non-sense. The function is simply not defined after x takes on value x1 or greater OR y results in 0.
I'm having the following piecewise linear function with two conditions. How do you plot that in R? Semantically I want to make the statement: "if x equals or is greater than 20(x1), y must be zero, otherwise y equals mx+y1−mx1." . This slope muss decrease and set y to zero at 20.
f ( x ) = { m x + y 1 − m x 1 if 0 ≤ x < x 1 0 if x ≥ x 1So far, i tried this (uncertain how to set y1)
m <- -2
x1 <- 20
y1 <- ???
x <- seq(0, 100, 1)
fx <- (0 <= x & x < x1) * (m*x + y1 - m*x) + (x >= x1) * 0
plot(x, fx)
Of course, this results in an error.
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
I'm uncertain how to represent the y and y1.