You can find this session in /home/ceng303/maple/sessions as: ch1_6.mw


Section 1.6 Session: creating simple functions

> restart;

>x:=2.1; Assign x a value

x := 2.1

We can define an expression to square x by:

>fe:=x^2; fe is an  expression that gives the square of x which at present has the value 2.1.

fe := x^2

We might also try:

>fe2(x):=x^2;fe2 is also an expression but it looks like a function.

fe2(x) := x^2

Now: compare fe to fe2 when we give x a new value:

> x:=3.5;

x := 3.5

> fe;  fe does not change.

12.25

> fe2(x);  fe2 does not act like x squared.

fe2(3.5)

> fe2(2.0);  the argument is shown but no evaluation as a function takes place.

fe2(2.0)

> evalf(fe2(x));  even using evalf does not help.

fe2(3.5)

> f:=x->x^2; Here is one way to define a function.   The arrow is a minus sign followed by a greater than sign: ">".   The "x" used in its definition is a dummy argument.

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

> f(x); f maps x to the square of x (but x still has the value 3.5).

12.25

> f(t); It  maps t to the square of t

t^2

> f(2.5); It maps any number into the square of that number

6.25

>