Modelling Demand & Supply Curves:
An Application of Pure Mathematics

Motivation

You are a mathematician and your friend, an economist, needs help modelling demand and supply curves for a client.  Additionally, your friend needs help computing associated values.  You agree to help your friend by writing a computer program that will generate the required information for any arbitrary set of linear demand and supply curves.

Be sure to check the activity rubric before you begin the activity.

Job Parameters

Your friend has been supplied with the following data sets:

Product A:
(Subscript[q, d])=-2(Subscript[p, d])+50         (Demand Set)
(Subscript[q, s])=10(Subscript[p, s])-10           (Supply Set)

Product B:
(Subscript[q, d])=-0.1(Subscript[p, d])+6        (Demand Set)
(Subscript[q, s])=(1/8)(Subscript[p, s])+1.5           (Supply Set)

From the given data sets the following information must be computed:

The graphs of each data set in the first quadrant on a pair of p vs q axes.

The intercepts for each data set.

The intersection point for each data set.  This is called the equilibrium point.

The area of the region in the first quadrant bound by the y-axis, the demand curve and the equilibrium horizontal.  This is called the Consumer Surplus.

The area of the region in the first quadrant bound by the y-axis, the supply curve and in some cases the x-axis.  This is called the Producer Surplus.

Shift in the demand curve.

Solve Particular Data Sets for Product A

(Subscript[q, d])=-2(Subscript[p, d])+50         (Demand Set)
(Subscript[q, s])=10(Subscript[p, s])-10           (Supply Set)

Please Place your “by hand” answers below for each item.  Use the Classroom Palette for assistance creating the proper typeset.

Solve the data sets for p in terms of q.  Why is this necessary?

answer here

Solve the data sets for the intersection point (equilibrium point).

answer here

Please Place your Mathematica answers below for each item.  Use the Documentation Center if necessary to write the correct code.

Solve the data sets for p in terms of q.

(* answer here *)

Solve the data sets for the intersection point (equilibrium point).

(* answer here *)

Plot the demand curve in blue, the supply curve in red and the equilibrium point in black.

(* answer here *)

Solve Particular Data Sets for Product B

(Subscript[q, d])=-0.1(Subscript[p, d])+6        (Demand Set)
(Subscript[q, s])=(1/8)(Subscript[p, s])+1.5           (Supply Set)

Please Place your “by hand” answers below for each item.  Use the Classroom Palette for assistance creating the proper typeset.

Solve the data sets for p in terms of q.  Why is this necessary?

answer here

Solve the data sets for the intersection point (equilibrium point).

answer here

Please Place your Mathematica answers below for each item.  Use the Documentation Center if necessary to write the correct code.

Solve the data sets for p in terms of q.

(* answer here *)

Solve the data sets for the intersection point (equilibrium point).

(* answer here *)

Plot the demand curve in blue, the supply curve in red and the equilibrium point in black.

(* answer here *)

Generalize Solutions to Data Sets

In this section you will begin to develop a code to model arbitrary linear demand and supply data sets.  Since collaboration is encouraged please use the following variable assignments.  Common variables will facilitate conversation, as well as readability of another working group’s code.  Please give a typeset answer for each of the following.

ds : Demand Slope
di : Demand Intercept

ss : Supply Slope
si : Supply Intercept

Given these variable assignments the generalized equations are:

answer here

Find the generalized equations expressed for p in terms of q. Why is this neccessary?

answer here

Find the generalized solution for the intersection point.

answer here

Developing a Code

When developing code sometimes it is easiest and best to work in stages.  I have prepared some stages for you.  Each of the following slides will prompt you to write code that executes a certain portion of the final project.  As you will progress please be mindful of the future elements and how your stages will ultimately need to fit together.

Defining functions for Static Plots of Demand & Supply Curves

Define a function Demand1 with the two variables ds_ and di_ that will plot an arbitrary demand curve.

(* define function here *)

Product A

(* use Demand1 with Product A here *)

