Piecewise functions

We are used to functions that have the same rule for all inputs. For example, f(x)=x² outputs the square of every input. Piecewise functions have different output rules, depending on the inputs. For example, we can define function g to output x² for all positive values of x and x³ for all negative values of x, so g(2)=4 and g(-2)=-8.