\subsection{Functions}

\SAGE allows one to construct piecewise-defined functions.
To define

\[
f(x) =
\left\{
\begin{array}{ll}
1,& 0<x<1,\\
1-x, & 1<x<2,\\
2x, & 2<x<3,\\
10x-x^2, 3<x<10,
\end{array}
\right.
\]
type

\begin{verbatim}
sage: f1 = x^0
sage: f2 = 1-x
sage: f3 = 2*x
sage: f4 = 10*x-x^2
sage: f = Piecewise([[(0,1),f1],[(1,2),f2],[(2,3),f3],[(3,10),f4]])
sage: f
Piecewise defined function with 4 parts, [[(0, 1), 1], [(1, 2), -x + 1], [(2, 3), 2*x], [(3, 10), -x^2 + 10*x]]
\end{verbatim}%link

\noindent
By convention, we assume this takes the average value of the jumps at
each of the inner midpoints.

To compute critical points and function values, 

%link
\begin{verbatim}
sage: f.critical_points()
[5.0]
sage: f(5)
      25
sage: f(1/2)
      1
sage: f(1)
      1/2
sage: f(0)
      1
sage: f(10)
      0
\end{verbatim}
Several other methods are available for these functions, such as laplace transforms,
Fourier series, and plotting (not only of the function itself but even the
plotting of the partial sums of Fourier series of the function).
See the section on ``piecewise functions'' in the \sage
reference manual for examples.
