/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
/* [ Created with wxMaxima version 12.04.0 ] */

/* [wxMaxima: comment start ]
    Eric Doviak
    original: 31 Aug 2011
    updated:  02 May 2012

    Math Methods 7025X 

    Simple microeconomic model of textbook demand
    Two cases:  perfect competition and monopoly
   [wxMaxima: comment end   ] */

/* [wxMaxima: comment start ]
    The Case of Perfect Competition
   [wxMaxima: comment end   ] */

/* [wxMaxima: comment start ]
    individual demand and market demand
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* each student has the following demand for textbooks:          */

qd(p,m,b) := b - m*p $

/*  10,000 students          */
/*  100 textbook companies   */
/*  because there are 10,000 students, market demand is given by: */

QD(p,m,b) := 10000 * qd(p,m,b) $
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    individual firm supply and market supply
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* each company faces the following marginal cost of producing textbooks     */
/*                                                                           */
/*      mc = q / r                                                           */ 
/*                                                                           */
/* in a competitive market, the company would produce until  mc = p          */
/* so invert the marginal cost equation and replace "mc" with "p" to obtain: */

qs(p,r) := p * r  $


/* because there are 100 companies, market supply is given by: */

QS(p,r) := 100 * qs(p,r)  $
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    assume some parameter values
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
m :   0.10 $ 
b :   7    $
r :  25    $

/* those parameters yield the following market demand and market supply:  */

print("")$
print("market demand: ",QD(p,m,b))$
print("market supply: ",QS(p,r))$
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
   let's plot the supply and demand curves
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/*  first flip the axes, so that price is on the vertical  */

market_demand(q) := ''(subst(solve(QD(p,m,b)=q,p)[1],p)) $
market_supply(q) := ''(subst(solve(QS(p,r)  =q,p)[1],p)) $

print("")$
wxplot2d([market_demand,market_supply], [q,0,60000],
    [xlabel,"quantity"],[ylabel,"price"],[legend,"Demand","Supply"])$
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    solve for equilibrium price and quantity
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* solving for equilibrium price                  */
peq:subst(solve( QD(p,m,b) = QS(p,r) , p ), p)$

/* plugging in to obtain the equilibrium quantity */
qeq:QS(peq,25)$

print("") $
print("In perfect competition:") $
print("  *  the equilibrium price would be:    ", peq) $
print("  *  the equilibrium quantity would be: ", qeq) $
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    The Case of Monopoly
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* kill the constants */
kill(m,b,r)$
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    total cost and marginal cost
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* Now suppose one company acquires all of the others  */
/* and has a monopoly on textbooks.                    */
/* Because there were 100 companies, the monopolist's  */
/* marginal cost would be:                             */
/*                                                     */
/*   100 * mc = q / r   ==>  mc = q / (100*r)          */

MC(q,r):= q / (100*r) $

/* assuming total cost = 0, when quantity = 0          */
/* then total cost is given by:                        */

TC(q,r):=(q^2)/(200*r)$
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    total revenue and marginal revenue
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* The monopolist's revenue would depend on the price  */
/* and quantity sold:   TR = p*Q                       */
/*                                                     */
/* Solving the market demand equation for price:       */

pmkt(q,m,b):=''(subst(solve(QD(p,m,b)=q,p),p))$

/* enables us to calculate total revenue as a function */
/* of quantity alone:                                  */

TR(q,m,b) := q*pmkt(q,m,b)$

/* To obtain the marginal revenue function, we take the */
/* derivative with respect to "q"                       */

MR(q,m,b) := ''(diff(TR(q,m,b),q,1))$
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    assume the same parameter values
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* The monopolist produces up to the point where: MR = MC  */
/* so plugging in:                                         */
m :   0.10 $ 
b :   7    $
r :  25    $

print("")$
print("marginal cost and marginal revenue")$
print("MC = ",MC(q,r)) $
print("MR = ",MR(q,m,b)) $
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
   let's plot the demand curve along with MC and MR
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
print("")$
wxplot2d([pmkt(q,m,b),MC(q,r),MR(q,m,b)], [q,0,60000],[y,0,70],
    [xlabel,"quantity"],[ylabel,"price, MC, MR"],[legend,"Demand","MC","MR"])$
/* [wxMaxima: input   end   ] */

/* [wxMaxima: comment start ]
    solve for profit-maximizing price and quantity
   [wxMaxima: comment end   ] */

/* [wxMaxima: input   start ] */
/* we can obtain the quantity that the monopolist produces */
qmono:float(subst(solve(MR(q,m,b)=MC(q,r),q),q))$ 

/* the monopolist's marginal cost                      */
mcmono:float(MC(qmono,r))$

/* the price that the monopolist receives              */
pmono:float(pmkt(qmono,m,b))$

/* and the monopolist's profit                         */
profit:float(TR(qmono,m,b)-TC(qmono,r)) $
avgpft:float(profit/qmono) $

print("") $
print("The monopolist's:")$
print("  *  price:    ", pmono) $
print("  *  quantity: ", qmono) $
/*  print("  *  marginal cost:  ",mcmono) $  */      
/*  print("  *  average profit: ",avgpft) $  */
print("") $
print("For comparison, in perfect competition:") $
print("  *  price:    ", peq) $
print("  *  quantity: ", qeq) $
/* [wxMaxima: input   end   ] */

/* Maxima can't load/batch files which end with a comment! */
"Created with wxMaxima"$