Product B

(* use Demand1 with Product B here *)

Define a function Supply1 with the two variables ss_ and si_ that will plot an arbitrary supply curve.  Plot the curve in red.

(* define function here *)

Product A

(* use Supply1 with Product A here *)

Product B

(* use Supply1 with Product B here *)

Define a function Equilibrium1 with the four variables ds_, di_, ss_ and si_ that will plot an equilibrium point.  Plot the point in black.

(* define function here *)

Product A

(* use Equilibrium1 with Product A here *)

Product B

(* use Equilibrium1 with Product B here *)

Combining Functions of Static Plots of Demand & Supply Curves and Equilibrium Point into One Plot

Define a function Econ1 with the four variables ds_, di_, ss_ and si_ that combines your previous 3 plots into 1.

(* define function here *)

Product A

(* use Econ1 with Product A here *)

Product B

(* use Econ1 with Product B here *)

Adding Details and Embellishments to Static Plot

In order to proceed you should have a working Econ1 function that has been tested using the data sets for Product A and Product B respectively.

At this stage Econ1 needs refinement.  The following items will help you to add some necessary detail.  Take a moment to review the job parameters so that the prompts seem sensible.

Good developers always add comments to their code in order to make it easier to edit or modify in the future.  Comments are descriptions in the working code that are not executed.  In Mathematica comments are entered using: (* ... *) as used previously in this activity.

Add comments to your existing code before adding anymore executable lines.

(* add comments to code here *)

Re-evaluate Econ1 and test it with either the Product A or Product B data sets to confirm that the comments did not change execution.

(* test code with comments here *)

Next label the axes add a plot legend that provides a label for the demand curve, supply curve and equilibrium point.

(* test code with labels here *)

Add black dashed horizontal and vertical lines to emphasize the equilibrium point and to create a separation between the consumer and producer surplus regions.  Remember to add comments to your code that describe the new elements.

(* add dashed lines to code here *)

Re-evaluate Econ1 and test it with either the Product A or Product B data sets to confirm proper execution.

(* test code with graphics here *)

Shade the Consumer Surplus region blue and the Producer Surplus red.

(* add filling to code here *)

Re-evaluate Econ1 and test it with either the Product A or Product B data sets to confirm proper execution.

(* test code with filling here *)

Creating a Grid Display for Required Values

The job parameters require the code to also display the values of the following computations: the demand curve price and quantity intercepts; the supply curve quantity intercept; market equilibrium quantity and price; consumer surplus, and producer surplus.

Define a function, DSdata1, that uses the four variables ds_, di_, ss_ and si_ to compute and display the required values in a grid.

(* define DSdata1 here *)

Evaluate DSdata1 and test it with either the Product A or Product B data sets to confirm proper execution.

(* test DSdata1 here *)

Assembling Components for a Static Plot Solution

Now you are ready to combine Econ1 and DSdata1 into one function.  Feel free to name this function whatever you like.  Remember to use all four variables and to add or modify comments to your code as appropriate.

(* define super-function here *)

Evaluate your function and test it with either the Product A or Product B data sets to confirm proper execution.

(* test your function here *)

Creating a Dynamic Plot

Sometimes there are factors cause the demand curve to shift.  Geometrically, this changes the coordinate of the intersection or market equilibrium, as well as in the size of the areas that define the consumer and producer surpluses.  The last step is to transform your static plot into a dynamic one by wrapping a portion of your function call in a Manipulate[...].  Other modifications may be needed.

Modify your function so that it produces a dynamic plot.  Set the lower bound so that the producer surplus can never be smaller than 0.

(* define and modify code to create dynamic plot here *)

Evaluate your function and test it with either the Product A or Product B data sets to confirm proper execution.

(* test your function here *)

Rubric

This activity will be scored according to the following rubric.  The activity is worth a total of 25 points with each category being worth a total of 5 points.  Half point increments may be assigned.  Please ask if any part of this rubric is unclear to you.  Also, feel free to ask if your work is satisfying certain aspects of the rubric as you progress.

