MAPLE ORIENTATION LAB #2

 

In working with MAPLE this semester, you will be dealing primarily with three different types of objects.  They are:  expressions, functions, and equations.  Different commands in MAPLE apply to different objects.  For example the solve command can be used on equations but not expressions or functions.  The plot command can be used on expressions and functions of one variable but not on equations.  Later on in the course you will learn about the D operator which can be used on all three, expressions, functions, or equations.  (You will also work some with inequalities.)  Consult your textbook to review functions and related concepts.

 

 

EXPRESSIONS

 

Expressions are probably the most familiar to you as you have seen these daily in your previous mathematics courses.  It is difficult to define an expression, so examples of expressions might be the simplest way to learn what they are.  Here are examples of expressions written in MAPLE language.

 

1+1

(x+y)^2

(x+y)*(x^3-y^3)*(z+y)

x/(x+1)

x^4-2*x^3+Pi*x^2-6*x+sqrt(2)

x^3*y^7/z^(1/2)

sin(Pi/2)+2^4-65*mm

2+3*x 

 

Expressions could be defined as a list of variables, numbers, and other symbols (like ^, * and /) which indicate arithmetic operations for the variables and numbers.  MAPLE treats the variables in an expression as if they were real (or complex) numbers or even names of functions when applicable.  Thus for example when the command expand is used on , MAPLE will use the distributive, associative and commutative properties for real numbers and respond with.  (Note:  These properties also hold for complex numbers and functions.)

 

 

FUNCTIONS

 

Recall that the mathematical definition of a function is a rule that assigns to every member of a given set A, called the domain, exactly one element from another set B.  Normally, we give functions names.  A common name is the name f.  If we give a function with domain A the name f, then for a in the set A, f(a) is the element of B that the function f assigns to a and is called the image of the function f at a.  Also the set  which is a subset of B is called the range of the function f.  The functions that we use in MATH 111 all have domains that are subsets of the real numbers  while the set B can be thought of as all real numbers.  Thus the range of functions in MATH 111 will also be some subset of the real numbers.  These functions can be described by saying they are real-valued functions (the range is a subset of ) of one real variable (the domain is a subset of ).

 

Until now some type of formula, such as , defines most of the functions you have seen. This formula tells us that the function named ÒfÓ takes a real number x and assigns to it the number x divided by x plus 1.  For example, f assigns to an input of 2 the output 2/3.  If no domain for the function is stated then the function has an understood domain, the largest subset of  for which the formula for f(x) makes sense.  For the example above, the understood domain is .

 

There are three relatively simple ways to define functions in MAPLE:

 

i)  the use of the 'arrow'  (->)

ii) the use of unapply  on an expression

iii) the use of proc or piecewise.

 

We will illustrate the use of each of the three ways.

 

i)  Arrow

To define the function above using this method, we simply type

 

> f:=x -> x/(x+1);

 

(Recall the arrow is formed by typing a dash and then a greater than symbol.)  The rule  tells how values of the function named ÒfÓ are calculated.  In fact, if you type

 

> f(t); 

 

then MAPLE will respond with the expression  .

Typing

 

> f(t+h);

in MAPLE will yield  .  MAPLE uses the understood domain of the function.  If you type f(–2) in MAPLE the response will be 2, but if you type f(–1) MAPLE will respond with an error message telling you it tried to divide by zero. 

 

If you havenÕt already typed

 

> f:=x -> x/(x+1);

 

do so now.

 

ii)  Unapply

This command can be used when you have a previously defined expression that you want to convert into a function.  For example, suppose in a worksheet that you made the assignment

 

 > s1:=(1/2)*g*t^2+v0*t+s0;

 

which is the position of an object that is falling in a constant gravitational field.  If you wanted to convert this to a function, named s, of the variable t, you would type

 

> s:=unapply(s1,t);

 

We now have  defined in two ways.  First as an expression named s1, second as the output of a function named s.

 

This method also assumes the understood domain for any defined function.

 

iii)  Proc or piecewise

 

This method can be used to define complicated functions (or simple ones).  For example suppose we wanted to define a function h given by the formula

 .

 

To define this function in MAPLE, type

 

> h:= x->piecewise(x<=1,x^2-x,x>1,x^2+x);

 

or

 

> h:=proc(x); if x > 1 then x^2+x else x^2-x fi; end;

 

The word fi ("if" backwards) is MAPLE's way of saying this is the end of the if statement.

 

 

IMPORTANT NOTE

 

