Lab#4

Lab#3 review

Plotting and Linear Programming

Code:

plot(x, y = NULL, type = "p",  xlim = NULL, ylim = NULL,
     log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
     ann = par("ann"), axes = TRUE, frame.plot = axes,
     panel.first = NULL, panel.last = NULL, asp = NA,
     xgap.axis = NA, ygap.axis = NA,
     ...)
curve(expr, from, to, n = 101, add = FALSE, type = “l”, ylab = NULL, log = NULL, …)

Example(plot): plot \(y=x^3-3x\) and \(y=x^2-2\) in the same graph for \(x \in [-2,2]\)

x=seq(-2,2,by=0.01)
f=function(x){x^(3)-3*x}
f_2=function(x){x^2-2}
plot(x,f(x),type="l")
lines(x,f_2(x),type="l",col="red")

#par(mfrow=c(2,2)) # combining plots create a 2*2  
curve(x^3-3*x, -2, 2)
curve(x^2-2, add = TRUE, col = "red")

Linear Programming question

Linear programming

Standard Form in matrix form: \[\begin{equation} \begin{split} \max \ C^Tx\\ s.t.\ \ Ax\le b\\ \ \ \ \ 0 \le x \end{split} \end{equation}\] Standard Form in scalar form: \[\begin{equation} \begin{split} \max \ c_1x_1+c_2x_2+...+c_nx_n&\\ s.t.\ \ a_{11}x_1+a_{12}x_2+.&..+a_{1n}x_n\le b_1\\ \ \ \ \ a_{21}x_1+a_{22}x_2+.&..+a_{2n}x_n\le b_2\\ &\vdots \\ \ \ \ \ a_{m1}x_1+a_{m2}x_2+.&..+a_{mn}x_n\le b_m\\ \ \ \ \ x_1,x_2,.&..,x_n \ge 0 \end{split} \end{equation}\] DUAL Form of LP problem:

The shadow prices solve another linear program, called the dual. If we have a standard form: \[\begin{equation} \begin{split} \max \ C^Tx\\ s.t.\ \ Ax\le b\\ \ \ \ \ 0 \le x \end{split} \end{equation}\] The corresponding DUAL form can be found as: \[\begin{equation} \begin{split} \min \ B^Ty\\ s.t.\ \ A^Ty\ge c\\ \ \ \ \ 0 \le y \end{split} \end{equation}\] In which, the decision variable y called the dual variables. Each decision variable in the primal problem corresponds to a constraint in the dual problem, and each constraint in the primal problem corresponds to a variable in the dual problem.

Example

  1. A chicken farmer wants to feed the chickens the minimum daily requirement of nutrients A, B and C at lowest costs. Daily requirements are 14 units of A, 10 of B and 6 of C. Feed grain X contains 1A, 1B and 1C, while feed grain Y contains 2A, 1B and ½C. The price of X = $0.67 and the price of Y = $1.00. The problem is to find the least-cost combination of X and Y that fulfills the minimum nutrient requirements.
  1. Provide an analytical representation of the mathematical programming problem.
  1. The primal problem in its ‘original’ form
  2. The primal problem in ‘standard’ form
  3. The dual representation of the problem

Solve linear optimization problem in R

Code:

lp (direction = "min", objective.in, const.mat, const.dir, const.rhs,
transpose.constraints = TRUE, int.vec, presolve=0, compute.sens=0,
binary.vec, all.int=FALSE, all.bin=FALSE, scale = 196, dense.const,
num.bin.solns=1, use.rw=FALSE)

Simple Example: \[\begin{equation} \max\ x_1 + 9x_2 + x_3\ subject\ to\\ x_1 + 2x_2 + 3x_3 \le 9\\ 3x_1 + 2x_2 + 2x_3 \le 15\\ \end{equation}\]

library("lpSolve")
f.obj <- c(1, 9, 1)
f.con <- matrix (c(1, 2, 3, 3, 2, 2), nrow=2, byrow=TRUE)
f.dir <- c("<=", "<=")
f.rhs <- c(9, 15)
op=lp ("max", f.obj, f.con, f.dir, f.rhs,compute.sen=TRUE)
op
## Success: the objective function is 40.5
op$solution
## [1] 0.0 4.5 0.0
op$duals
## [1]   4.5   0.0  -3.5   0.0 -12.5

Go back to the chicken farmer example:

  1. Set up the PRIMAL problem in R and solve it. From the R output, find the value of the objective function, the solution, the marginal loss values and the dual values (shadow prices). Explain what each means.

A shadow price is an estimated price for something that is not normally priced in the market or sold in the market.

Basic Consumer Theory

Assumptions? Why Assumptions are important in Economics?

Example 1:

There are coffee(x) and tea(y). The price of coffee is $1, and the price of tea is $2 dollar.You have 5 dollars in total, and you have to spend all the money. How much coffee and tea you will buy?

{5,0},{3,1},{1,2}

Is there any way to compared which consumption bundle is better?

Need Assumptions about preference, the utility level each of the product is given by the table:

U 1 2 3 4 5
Coffee 5 3 1 0 -5
Tea 20 10 \ \ \

Example 2:

Underlying Assumptions:

1.Rational Behavior

2.Assumption on Preferences

3.Utility Maximization Behavior \[ MRS_{xy}=\frac {\frac{\partial u}{\partial y}}{\frac{\partial u}{\partial x}}=\frac{p_y}{p_x} \]