# Cost and profitability analysis

## Production costs

The following matrix has three columns, the first is the number of items my company can produce ($$Q$$), the second column are fixed costs ($$C_f$$), which are constant, and the third column are the variable costs ($$C_v$$).

d: matrix([10,75,170], [20,75,280],
[30,75,350], [40,75,400],
[50,75,450], [60,75,520],
[70,75,630], [80,75,800],
[90,75,1050],[100,75,1400]);


$\pmatrix{10&75&170\cr 20&75&280\cr 30&75&350\cr 40&75&400\cr 50&75& 450\cr 60&75&520\cr 70&75&630\cr 80&75&800\cr 90&75&1050\cr 100&75& 1400\cr }$

We can easily extract quantities and costs from the matrix,

[Q, Cf, Cv]: args(transpose(d));


$\left[ \left[ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 \right] , \\ \left[ 75 , 75 , 75 , 75 , 75 , 75 , 75 , 75 , 75 , 75 \right] , \\ \left[ 170 , 280 , 350 , 400 , 450 , 520 , 630 , 800 , 1050 , 1400 \right] \right]$

Total costs are $$C_t = C_f+C_v$$,

Ct: Cf+Cv;


$\left[ 245 , 355 , 425 , 475 , 525 , 595 , 705 , 875 , 1125 , 1475 \right]$

All costs in one plot,

draw2d(
points_joined = true,
yrange        = [0,1400],

key           = "Fixed costs",
points(Q, Cf),

key           = "Variable costs",
color         = red,
points(Q, Cv),

key           = "Total costs",
color         = black,
points(Q, Ct));


## Average and marginal costs

We define the average fixed cost as $$\overline{C}_f=\frac{C_f}{Q}$$,

Cfm: Cf/Q;


$\left[ {{15}\over{2}} , {{15}\over{4}} , {{5}\over{2}} , {{15 }\over{8}} , {{3}\over{2}} , {{5}\over{4}} , {{15}\over{14}} , {{15 }\over{16}} , {{5}\over{6}} , {{3}\over{4}} \right]$

The average variable cost as $$\overline{C}_v=\frac{C_v}{Q}$$,

Cvm: Cv/Q;


$\left[ 17 , 14 , {{35}\over{3}} , 10 , 9 , {{26}\over{3}} , 9 , 10 , {{35}\over{3}} , 14 \right]$

And the average total cost as the sum $$\overline{C}_t=\overline{C}_f + \overline{C}_v$$,

Ctm: Cfm+Cvm;


$\left[ {{49}\over{2}} , {{71}\over{4}} , {{85}\over{6}} , {{95 }\over{8}} , {{21}\over{2}} , {{119}\over{12}} , {{141}\over{14}} , {{175}\over{16}} , {{25}\over{2}} , {{59}\over{4}} \right]$

Also, the marginal cost is the quotient between the variation of total cost and the variation of produced units. Algebraically speaking, $C_{mg} = \frac{\Delta C_t}{\Delta Q}.$ The meaning of this concept is the additional cost of producing an additional unit of product. Let's calculate it,

Cmg: makelist((Ct[k]-Ct[k-1]) / (Q[k]-Q[k-1]),
k, 2, length(Q)) ;


$\left[ 11 , 7 , 5 , 5 , 7 , 11 , 17 , 25 , 35 \right]$

draw2d(
points_joined = true,

key           = "Average variable cost",
points(Q, Cvm),

key           = "Average total cost",
color         = red,
points(Q, Ctm),

key           = "Marginal costs",
line_width    = 2,
color         = black,
points(rest(Q), Cmg) )$ ## Threshold of profitability If my company sells each item at the price of 15€. Incomes are $$I=15 Q$$, I: 15*Q;  $\left[ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 \right]$ Let's make a graphical representation of both total costs and incomes against the number of items we can produce, draw2d( points_joined = true, grid = true, key = "Total costs", color = black, points(Q, Ct), key = "Incomes", color = green, points(Q, I) )$


The intersection point of the two curves gives the threshold of profitability, that is, the critical number of items to be produced by my company in order to cover all costs. Any change in this production plan gives rise to profit or loss.

We want to calculate precisely this threshold point. Since we only have at hand isolated values of quantities, costs and incomes, a possible estimation is via interpolation techniques. We start loading the interpol package,

load(interpol) $ The Lagrange method of interpolation returns a polynomial that passes through all empirical points. First, for the total costs, lct: expand(lagrange(transpose(matrix(Q,Ct)), varname=q));  ${{q^3}\over{300}}-{{2\,q^2}\over{5}}+{{62\,q}\over{3}}+75$ Second, for the incomes, lin: expand(lagrange(transpose(matrix(Q,I)), varname=q));  $15\,q$ Graphical representation of the two interpolators, draw2d( grid = true, color = black, points(Q, Ct), key = "Total costs", explicit(lct,q,10,100), color = green, key = "", points(Q, I), key = "Incomes", explicit(lin,q,10,100) )$


The last step is to solve equation $$I=C_t$$, but since it is a polynomial equation of fifth degree, there is not an exact algebraic method for solving it. We choose a numerical procedure instead,

find_root (lin-lct, q, 20, 30);


$27.23174620148754$

When the production level is below 27.23 we loss money, but for greater values, we get profit, which is the difference $$I-C_t$$. We see that the two curves have another intersection around $$q \approx 100$$. The maximum benefit is somewhere between these two numbers. Let's calculate the maximum of the difference $$I-C_t$$,

solve( diff(lin-lct, q));


$\left[ q=-{{10\,\sqrt{93}-120}\over{3}} , q={{10\,\sqrt{93}+120 }\over{3}} \right]$

In decimal format,

float(%);


$\left[ q=7.854497463356816 , q=72.14550253664318 \right]$

Clearly, our best decision is to produce a total amount of 72 units. The estimated benefit is

subst(q=rhs(second(%)), lin-lct);


$346.4467952524305$