A20-FunctionsRelations.mws

High School Modules > Algebra by Gregory A. Moore

     Functions & Relations


The definition of a function, and the connection with relations, domains and ranges, numeric and algebraic views of functions.

[Directions : Execute the Code Resource section first. Although there will be no output immediately, these definitions are used later in this worksheet.]

0. Code

>    restart; with(plots):

Warning, the name changecoords has been redefined

>    Domain  :=  proc( SET )
   local domain, k;
   domain := {};
   for k from 1 to nops(SET) do
     domain := domain union {SET[k][1]};
   od:
   domain;
end proc:

>    Range  :=  proc( SET )
   local range, k;
   range := {};
   for k from 1 to nops(SET) do
     range := range union {SET[k][2]};
   od:
   range;
end proc:   
 

1. Relations, Domains & Ranges


A relation is any pairing of values. A function is a special type of relation where each of the first type of item only has one of the second type.

>    fruity_colors := { [apple,red],[banana,yellow],[kiwi,green],
                   [cherry,red],[lemon,yellow],[pear,green]};

fruity_colors := {[apple, red], [banana, yellow], [kiwi, green], [cherry, red], [lemon, yellow], [pear, green]}


The first element of each pair is a fruit, and the second element is the color of the fruit. The set of all fruits is the domain of the relation, and the set of all colors is the range.

>    Domain(fruity_colors);

{apple, banana, kiwi, cherry, lemon, pear}

>    Range(fruity_colors);

{red, yellow, green}


Lets look at some other examples.

>    Baseball_teams := { [Los_Angeles, Dodgers], [New_York, Yankees],
                   [Toronto, Blue_Jays], [San_Francisco,Giants],
                   [Atlanta,Braves] };
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

Baseball_teams := {[Los_Angeles, Dodgers], [New_York, Yankees], [Toronto, Blue_Jays], [San_Francisco, Giants], [Atlanta, Braves]}

`\n the domain ` = {San_Francisco, Los_Angeles, New_York, Toronto, Atlanta}
`\n the domain ` = {San_Francisco, Los_Angeles, New_York, Toronto, Atlanta}

`\n the range ` = {Blue_Jays, Dodgers, Yankees, Giants, Braves}
`\n the range ` = {Blue_Jays, Dodgers, Yankees, Giants, Braves}

>    Typcal_foods := { [America, hotdog], [Mexico, Taco],
                   [Japan, Sushi], [India,Naan],[Middle_East,felafel],
                   [Vietnam,Pho] };
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

Typcal_foods := {[America, hotdog], [Mexico, Taco], [Japan, Sushi], [India, Naan], [Middle_East, felafel], [Vietnam, Pho]}

`\n the domain ` = {Middle_East, America, Mexico, Japan, India, Vietnam}
`\n the domain ` = {Middle_East, America, Mexico, Japan, India, Vietnam}

`\n the range ` = {hotdog, Taco, Sushi, Naan, Pho, felafel}
`\n the range ` = {hotdog, Taco, Sushi, Naan, Pho, felafel}


We can also have relations of numbers of course.

>    Number_set := { seq([k, k^2], k = 1..9) };
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

Number_set := {[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]}

`\n the domain ` = {1, 2, 3, 4, 5, 6, 7, 8, 9}
`\n the domain ` = {1, 2, 3, 4, 5, 6, 7, 8, 9}

`\n the range ` = {1, 4, 9, 16, 25, 36, 49, 64, 81}
`\n the range ` = {1, 4, 9, 16, 25, 36, 49, 64, 81}

>    Number_set := { seq([(k-2)^2, (k-4)^2], k = 1..7) };
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

Number_set := {[1, 1], [1, 9], [0, 4], [4, 0], [9, 1], [16, 4], [25, 9]}

`\n the domain ` = {0, 1, 4, 9, 16, 25}
`\n the domain ` = {0, 1, 4, 9, 16, 25}

`\n the range ` = {0, 1, 4, 9}
`\n the range ` = {0, 1, 4, 9}

