Chapter 1: Functions

Introduction

Perhaps the most basic concept in mathematics is that of a function.  A function is a set of relations or rules that assigns to each value x in the domain set X a unique value y in the range set Y.  A function is a special case of a more general concept, that of a relation.  Two examples of relations are

f(x)=(x^2)+2x+4 and ((x^2)/(a^2))+((y^2)/(b^2))=1,

where the first is also a function of x.

Functions appear in mathematics courses at a variety of levels.  In algebra and pre-calculus the concept of a function is introduced and the relationship between functions, relations and graphs are explored.  Concepts such as one-to-one, inverses and roots are investigated.  Basic functions such as polynomials, rational functions, exponential and logarithmic functions are introduced along with their graphs and a basic concept of increasing/decreasing and asymptotes.  In trigonometry the functions sin(x), cos(x) and so on, are introduced.  The concept of periodic functions, amplitudes, phase shift and frequency are explored.  In calculus, the concept of an operator, or function of functions, is introduced.  Two such operators are differentiation and integration.  Continuity, smoothness of functions (differentiability), slopes of curves (other than straight lines), concavity and maximum/minimum values of functions is usually covered in first semester calculus.  In second semester calculus sequences (functions over the integers), series, power series, parametric and polar functions are investigated.  In third semester calculus the concepts dealing with functions of more than one independent variable are introduced.  As a student progresses through the upper division mathematics courses, they are introduced to functions in the context of ordinary (and possibly partial) differential equations, dynamical systems and modeling, the complex number system, the topological and algebraic setting, and the analysis of real numbers.

    In this chapter we will explore some of the properties and concepts of functions and relations using Mathematica.  We will start with some of the basic Mathematica commands to input, manipulate and use functions.

Polynomials and Graphs

In this section we will use Mathematica to investigate some of the properties of polynomials.  Fist input and graph several polynomial functions.  Note that to execute a command use the <Shift><Enter> key or the number-pad <Enter> key.

Example 1:

f=x^2+2*x+1

Plot[f,{x,-5,5}]

Plot[f,{x,-10,10}]

g[x_]:=(x^2)+2 x+1

Plot[g[x],{x,-5,5}]

Note that in this example f is defined as an expression and g is defined as a function of x.  The "=" is used as an assignment operator, meaning that future references to the variable f would be interpreted to mean x^2+2*x+1.  In the definition for the function g the underscore indicates the independent variable of the function and the ":=" is a delayed assignment operator.  Also note that the multiplication operator is either "*" or a blank space (Mathematica treats 2x as one symbol, not as 2 x).

Example 2:

f[x_]:=Sin[x]+Cos[2 x]
Clear[f]
f[x_]:=Sin[x]+Cos[2 x]
q[CAT_]=Sin[CAT]+Cos[2 CAT]
q[Pi]

Note that the symbol f can not be used in a delayed assignment after being used as the left-hand-side of an assignment.  We use the Clear command to unassign the value on the symbol f.  Also note that the function q and the function f are, for all practical purposes, the same.  Lastly, note that multiple command lines can be entered in the same block, separated by a normal <Enter>.  A graph of this function follows.

Plot[f[x],{x,-2 Pi,2 Pi},PlotRange->{-2,2},PlotStyle->Red]

Example 3:

Clear[f,g,q]
f=x^2+5*x-24;
g=(x-3)*(x+2);
gobolyguk[x_]:=x^3+8

Note that the semicolon supresses the output on the asignments of f  and g. Also note that variable and function names can be quite expressive.  Next we show several basic algebraic manipulation command that can be used on expressions.

gobolyguk[2]

f/.{x->2}

Expand[g]

Factor[f]

Factor[gobolyguk[CAT]]

Expand[f*g]

h=Simplify[f/g]

k=h*gobolyguk[x]

Simplify[k]

Here we have used several commands to manipulate algebraic expressions (and functions).  Note that the output of a command can be assigned toa label and used in a later command (such as the use of h and k).  Also note that Mathematica commands have descriptive names: Expand for multiplying out polynomials, Factor for factoring polynomials, etc.

Now let's look at some useful commands for solving equations.  Many times in mathematics the solution to a problem involves finding the roots of an expression.  A value r is a root or zero of a function f if f(r)=0.

Example 4:

Clear[f]
f=x^2-2*x-3

We can look at a graph to see the where the roots of this function are located:

Plot[f,{x,-4,4},PlotRange->{-4,4}]

It looks like the zeros are at -1 and 3.  We can use Mathematica to find the roots through the following command:

Solve[f==0,x]

Note the use of the double equals in the Solve command instead of a single equal sign.  The double equals is used to express an equation, while the single equal sign is used by Mathematica to assign an expression or value to a label.

