suppressPackageStartupMessages(library(mosaic))
we have a demand function x, as a function of price, p: x(p)=800-4*p
#’ initial price is 40, rises to 60
a) find the price change dp
dp=60-40
the change in price is 20
b) make a function x(p)
x <- function(p) {800-4*p}
demand at p=40 is:
x(40)
## [1] 640
demand at p=60 is:
x(60)
## [1] 560
hence:
dx=x(60)-x(40)
the change in demand is -80
plot the function, this is the mathematical view of demand
plotFun(x(p)~p, xlim=range(0,100))
using ggplot
first make a dataframe
dframe <- data.frame(p=0:80,q=x(0:80))
ggplot(dframe, aes(x=p,y=q)) + geom_line() + ggtitle("Mathematical view of demand")
ggplot(dframe, aes(x=p,y=q)) + geom_line() + coord_flip() + ggtitle("Economist view of demand")
D(expression(800-4*p), "p")
## -4
the elasticity is slope*p/x(p), as a function
e <- function(p) {-4*p/x(p)}
in the price interval [40,60] it look like:
curve(e(x), 40,60, xlab = "p", ylab = "price elasticity")
with a mean value of:
mean(e(40:60))
## [1] -0.3355125
in the price interval [40,60] a price increase of 1% gives a 0.336 percent decrease in the quantity demanded
————————————–
d) x(p)=9.6 - 0.4*p, make a function X(p)
X <- function(p) {9.6-0.4*p}
the derivative or slope of the function is
D(expression(9.6 - 0.4*p), "p")
## -0.4
the elasticity is slope*p/x(p), as a function
E <- function(p) {-0.4*p/X(p)}
the demand function in the price interval [0,30]
curve(X(x), 0,20)
the elasticity in the price interval [0,15]
curve(E(x), 0,15, xlab = "p", ylab = "price elasticity")
it is equal to -1 with a price between [10,15]
-0.4*p/X(p) = -1 same as E(x)+1=0
findZeros(E(p)+1 ~ p, near = 10)
## p
## 1 12
## 2 24
at p=12, the elasticity is equal to -1
plot(0:15,E(0:15), type="l", xlab = "p", ylab = "price elasticity")
abline(h=-1, col="purple")
abline(v=12, col="red")