Now suppose the cost function is convex, that is, the unit cost gets more and more expensive as the total number of goods produced increases. For example the price for bringing 100 goods to market costs $1 each, 200 goods to market costs $2 each, and 300 goods to market costs $5 each. The unit cost gets more expensive because the machinery maintenance and labor gets more expensive as it produces near to or beyond its production capacity. Eventually there would be a quantity where it is impossible to bring to market, perhaps bringing 1 million goods to market costs $1 million each. How many goods then should the small firm bring to the market?

One obvious suggestion might be that the small firm brings exactly that
number of goods, such that the unit cost would equal the price. That
is, if the price is $5, then in our previous example the small firm should
bring 300 goods. However on deeper thought, this would turn out to
be unfavorable, because the small firm would then earn nothing. To
earn a profit, the small firm should bring somehow less number of goods
to the market. How much less should the firm bring? In the
extreme where the firm only bring 1 good to the market, then no doubt the
firm would earn a profit, but the firm may not be earning the maximum that
it can possibly earn.

The marginal cost is the increment in cost to produce the next good. For example say it costs $100 to produce 100 goods. If it costs $101.01 to produce 101 goods, then the marginal cost at the 100th good is $1.01. If it costs $102.03 to produce 102 goods, then the marginal cost at the 101st good is $1.02. Since the production cost function is convex, the marginal cost will always be increasing. The calculus solution suggests that the firm should bring exactly the quantity q whose marginal cost is equal to the market price p. Why does this maximize the firm's profit?

The criterion maximizes the firm's profit in the following way.
Suppose the price is $2 and the quantity whose marginal cost exactly equals
$2 is 140. That means the production of the 141st good would cost
$2. Hence this 141st good would earn zero profit even if sold in
the market. Therefore this 141st good need not be brought to market.
If the firm produces more than 140 goods, then all those goods in excess
of 141, would earn negative profit, that is these goods will incur loss
when sold at the market at $2 each. Therefore the small firm should
definitely not bring more than 140 goods to the market. Should the
firm bring less than 140 goods? Since the production cost function
is convex, we know that the marginal cost of each good before and at the
140 quantity is less than $2 each. Hence the trade of each one would
earn a positive profit. Hence the firm should attempt to sell every
one of these goods. Therefore the firm should not bring less than
140 goods to the market. Thus the calculus solution is verified to
be indeed the optimal quantity to earn maximum profit.

For example suppose I have a pencil factory and I would like to decide
on how many pencils to produce. I assume that all pencils produced
will be brought to the market, and the market would pay me a fixed price
for all my pencils. The factory has a human operated machine, which
produces pencils at a constant rate. As I increase the number of
pencils produced, the machine would need more frequent repairs and maintenance,
then the production workers need higher compensation pay. Thus the
production cost is arguably convex. Therefore by the calculus solution
above, I would do a study on the marginal production cost of each additional
pencil, and would produce exactly the number that matches the market price
of pencil. This quantity is not directly dependent on the standard
capacity of my factory's production. For example I may find that
it is more optimal for me to under work each day, doing 7 hours days instead
of the standard 8 hours days. I may just as likely find that it is more
optimal for me to over work each day, doing 20 hours days instead of the
standard 8 hours days. Thus only through the study of marginal cost,
can I realize whether my present production is at its optimal.

Finally I would like to make a suggestion on how to optimize in view
of such difficulty in marginal cost estimation. I propose that the
firm should start with a rough estimation and evolve its production decision
as outcomes are observed. For example if the annual review of the
production cost is higher than expected, then the firm should likely lower
its production. If the production machines are wearing down, the
firm should also lower its production. Conversely if there are new
cost cutting innovations in the production process, or if the financing
cost or tax are lowered, then the firm should increase its production.
Thus a lot of sound business judgement is needed to supplement the inaccuracy
of marginal cost estimation. The inaccuracies in estimation do not
make the marginal cost concept irrelevant in the business decision.
Instead it helps us identify factors that the firm should pay attention
to when making optimal production decisions.