For a related numerical example look here, for a graphical example look here, and finally for a word problem based example look here.
Remember that when calculating the profit maximizaing point for any firm, it is imperative that we set marginal revenue equal to marginal cost (MR=MC). If we are at any other point, then there are potential gains to be made. Imagine if MR<MC, at this point we are losing money on the margin. We are selling too many goods or services, and need to scale back. If MR>MC, then we are selling too few, and we could sell more goods or services because our marginal gain is greater than our marginal cost. Below is a graphic showing this relationship for a perfectly competitive firm:
A perfectly competitive firm faces a market price of $10 for its output X. it owns two plants, A and B, whose total costs are
TCa = 10 + 2X + .25 X2
TCb = 15 + .4X + .1X2
How many units should each plant produce to maximize profit at that price?
We have to figure out the marginal cost of each firm, and this can be done easily by taking the first derivative of the cost function with respect to quantity or X.
The MC for plant a is 2 + .5X, and the MC for plant b is .4 + .2X. You can find the MC easily from the total cost functions by using the "power rule" taught in most calculus classes.
Now we set the MC for each firm, and set it equal to the MR which is always going to be $10 (the market price given for this example).
So for plant a we get:
2 + .5X = 10, subtract 2 from both sides, then multiply both sides by 2 to get:
X = 16, so the profit maximizing quantity for the first plant is to produce 16 units.
So for plant b we get:
.4 + .2X = 10, subtract .4 from both sides, then multiply both sides by 5 to get:
X = 48, so the profit maximizaing quantity for the second plant is to product 48 units.
REMEMBER: The profit maximizing point for ALL firms occurs where marginal revenue equals marginal cost (MR=MC). For a perfectly competitive market, in the long run (after firms have been allowed to enter or exit) this will also be the minimum point of the average total cost curve (ATC).