Sensitivity Analysis Problems

Meershaert  1.4 #2

A farmer keeps a pig.  There are various costs associated with keeping it, resulting in different profit functions.  Can we use cheaper feed?  Would it be cost effective to use better feed?

All other things being the same, what happens if we slightly change the daily cost of keeping the pig?

linear cost function  = c t.

Investigate the different profit functions for different values of the parameter c.

Define a function for the profits.

Expand[(.65-.01t)(200+5t)-c t]

P[t_,c_]:=130.+1.25 t-c t-0.05 (t^2)

Collect[%,t]

Just to get an idea of what these profit functions look like for various values of c on either side of c=.45.
We can make a table of the functions and plot each parabola. 
As you can see from the term (1.25-c)t, a smaller value of c yields a larger profit maximum.
This makes intuitive sense, too:  lower the daily cost of keeping the pig and the profit should increase.

fcnlist=
Table[P[c,t],{c,.3,.6,.05}]

Plot[Evaluate[fcnlist],{t,4,15}]

I've plotted one function by itself to verify that the smallest value of c yields the top curve.  This is one graph of net profit versus time to sell in the case of c=.3.

Plot[P[t,.05],{t,4,15}]

Determine the optimal selling time based on the parameter.

Take the derivative of the profit function, leaving c a parameter.
Set to zero and solve.

D[P[t,c],t]

Solve[%==0,t]

This expression will yield the optimal time to sell the pig as a function of the daily cost of keeping the pig. 
The optimum here maximizes profit.  There is no need for a first or second derivative test since we know these are concave down parabolas.

Expand[10. (1.25-1. c)]

Obviously, larger daily costs of keeping the pig will lower the optimal time to sell the pig.

optimalt[c_]:=12.5-10. c

Here are some numerical estimates of how sensitive the optimal price is to the parameter.

This is a rather simple and "low-level" notion of sensitivity analysis; for instance, it requires no calculus.

The left column of this table is c, the daily cost of keeping the pig.
The right column represents the optimal time to sell the pig based on that keeping cost.

Table[{c,12.5-10c},{c,.3,.6,.05}]//MatrixForm

We want to investigate sensitivity near c=.45. Consider the point to the left.
The c value decreases by 11.1111%, as calculated below.  We have the difference in the parameter values divided by the main parameter value time 100%.  This is the relative change in c.

(.4-.45)/.45*100

The t value increases by 6.25%; the relative change in t.

(8.5-8)/8*100

An 11% (actually 11.111%) decrease in the daily cost of keeping the pig will increase the optimal selling time by approximately 6.25%, measuring from a daily cost of .45.

Do this again in the other direction.

(.5-.45)/.45*100

(7.5-8)/8*100

We have a symmetric percent change:  an 11% increase in the daily cost of keeping the pig will decrease profts by approximately 6.25%, measuring from a daily cost of .45.

Compute the sensitivity function of the optimal time to sell the pig based on variations in the daily cost of keeping it.

This is a more complicated and sophisticated notion of sensitivity.

Expand[ D[optimalt[c],c] c/t]