2. Functions & Relations


A relation is any pairing of values. A function is a special type of relation where each of the first type of item only has one of the second type. The set of fruity colors is function because each fruit has only one color - even though some fruit may have the same color as other fruit.

>    fruity_colors := { [apple,red],[banana,yellow],[kiwi,green],
                   [cherry,red],[lemon,yellow],[pear,green]};
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

fruity_colors := {[apple, red], [banana, yellow], [kiwi, green], [cherry, red], [lemon, yellow], [pear, green]}

`\n the domain ` = {apple, banana, kiwi, cherry, lemon, pear}
`\n the domain ` = {apple, banana, kiwi, cherry, lemon, pear}

`\n the range ` = {red, yellow, green}
`\n the range ` = {red, yellow, green}


In this next case, some of the values of the domain have more than one value of the range. Thus this is NOT a function.

>    country_and_cities := { [Canada, Toronto], [Canada, Montreal], [USA, New_York],
         [ USA, Los_Angeles], [Mexico, Guadalajara], [Japan, Osaka],
         [ Japan, Tokyo], [Russia, Moscow], [India, Bombay],
         [India, Delhi]};
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

country_and_cities := {[Canada, Toronto], [Canada, Montreal], [USA, New_York], [USA, Los_Angeles], [Mexico, Guadalajara], [Japan, Osaka], [Japan, Tokyo], [Russia, Moscow], [India, Bombay], [India, Delh...
country_and_cities := {[Canada, Toronto], [Canada, Montreal], [USA, New_York], [USA, Los_Angeles], [Mexico, Guadalajara], [Japan, Osaka], [Japan, Tokyo], [Russia, Moscow], [India, Bombay], [India, Delh...

`\n the domain ` = {Mexico, Japan, India, USA, Canada, Russia}
`\n the domain ` = {Mexico, Japan, India, USA, Canada, Russia}

`\n the range ` = {Los_Angeles, New_York, Montreal, Guadalajara, Toronto, Osaka, Tokyo, Moscow, Bombay, Delhi}
`\n the range ` = {Los_Angeles, New_York, Montreal, Guadalajara, Toronto, Osaka, Tokyo, Moscow, Bombay, Delhi}


Look closely at these number sets. In the first set, each x value has only one y value. But this is not true in the second example. A function is a relation for which each member of the domain only is only associated with one member of the range. Thus the first set is a function, while the second one is not.

>    Number_set := { seq([k, k^2], k = 1..9) };
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

Number_set := {[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]}

`\n the domain ` = {1, 2, 3, 4, 5, 6, 7, 8, 9}
`\n the domain ` = {1, 2, 3, 4, 5, 6, 7, 8, 9}

`\n the range ` = {1, 4, 9, 16, 25, 36, 49, 64, 81}
`\n the range ` = {1, 4, 9, 16, 25, 36, 49, 64, 81}

>    Number_set := { seq([(k-3)^2, (k-5)^2], k = 1..7) };
`\n the domain `= Domain(%);
`\n the range ` = Range(%%);

Number_set := {[1, 1], [4, 16], [1, 9], [0, 4], [4, 0], [9, 1], [16, 4]}

`\n the domain ` = {0, 1, 4, 9, 16}
`\n the domain ` = {0, 1, 4, 9, 16}

`\n the range ` = {0, 1, 4, 9, 16}
`\n the range ` = {0, 1, 4, 9, 16}

3. Functions as Tables


Functions can also be expressed as tables of values. The values of x from the domain are on the left, and values of y from the range are at right.

>    restart:

>    f:= x -> 100-x^2:
array( [[ k,f(k) ] $ k = 0..8] );

matrix([[0, 100], [1, 99], [2, 96], [3, 91], [4, 84], [5, 75], [6, 64], [7, 51], [8, 36]])

>    f:= x -> 2*floor(x/2):
array( [[ k,f(k) ] $ k = 0..8] );

matrix([[0, 0], [1, 0], [2, 2], [3, 2], [4, 4], [5, 4], [6, 6], [7, 6], [8, 8]])

>    f:= x -> 2^x + 1;
array( [[ k, f(k)] $ k = 1..8] );

f := proc (x) options operator, arrow; 2^x+1 end proc

matrix([[1, 3], [2, 5], [3, 9], [4, 17], [5, 33], [6, 65], [7, 129], [8, 257]])


The values don't necessarily have to be integers.

>    f:= x -> :
array( [[ k,f(k) ] $ k = 0..8] );

Error, `:` unexpected

>    f:= x -> evalf(sin(Pi/(x+3))):
array( [[ k, f(k)] $ k = 1..8] );

matrix([[1, .7071067813], [2, .5877852524], [3, .5000000002], [4, .4338837393], [5, .3826834325], [6, .3420201433], [7, .3090169944], [8, .2817325569]])

4. Functions as Formulas


Most of the functions that we will see for now can be expressed as a formula of some sort. In these cases, there is an input, x, and and output f(x). For value of x, there is a corresponding value f(x).

>    f := x -> 3*x^2 -10*x + 21;
`f(0)` = f(0);
`f(1)` = f(1);
`f(-1)` = f(-1);
`f(10)` = f(10);
`f(100)` = f(100);
`f(10000)` = f(10000);

f := proc (x) options operator, arrow; 3*x^2-10*x+21 end proc

`f(0)` = 21

`f(1)` = 14

`f(-1)` = 34

`f(10)` = 221

`f(100)` = 29021

`f(10000)` = 299900021


Functions come in all shapes and sizes.

>    f := x -> (x^2 + 11)/(3*x^2 - 9);
`f(0)` = f(0);
`f(1)` = f(1);
`f(-1)` = f(-1);
`f(10)` = f(10);
`f(100)` = f(100);
`f(10000)` = f(10000);

f := proc (x) options operator, arrow; (x^2+11)/(3*x^2-9) end proc

`f(0)` = -11/9

`f(1)` = -2

`f(-1)` = -2

`f(10)` = 37/97

`f(100)` = 3337/9997

`f(10000)` = 33333337/99999997

>    f := x -> x - 3/(x^2 + 3);
`f(0)` = f(0);
`f(1)` = f(1);
`f(-1)` = f(-1);
`f(10)` = f(10);
`f(100)` = f(100);
`f(10000)` = f(10000);

f := proc (x) options operator, arrow; x-3/(x^2+3) end proc

`f(0)` = -1

`f(1)` = 1/4

`f(-1)` = -7/4

`f(10)` = 1027/103

`f(100)` = 1000297/10003

`f(10000)` = 1000000029997/100000003


Functions can also represent science formulas as well as abstract mathematical functions

>    Centigrade := F -> (5/9)*(F-32);
Centigrade(0); Centigrade( 212);

Centigrade := proc (F) options operator, arrow; 5/9*F-160/9 end proc

-160/9

100

>    Feet2Inches := inches -> inches * 12;
Feet2Inches(1); Feet2Inches(2.5);
Feet2Inches(6);

Feet2Inches := proc (inches) options operator, arrow; 12*inches end proc

12

30.0

72

>    Grams2Kg := grams -> grams*1000;
Grams2Kg(3000);  Grams2Kg(10);

Grams2Kg := proc (grams) options operator, arrow; 1000*grams end proc

3000000

10000


Notice that functions can also be evaluated with constants.

>    f := x -> (x+3)/(x-5);
f(6); f(15); f(Q); f(any_value);

f := proc (x) options operator, arrow; (x+3)/(x-5) end proc

9

9/5

(Q+3)/(Q-5)

(any_value+3)/(any_value-5)

>    f := x -> 100*x^3 + 2000*x +  3000;
f(6); f(15); f(Q); f(any_value);

f := proc (x) options operator, arrow; 100*x^3+2000*x+3000 end proc

36600

370500

100*Q^3+2000*Q+3000

100*any_value^3+2000*any_value+3000


         © 2002 Waterloo Maple Inc