library(mosaic)
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
library(mosaicCalc)
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D

បំរាប

p <- function(q) {(10 + 0.5 * q)~q}
C <- function(q) {(100 + 10 * q + 0.5 * q^2)~q}

1. រកអនុគមន៍ចំណូល

R <- makeFun((10 + 0.5 * q) ~ q)
R
## function (q) 
## (10 + 0.5 * q)

2. រកអនុគមន៌ប្រាក់ចំណេ

P <- makeFun ((10 + 0.5 * q)-(100 + 10 * q + 0.5 * q^2)~q)
P
## function (q) 
## (10 + 0.5 * q) - (100 + 10 * q + 0.5 * q^2)

3. សង់ក្រាប

library(ggplot2)
q_vals <- seq(-20, 70, length.out = 100)
C_vals <- 100 + 10 * q_vals + 0.5 * q_vals^2
R_vals <- 10 + 0.5 * q_vals
df <- data.frame(q = q_vals, Cq = C_vals, Rq = R_vals)
ggplot(df, aes(x = q)) +
  geom_line(aes(y = Cq, color = "C(q)"), size = 1) +
  geom_line(aes(y = Rq, color = "R(q)"), size = 1) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black") +
  geom_vline(xintercept = 0, linetype = "dashed", color = "black") +
  labs(title = "Graphs of C(q) and R(q)", x = "q", y = "Function Values") +
  scale_color_manual(values = c("C(q)" = "yellow", "R(q)" = "blue")) +
  theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

# 2. រកដេរីវេ C,R,P

C<-makeFun((100 + 10 * q + 0.5 * q^2) ~ q)
MC=D(C(q)~q)
MC
## function (q) 
## q + 10
MR= D(R(q)~q)
MR
## function (q) 
## 0.5
MP= D(P(q)~q)
MP
## function (q) 
## -(q + 9.5)

Graphic 1

MC <- function(q) {
 10 + q
}

MR <- function(q) {
 20 - q
}

# បង្កើតចន្លោះ q
q_vals <- seq(0, 20, by = 0.1)

# គណនាតម្លៃ MC(q) និង MR(q)
MC_vals <- MC(q_vals)
MR_vals <- MR(q_vals)

# គូសក្រាប
plot(q_vals, MC_vals, type = "l", col = "pink", lwd = 2, xlab = "q", ylab = "Cost/Revenue", main = "Graphs of MC and MR")
lines(q_vals, MR_vals, col = "black", lwd = 2)
legend("topright", legend = c("MC(q)", "MR(q)"), col = c("pink", "black"), lwd = 2)

## Graphic 2

L_vals <- seq(0, 20, by = 0.1)
MP_vals <- MP(L_vals)
plot(L_vals, MP_vals, type = "l", col = "red", lwd = 2,
     xlab = "L", ylab = "MP",
     main = " Marginal Product (MP)")

### Find the amount that makes the most profit (P)

library(Deriv)
R <- function(q) {
 (100 - 2 * q) * q
}
profit <- function(q) {
 R(q) - C(q)
}
profit_prime <- Deriv(profit)
q_optimal <- uniroot(function(q) profit_prime(q), c(0, 50))$root
q_optimal
## [1] 18

Calculate the maximum accuracy

R <- function(q) {
 (100 - 2 * q) * q
}
C <- function(q) {
 50 + 20 * q + q^2
}
profit <- function(q) {
 R(q) - C(q)
}
profit_prime <- Deriv(profit)
q_optimal <- uniroot(function(q) profit_prime(q), c(0, 50))$root
q_optimal
## [1] 13.33333

Excerpt

Find the production volume that makes P(q)= 0