Carregando WebR (~10s na primeira vez)...
Edite o código e clique "Executar"
R
# Maximização de Lucro — A firma do rodízio de pizza # Cap. 1, Seção 1.7 # Parâmetros (altere!) P <- 30 # preço por pizza vendida custo_fixo <- 200 # custo fixo (aluguel do forno) # Custo variável: CV(q) = 2*q^2 (custo marginal crescente) CV <- function(q) 2 * q^2 CT <- function(q) custo_fixo + CV(q) CMg <- function(q) 4 * q # derivada de CV Receita <- function(q) P * q Lucro <- function(q) Receita(q) - CT(q) # Solução: CMg = P => 4q = P => q* = P/4 q_star <- P / 4 lucro_max <- Lucro(q_star) cat("=== Maximização de Lucro ===\n") cat(sprintf(" P = R$ %.0f por pizza\n", P)) cat(sprintf(" q* = %.1f pizzas (CMg = P)\n", q_star)) cat(sprintf(" Receita = R$ %.0f\n", Receita(q_star))) cat(sprintf(" Custo Total = R$ %.0f\n", CT(q_star))) cat(sprintf(" Lucro = R$ %.0f\n\n", lucro_max)) # CPO: dπ/dq = P - CMg = 0 cat("Verificação CPO: P - CMg(q*) =", P - CMg(q_star), "✓\n") # CSO: d²π/dq² = -dCMg/dq = -4 < 0 ✓ cat("CSO: d²π/dq² = -4 < 0 ✓ (é máximo)\n") # Gráfico q <- seq(0, 15, length.out = 300) par(mfrow = c(1, 2), mar = c(4, 4, 3, 1)) # Painel 1: Receita, Custo, Lucro plot(q, Receita(q), type = "l", col = "#2a7f2a", lwd = 2, xlab = "Quantidade (q)", ylab = "R$", main = "Receita, Custo e Lucro", ylim = c(-200, 400)) lines(q, CT(q), col = "#C8102E", lwd = 2) lines(q, Lucro(q), col = "#ff9800", lwd = 2, lty = 2) abline(h = 0, col = "gray", lty = 3) points(q_star, lucro_max, pch = 19, col = "#ff9800", cex = 1.5) legend("topleft", legend = c("Receita", "CT", "Lucro"), col = c("#2a7f2a","#C8102E","#ff9800"), lwd = 2, lty = c(1,1,2), cex = 0.8) # Painel 2: P e CMg plot(q, CMg(q), type = "l", col = "#C8102E", lwd = 2, xlab = "Quantidade (q)", ylab = "R$/pizza", main = "P = CMg", ylim = c(0, 60)) abline(h = P, col = "#2a7f2a", lwd = 2) points(q_star, P, pch = 19, col = "#333", cex = 1.5) text(q_star + 1, P + 3, sprintf("q*=%.1f", q_star), font = 2) legend("topleft", legend = c("CMg(q)", "P"), col = c("#C8102E","#2a7f2a"), lwd = 2, cex = 0.8)
Executar (R)
Restaurar código original
Saída do R
Aguardando execução...
WebR
executa R no navegador. Altere o preço P e veja q* mudar. Se P cair abaixo de quanto, a firma tem prejuízo?