# Calculating a parametrized maximum, as a function of the parameter

Suppose I have the following maximization problem:

Maximize[{x^2-a,0<=x<=a},{x}]


The result is a function of $a$:

I want to extract this function of $a$. I tried:

mm[a_] := Out[34][[1]]


but this did not work. For example, mm[1] returns:

What is the correct way of defining this function?

There are some things you need to be aware of and I advise to read the most common pitfalls post. Learn the difference between := and = and don't use things like Out in a definition. That definitely bites you at some point.
{res, val} = Maximize[{x^2 - a, 0 <= x <= a}, {x}];