data2={

(* row 2 column 1*)
{ "Text Typesetting",

(* row 2 column 2*) "All text is written in a Text cell, it is professionally presented, and mathematical formulas use conventional notation.", 

(* row 2 column 3*)
"All text is in a Text Cell, presentation is consistent, and mathematical formulas may or may not be in conventional notation.", 

(* row 2 column 4 *)
"Text may or may not be in a Text cell; presentation is inconsistent or not aesthetically pleasing; mathematical formulas may or may not be in conventional notation.",

(* row 2 column 5 *)
"Text is not written in a Text cell; presentation may create confusion; mathematical formulas are not in conventional notation.",

(* row 2 column 6 *) "Text is not in a Text cell; mathematical formulas do not use conventional notation and presentation lacks professionalism"}, 

(* row 3 column 1 *)
{"By Hand Mathematical Solutions",

(* row 3 column 2 *) "All computations are correct with appropriate justification; equations are presented in a conventional a format.",

(* row 3 column 3 *) "All computations are correct; justification is adequate; presentation is consistent.",

(* row 3 column 4 *)
"Computations are partially correct; justification is incomplete; presentation is inconsistent with the rest of the work.", 

(* row 3 column 5 *)
"Computations are partially correct; justification is incorrect or missing; presentation is inconsistent or lacks professionalism.",

(* row 3 column 6 *) "Computations are incorrect; no justification; presentation lacks professional."}, 

(* row 4 column 1 *)
{"Mathematica Solutions",

(* row 4 column 2 *) "All computations are correct and agree with manual computations; the Mathematica input is efficient and correct.",

(* row 4 column 3 *)
"All computations are correct and agree with manual computations; Mathematica input generates correct answers, but may not be the most efficient code.",

(* row 4 column 4 *)
 "Only a score of '5', '4', '2' or '1' is achievable in this category due to the 'binary' nature of this category.",

(* row 4 column 5 *)
 "Computations are partially correct either due to incorrect function call, mathematical equation or typographical error; Outputs are incorrect or error messages.",

(* row 4 column 6*)
 "Computations are incorrect either due to incorrect function call, mathematical equation or typographical error; Outputs are error messages."},

(* row 5 column 1 *)
 { "Generalizations" ,

(* row 5 column 2 *) "Generalizations are correct and expressed in both q in terms of p and p in terms of q; uses the specified variables and is professionally presented in a Text cell.",

(* row 5 column 3 *) "Generalizations are correct and expressed q in terms of p or p in terms of q; uses the specified variables and is adequately presented.",

(* row 5 column 4 *)
"Generalizations are mostly correct; equations are expressed in either q in terms of p or p in terms of q but not both; uses the specified variables and is adequately presented.",

(* row 5 column 5 *)
 "Generalizations are partially correct; equations are expressed in unconventional manner; uses prescribed variables or different variables.",

(* row 5 column 6 *) "Generalizations are incorrect and will not lead to executable code that will produce the desired output; different variable assignments were used than what was prescribed." }, 

(* row 6 column 1 *)
{ "Code Development",

(* row 6 column 2 *) "The code executes desired output correctly, is efficient, properly commented and easy to read or modify.",

(* row 6 column 3 *)
 "The code executes desired output; mostly commented and fairly easy to modify.",

(* row 6 column 4 *)
 "The code executes and most of the output is correct; partially commented and difficult to find different sections",

(* row 6 column 5 *)
 "Code executes but does not produce the desired output; code is not commented and difficult to read; job parameters are largely unsatisfied.",

(* row 6 column 6 *)
 "Code does not execute or does not produce accurate data or does not satisfy the job parameters." }

 };

Text@Grid[Prepend[data2,{"",5,4,3, 2, 1}], Dividers-> All,
ItemSize->{8, 1}, ItemStyle->{ FontSize-> 10 }, Background->{ {LightGray, None}, {Red, None }} ]