It is critical to distinguish between functions and expressions both in general and within MAPLE.  Consider the example from part i) above where we defined a function named ÒfÓ whose function values, f(x), are given by the formula  .  The function f is the rule that assigns to x the number  .  Thus in some sense, the function is something unseen, an abstract concept.  The formula f(x) =  is not the function but tells us that the image of x under the function f is  .  In MAPLE, f is again the name of the function.  The fact that f names a function is signified by the arrow or in case iii) by the word proc.  However,  is an expression in MAPLE and so is f(x).  Thus MAPLE makes the same distinction between functions and expressions as mathematicians make between a function and the image of the function.

 

 

GRAPHING FUNCTIONS

 

Functions are graphed with the plot command.  To plot a function that has been defined in the worksheet and whose name is f, type

 

> plot(f);

 

and the default domain will be the interval [–10,10].  Specify the domain and range by typing

 

> plot(f,a..b,c..b);

 

where ÒaÓ and ÒbÓ represent the desired limits of the domain, and ÒcÓ and ÒdÓ the limits of the range.

For practice, have MAPLE plot the function .  Specifying a non-default domain and range will give you a better picture. 

 

Maple can also graph several functions at once.  Like sets of equations or sets of expressions, sets of functions are enclosed in curly (set) brackets with commas between the names of the functions.  For example, to graph and k(t) = 2t on the domain interval [0,5] and range interval [0,25] type

 

> h:=t-> t^2;

> k:=t-> 2*t;

> plot({h,k},0..5,0..25);

 

 

EQUATIONS

 

You probably are also quite familiar with equations.  We can also name equations in MAPLE.  For example, the assignment

 

> eq1:=3*x+4 = x + 1/x;

 

assigns eq1 to be the name of the equation above.  We can then do things with this equation  by referring to its name eq1.  For example, we can type  

 

> solve(eq1,x);

 

and MAPLE will solve the equation for x.  Another thing we can do is multiply or divide both sides of an equation by a number.  If we type

 

 > eq1*x;

 

MAPLE will respond with .  If we then type

 

> expand(%);

 

MAPLE responds with .  If we have defined another equation and given it the name eq2, then we can add corresponding sides of these equations by typing 

 

> eq1+eq2; 

 

Later on you will be doing even more with equations.

 

If you ever have questions regarding the differences among expressions - functions - equations

be sure to ask.  There is a subtlety here that often creates confusion, especially between functions and expressions.

 

 

 

 

PROBLEMS

 

1.  Solve the following equations for x.  In some of the problems fsolve may give more meaningful results than solve.

 

     

 

     

 

      c)  3x + 2y = 4xy

 

 

2.   Solve the following inequalities for x.  Be sure to interpret the MAPLE output.

 

      a)  (x – 4)(x + 1) < –6

 

      b) 

 

      c) 

 

 

3.   a)  Define the function f in Maple given by f(x)=|x|.

 

      b)  Plot the graph of f.

     

      c)   (a*b), and f(–a).

       

      d)  Plot the graph of y = | |x| – 1|.

 

 

4.   Define the function p in Maple given by p(x) = | x + 1 | – 2.  Plot the graph of p, the graph of g where g(x) = p(–x) and the graph of h where h(x) = –p(x).

 

 

5.   Define the function f in Maple given by

     

      a)   Find .

      b)   Find f(–a) and f(a*b)

 

      c)   Do the following give equivalent results: f(a+b) and f(a) + f(b)?

 

      d)   Compute the quotient  

 

                                     

      and simplify it.

 

6.   Define a function g by .

      a)   What is the understood domain of g?

 

      b)   Find g(0), g(1), g(2), g(–1), g(6), and g(–6).

 

      c)   Plot the graph of g.

     

7.   Use the functions f and g given in problems 5 & 6.

      a)   What is f(g(x))?

      b)   What is g(f(x))?

      c)   What is the understood domain of ?

      d)   What is the understood domain of ?

      e)   Sketch the graph of each of the composite functions above.

 

8.   Define a function h by .

      a)   Plot the graph of this function.

         b)   At what value(s) of x does it cross the x-axis?

         c)   At what value(s) of y does it cross the y-axis?

 

9.   Submit an electronic copy of the MAPLE Worksheet you used to solve the eight problems above.  Then write several paragraphs to complete the following parts.

a)   Describe the differences among the following concepts: expression, function, and equation.

      b)   Describe how to define a function in MAPLE.

      c)   Describe the difference between the name of a function in MAPLE and the image of that

            function at some point.

 

© Mathematics and Computer Science Department,

The College of Wooster, Wooster, OH 44691