This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# Solution to the Given Problem
# <!-- A car company produces 2 models, model A and model B. Long-term projections indicate an expected demand of at least 100 model A cars and 80 model B cars each day. Because of limitations on production capacity, no more than 200 model A cars and 170 model B cars can be made daily. To satisfy a shipping contract, a total of at least 200 cars much be shipped each day. If each model A car sold results in a $2000 loss, but each model B car produces a $5000 profit, how many of each type should be made daily to maximize net profits? -->
#library to run Linear Programming in R
library(lpSolve)
#x1 = No. of cars of model A produced in one day
#x2 = No. of cars of model B produced in one day
#Z = -2000x1 + 5000x2
obj.fun <- c(-2000, 5000)
#The coefficients correspond to following equations
#x1 >= 100 => x1 + 0x2 >= 100
#x1 <= 200 => x1 + 0x2 <= 200
#x2 >= 80 => 0x1 + x2 >= 80
#x2 <= 170 => 0x1 + x2 <= 170
# x1 + x2 >= 200
constr <- matrix(c(1,0,1,0,0,1,0,1,1,1), ncol=2, byrow=TRUE)
#Signs of the corresponding above equations in order
constr.dir <- c(">=","<=",">=","<=",">=")
#Values of the right hand side of the equations in order
rhs <- c(100,200,80,170,200)
#Applying Linear Programming
prob.sol <- lp("max",obj.fun,constr,constr.dir,rhs,compute.sens=TRUE)
#Getting Results(x1 = 100, x2 = 170)
prob.sol$solution
## [1] 100 170
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.