Section 1.6 Session: creating simple functions
> restart;
> x:=2.1; <- Assign x a value
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.
We might also try:
> fe2(x):=x^2; <- fe2 is also an expression but it looks like a function.
Now: compare fe to fe2 when we give x a new value:
> x:=3.5;
> fe; <- fe does not change.
> fe2(x); <- fe2 does not act like x squared.
> fe2(2.0); <- the argument is shown but no evaluation as a function takes place.
> evalf(fe2(x)); <- even using evalf does not help.
> 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(x); <- f maps x to the square of x (but x still has the value 3.5).
> f(t); <- It maps t to the square of t
> f(2.5); <- It maps any number into the square of that
number
>