Carregando WebR...
# ============================================ # Curvas de Custo: CT, CMe, CMg, CVMe # Funcao cubica classica # ============================================ # Parametros da funcao de custo cubico # CT(q) = CF + a*q + b*q^2 + c*q^3 CF <- 100 # custo fixo a <- 10 # coef. linear b <- -2 # coef. quadratico (negativo => fase de rendimentos crescentes) c <- 1/3 # coef. cubico # Altere os parametros acima e re-execute! q <- seq(0.01, 8, length = 500) CT <- CF + a*q + b*q^2 + c*q^3 CV <- a*q + b*q^2 + c*q^3 CMe <- CT / q CVMe <- CV / q CFMe <- CF / q CMg <- a + 2*b*q + 3*c*q^2 # Pontos especiais # Minimo do CVMe: dCVMe/dq = 0 => a/q^2... ou CMg = CVMe # CMg = CVMe => a + 2bq + 3cq^2 = a + bq + cq^2 => bq + 2cq^2 = 0 => q(b + 2cq) = 0 q_min_CVMe <- -b / (2*c) # Minimo do CMe: CMg = CMe => CF/q + bq + 2cq^2 = 0 (resolver numericamente) f_diff <- function(q) CMg_f(q) - CMe_f(q) CMg_f <- function(q) a + 2*b*q + 3*c*q^2 CMe_f <- function(q) CF/q + a + b*q + c*q^2 q_min_CMe <- uniroot(function(q) CMg_f(q) - CMe_f(q), c(1, 8))$root cat("====== PONTOS CRITICOS ======\n") cat("Min CVMe em q =", round(q_min_CVMe, 2), " | CVMe =", round(a + b*q_min_CVMe + c*q_min_CVMe^2, 2), "\n") cat("Min CMe em q =", round(q_min_CMe, 2), " | CMe =", round(CMe_f(q_min_CMe), 2), "\n") cat("CMg no min CMe =", round(CMg_f(q_min_CMe), 2), " (= CMe, OK!)\n") cat("CMg no min CVMe =", round(CMg_f(q_min_CVMe), 2), " (= CVMe =", round(a + b*q_min_CVMe + c*q_min_CVMe^2, 2), ", OK!)\n") # --- Graficos --- par(mfrow = c(1, 2), mar = c(4.5, 4.5, 3, 1), bg = "#f8f9fa") # Painel 1: Custo Total plot(q, CT, type = "l", lwd = 3, col = "#0d6efd", xlab = "q", ylab = "$", main = "Custo Total", ylim = c(0, max(CT) * 1.05), cex.lab = 1.1) lines(q, CV, lwd = 2, col = "#198754", lty = 2) abline(h = CF, col = "#dc3545", lty = 3, lwd = 1.5) text(0.5, CF, paste("CF =", CF), pos = 3, col = "#dc3545", cex = 0.85) legend("topleft", legend = c("CT", "CV", "CF"), col = c("#0d6efd", "#198754", "#dc3545"), lwd = c(3, 2, 1.5), lty = c(1, 2, 3), cex = 0.85, bg = "white") # Painel 2: Custos medios e marginal ylim2 <- c(0, max(CMe[q > 0.5]) * 1.1) plot(q, CMe, type = "l", lwd = 3, col = "#0d6efd", xlab = "q", ylab = "$/unidade", main = "CMe, CVMe e CMg", ylim = ylim2, cex.lab = 1.1) lines(q, CVMe, lwd = 2, col = "#198754") lines(q, CMg, lwd = 2, col = "#dc3545", lty = 2) lines(q, CFMe, lwd = 1.5, col = "#6c757d", lty = 3) # Marcar cruzamentos points(q_min_CVMe, CMg_f(q_min_CVMe), pch = 19, col = "#fd7e14", cex = 1.5) points(q_min_CMe, CMg_f(q_min_CMe), pch = 19, col = "#6f42c1", cex = 1.5) text(q_min_CVMe, CMg_f(q_min_CVMe), paste0(" Ponto de\n fechamento\n q=", round(q_min_CVMe, 1)), pos = 4, cex = 0.75, col = "#fd7e14", font = 2) text(q_min_CMe, CMg_f(q_min_CMe), paste0(" Min CMe\n q=", round(q_min_CMe, 1)), pos = 4, cex = 0.75, col = "#6f42c1", font = 2) legend("topright", legend = c("CMe", "CVMe", "CMg", "CFMe"), col = c("#0d6efd", "#198754", "#dc3545", "#6c757d"), lwd = c(3, 2, 2, 1.5), lty = c(1, 1, 2, 3), cex = 0.8, bg = "white")
▶ Executar
↻ Resetar
(Aguardando WebR...)