Linear Algebra examples

Primary tabs

Break-even analysis

A nice way you understand the value of matrix algebra use it in simple practical examples. One such example is a break even analysis: For instance with certain fixed costs, as well as a pay rate for labour, how many hours do need to charge out in order to break-even?

This can be calculated in an OpenMx model, optimising on profit, and solving with the constraint the we break-even. This model has one free parameter-namely the hours of work.

fit1 = mxModel("fit1",
mxMatrix(name="hours"        , values=1   , free=T, type="Full", nrow=1, ncol=1),
mxMatrix(name="fixedCosts"   , values=730 , free=F, type="Full", nrow=1, ncol=1),
mxMatrix(name="payRate"      , values=5.85 , free=F, type="Full", nrow=1, ncol=1),
mxMatrix(name="chargeOutRate", values=8.15, free=F, type="Full", nrow=1, ncol=1),
mxAlgebra(name="revenue"    , expression = chargeOutRate * hours),
mxAlgebra(name="expenditure", expression = fixedCosts + (payRate * hours)),
mxAlgebra(name="profit"     , expression = revenue - expenditure),
mxConstraint(revenue - expenditure ==0, name = "breakEven"),
mxAlgebraObjective(algebra="profit", numObs= NA, numStats=NA)
)
fit1 = mxRun(fit1)
summary(fit1)
    free parameters:
name matrix row col Estimate Std.Error lbound ubound
1   hours   1   1 317.3913        NA


How much will we lose if we can only charge out 35 hours?

fit1 = mxModel("fit1",
mxMatrix(name="hours"        , values=1   , free=T, type="Full", nrow=1, ncol=1),
mxMatrix(name="fixedCosts"   , values=730 , free=F, type="Full", nrow=1, ncol=1),
mxMatrix(name="payRate"      , values=5.85 , free=F, type="Full", nrow=1, ncol=1),
mxMatrix(name="chargeOutRate", values=8.15, free=F, type="Full", nrow=1, ncol=1),
mxAlgebra(name="revenue"    , expression = chargeOutRate * hours),
mxAlgebra(name="expenditure", expression = fixedCosts + (payRate * hours)),
mxAlgebra(name="profit"     , expression = revenue - expenditure),
mxConstraint(hours ==35, name = "maxHours"),
mxAlgebraObjective(algebra="profit", numObs= NA, numStats=NA)
)
fit1 = mxRun(fit1)
fit1@algebras\$profit@result
[,1]
[1,] -649.5

Two linear equations.

You have ingredients:
Inputs: 142 gallons of Apple, 108 gallons of Pear
You make products from these:
Outputs: light juice (7l of appl and 3l of pear per case) and golden juice (4l of apple and 6l of pear per case)

The products require different amounts of ingredients. How can you use all your available ingredients by balancing production between the two products?

fit1 = mxModel("fit1",
mxMatrix(name="appleAvailable", values=142, free=F, type="Full", nrow=1, ncol=1),
mxMatrix(name="pearAvailable", values=108 , free=F, type="Full", nrow=1, ncol=1),
mxMatrix(name="golden"       , values=1   , free=T, type="Full", nrow=1, ncol=1),
mxMatrix(name="light"        , values=1   , free=T, type="Full", nrow=1, ncol=1),
mxAlgebra(name="appleUsed", expression = 4 %x% golden + 7 %x% light),
mxAlgebra(name="pearUsed" , expression = 6 %x% golden + 3 %x% light),
mxConstraint(appleUsed == appleAvailable, name = "maxApple"),
mxConstraint(pearUsed  == pearAvailable , name = "maxPear"),
mxAlgebraObjective(algebra="light", numObs= NA, numStats=NA)
)

fit1 = mxRun(fit1)
summary(fit1)
name matrix row col Estimate Std.Error lbound ubound
1 <NA> golden   1   1       11        NA
2 <NA>  light   1   1       14        NA              

So, 11 cases of golden and 14 cases of light juice solves the problem.