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}
R <- makeFun((10 + 0.5 * q) ~ q)
R
## function (q)
## (10 + 0.5 * q)
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)
library(ggplot2)
q_vals <- seq(-10, 10, 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 = "gray") +
geom_vline(xintercept = 0, linetype = "dashed", color = "gray") +
labs(title = "Graphs of C(q) and R(q)", x = "q", y = "Function Values") +
scale_color_manual(values = c("C(q)" = "blue", "R(q)" = "red")) +
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)
L_vals <- seq(0, 20, by = 0.1)
MP_vals <- MP(L_vals)
plot(L_vals, MP_vals, type = "l", col = "blue", lwd = 2,
xlab = "L", ylab = "MP",
main = " Marginal Product (MP)")
##3 ការបង្កើនប្រាក់ចំណេញអតិបរមា #3.1 ស្វែងរកបរិមាណ
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
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
4 ចំណុចស្រង់ដើម 4.1 ស្វែងរកបរិំមាណផលិត