S[t_,c_]:=-((10.` c)/t)

For c=.45, the optimal time is t=8 days.  At this point,

S[8,.45]

If c increases by 10%,then t decreases by approximately 5.625%,according to this sensitivity function.

Comparing with our previous numerical estimate, an 11.111% increase in c will yield a 6.25% decrease in t.

11.111*(-0.5625)

This is exactly the same as our previous numerical result.  This is because optimalt[c] is linear.  When this function is nonlinear, the value based on the sensitivity function and that from the numerical estimates will be close, as long as we're not changing the parameter value too much.  This comparison is not absolutely necessary, but if we expect our sensitivity analyses to make sense, they should yield at least somewhat similar results.

Compare profit differences for different values of c.

Table[{c,optimalt[c],P[optimalt[c],c]},{c,.3,.6,.05}]//MatrixForm

Note that the profit decreases only slightly with increases in the daily cost of keeping the pig from the .45 value.

pvalues={134.51,134.05,133.61,133.20,132.81,132.45,132.11}

pdifs=Table[pvalues[[i]]-pvalues[[i-1]],{i,2,7}]

%/133.2*100

Profits change by less than 0.4%.

Table[{c,optimalt[c],P[optimalt[c],c]},{c,.3,.9,.1}]//MatrixForm

Even doubling the daily cost only changes the profit by a few dollars

130.61-133.2

%/133.2*100

That's less than 2% decrease.

============================================================

Using a new feed costing 60 cents/day, the pig grows at 7 lbs/day.

Assume  C = c t and 
g is the line joining the (c,g) pairs (.45,5), (.6,7).

ClearAll

Expand[(7-5)/(.6-.45)(c-.45)+5]

Investigate the different profit functions for different values of the parameter c.

Define a function for the profits.

Expand[(.65-.01t)(200+(-1.+13.33 c)t)-c t]

P[t_,c_]:=130.-2.65 t+7.6645 c t+0.01 (t^2)-0.1333 c (t^2)

Collect[130.-2.65 t+7.6645 c t+0.01 (t^2)-0.1333 c (t^2),t]

Just to get an idea of what these profit functions look like for various values of c on either side of c=.45, going past c=.6.
We can make a table of the functions and plot each parabola. 
This time, the effect of changing c is hard to visualize since both the t and t^2 terms are changed.

fcnlist=
Table[P[t,c],{c,.3,.9,.1}]

Plot[Evaluate[fcnlist],{t,0,30}]

Determine the optimal selling time based on the parameter.

Take the derivative of the profit function, leaving c a parameter.
Set to zero and solve.

D[P[t,c],t]

Solve[%==0,t]

This expression will yield the optimal time to sell the pig as a function of the daily cost of keeping the pig. 
The optimum here maximizes profit.  There is no need for a first or second derivative test since we know these are concave down parabolas.

Simplify[-((1. (-2.65+7.6645 c))/(0.02-0.2666 c))]

optimalt[c_]:=((2.65-7.6645 c)/(0.02-0.2666 c))

Here are some numerical estimates of how sensitive the optimal price is to the parameter.

This is a more mathematical notion of sensitivity.  It is a rather simple and "low-level" notion; for instance, it requires no calculus.

The left column of this table is c, the daily cost of keeping the pig.
The right column represents the optimal time to sell the pig based on that keeping cost.

Table[{c,optimalt[c],P[optimalt[c],c]},{c,.35,.9,.05}]//MatrixForm

We want to investigate sensitivity near c=.45. Consider moving from c=.45 toward c=.6, which is a pretty big leap.

(.6-.45)/.45*100

(13.92-7.99)/7.99*100

(143.566-133.193)/133.193*100

(13.92-7.99)

(143.566-133.193)

A 33.33% increase in the daily cost of keeping the pig will increase the optimal time to sell by approximately 74.22% and increase the profit by almost 8%.  It's probably worth it to keep the pig another 6 days to get another $10 in profit.

Compute the sensitivity function of the optimal time to sell the pig based on variations in the daily cost of keeping it.

This is a more complicated and sophisticated notion of sensitivity.

D[optimalt[c],c] c/t

Together[%]

S[t_,c_]:=((0.5531999999999999c)/((((0.02-0.2666 c))^2) t))

For c=.45, the optimal time is almost t=8 days.  At this point,

S[8,.45]

If c increases by 10%,then the optimal t increases by approximately 31%,according to this sensitivity function.

33*(3.113617890508694`)

According to this, a 33% increase in c will yield a 103% increase in t.  That means the time more than doubles.

This seems pretty far off from our previous numerical result.  This is because optimalt[c] is nonlinear AND we're changing the parameter value by a significant amount.

Compare profit differences for different values of c.

pvalues=Table[P[optimalt[c],c],{c,.35,.9,.05}]

pdifs=Table[pvalues[[i]]-pvalues[[i-1]],{i,2,12}]

The percent increases in profit:

percents=pdifs/133.193*100

clist=Table[c,{c,.35,.9,.05}]

points=Table[{clist[[i+1]],percents[[i]]},{i,1,11}]

A table of c values and the corresponding percent increase in profit.

MatrixForm[points]

Profits increase from 1.65% and almost 3% as we use more expensive feed.  As you can see, this trend continues.

============================================================