How do I chart the production function of Cobb-Douglas in the R?

Asked

Viewed 233 times

3

I would like to draw up the graph for the Cobb-Douglas production function in the R,:

P(L, K) = 1,01L 0,75 k 0,25

Where L and K vary between 0 and 300.

2 answers

3

Here is one of the infinite possibilities to accomplish what you want:

# criar uma função
P = function(L, K) {
  return(1.01 * L^0.75 * K^0.25 )
}

# Variáveis
L = K = 0:300

# definir amostra de uma variável para plotar em função da outra
amostra <- seq(0, 300, 20)

# definir cores
cols <- rainbow(length(amostra))

# 2 plots
par(mfrow = c(1, 2), mar = c(3,3,0.5,0.5), mgp = c(1.5, 0.3, 0), tck = -.008)

# L
plot(0, pch = '', xlim = c(0, 300), ylim = c(0, 200), xlab = 'L', ylab = 'F(L, K)')
for(k in 1:length(amostra)) {
  points(L, P(L, K[k]), type = 'l', col = cols[k])
}
legend('topleft', legend = amostra, title = 'K', lty = 1, col = cols, bty = 'n', cex = 0.7)

# K
plot(0, pch = '', xlim = c(0, 300), ylim = c(0, 100), xlab = 'K', ylab = 'F(L, K)')
for(l in 1:length(amostra)) {
  points(K, P(L[l], K), type = 'l', col = cols[l])
}
legend('topleft', legend = amostra, title = 'L', lty = 1, col = cols, bty = 'n', cex = 0.7)
  • Perfect, thank you very much!

3


This answer needs the package plot3D installed. If not already installed, you can do so with

install.packages("plot3D")

First I define a function cobbDouglas quite general, which also accepts as arguments the constant A and the exponents alpha and beta.

cobbDouglas <- function(K, L, A, alpha, beta){
  A * L^beta * K^alpha
}

Now it is first to calculate the function values, with outer().

L <- 0:300
K <- 0:300
Z <- outer(K, L, cobbDouglas, A = 1.01, alpha = 0.25, beta = 0.75)

And plot the graph with plot3D::persp3D. Before that I reset the values of the margins to have more space for the graph and at the end restore the graphical parameters as they were.

op <- par(bg = "white", mar = c(1, 1, 1, 2) + 0.1)
plot3D::persp3D(L, K, Z, theta = 30, phi = 30, 
                expand = 0.5, col = rainbow(100))
par(op)

inserir a descrição da imagem aqui

  • Perfect, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.