Example 5:

Clear[f]
f[x_]:=x^5-4*x^4+4*x^3-7*x^2+15*x-6
Plot[f[x],{x,-1,6},PlotRange->{-10,10}]

Solve[f[x]==0,x]

NSolve[f[x]==0,x]

Note how the Solve command returns something strange looking, while the NSolve command returns a numerical approximation to the foots of the polynomial.

Exercise 1.

(1) Define a Mathematica expression f=(((x^2)+1)/((x^2)-1)).  Plot the expression using ranges variaous ranges of values for the x and y axes.

(2) Define a Mathematica function f(x)=(x^4)-2 (x^3)-12 (x^2)+8.  Try using Solve and/or NSolve commands to find all of the roots of this function.  Graph the function with appropriate ranges to show al of the x-intercepts.  You might need to use the help menus and the examples therein to figure out how to make the Solve or NSolve command find each root.

(3) Define a Mathematica function f(x)=(x^3)-7 x+6.  Graph the function and find all of it's roots.

Calculus and Functions

In this section we will use Mathematica to explore the relationship that functions have in calculus.  We will first look at the concept of limits, then derivatives and integrals.  We will work with parametric and polar functions and their graphs.

First let's look at limits.

Example 1: Defind the function f(x)=((x+1)/((x^2)-1))and find the limit as x approaches -1, 1, and infinity.  Graph the function to check the limits.

Clear[f]

f[x_]:= (x+1)/(x^2-1)

Limit[f[x],x->-1]

Limit[f[x],x->1,Direction->1]

Limit[f[x],x->1,Direction->-1]

Limit[f[x],x->1]

Note that if the direction is not specified, then Limit command does not indicate an answer of "undefined".  This is due to viewing singularities in the context of complex numbers where both plus and minus infinity are viewed as the same value.  The point is that you must be carefull in how you interpret the output to the Mathematica Limit command.

Limit[f[x],x->Infinity]

Limit[f[x],x->-Infinity]

Plot[f[x],{x,-10,10},PlotRange->{-10,10}]

Notice the form of the Limit command excepts two or three arguements (at least).  Limits from the left or the right require the third Direction option.

Next, let's look at derivatives.  In Mathematica there are several commands used to diverentiate functions/expressions, we will look at the D command and the Derivative ( ' ) command.

Example 2: Using the D and Derivative commands.

y=x^3+2*x^2-5*x+10

dydx=D[y,x]

d2ydx2=D[y,x,x]

d3ydx3=D[y,{x,3}]

d4ydx4=D[y,{x,4}]

All higher derivatives will be 0.  Note that the output of one command could also be used as the input of another command.  Also note that the D command can take several forms either listing the individual derivatives (as in the second derivative), or can take higher derivatives directly (as in the third and fourth derivatives).

Now for the Derivative command:

yp=Derivative[1][y]

Notice that this didn't give the same sort of response as above.  The reason for this is that this command works on functions where the D command works on expressions.

Clear[y]
y[x_]=x^3+2*x^2-5*x+10

dydx=Derivative[1][y][x]

Note that here we differentiate the function y with respect to it's first variable, x, one time and then evaluate the result at x.

yp=y'

yp[x]

The alternate form of the Derivative command is using the single quote mark ( ' ).

y''[x]

Derivative[2][y][x]

Derivative[2][y][Pi]

Now let's look at integration.

Example 3:

Clear[f]
f[x_]=x^2+2*a*x+a^2

Here we have a function of x with a parameter a.  We can use the Fundemental Theorem of Calculus to generate an antiderivative as follows:

intf[x_]=Integrate[f[t],{t,0,x}]

intf[1]

Note that we used a definite integral where we pick the lower limit arbitrarily to be 0 and the upper limit to be x.  Alternately we could use the Math Assistant to enter the same function in a "pretty-print" form:

intf2[x_]=(∫_0^x)f[t]\[DifferentialD]t

Exercise 2.

(1) Define the function f(x)=(((x^3)-1)/((x-1)((x^2)-1))).  Find the limits as x approached 1, -1, and plus or minus infinity.

(2) Find the first and second derivative of the function in problem (1) as an expression.  Find the third and tenth derivatives of the function from problem (1) defined as a function.

(3) Find an antiderivative of the function in problem (1).

(4) Use the help (Document Center) and search for a direct way to get the partial fraction decomposition of the function in problem (1).  Use this and your calculus II knowedge to confirm the answer to problem (3).

(5) Evaluate the following definite integral: (∫_0^10)(e^((-(x^2))))dx.  (Note: in Mathematica the natural exponential function is Exp[].  Also, recall that NSolve was the numerical approximation to Solve.  Is there a corresponding Mathematica command to get a numerical approximation to a definite integral?)