functions.mws

Click on a box with a + inside to expland the section.

Functions versus expressions

Maple makes a big distinction between functions and expressions. Youu should too! Here are some examples.

> f:=x->5*x^2+1; This defines a function f.

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

> f(2);f(x); Evaluating a function at a certain point gives an expression, a particular value of the function.

21

5*x^2+1

> f(cos(y)); Another value of the function. It is an expression with a y in it, not a function of y.

5*cos(y)^2+1

> diff(f(x),x); diff differentiates expressions, not functions

10*x

> D(f); D differentiates functions, giving back another function

proc (x) options operator, arrow; 10*x end proc

> D(f)(3); Of course, you can evaluate the function D(f) at 3.

30

Combinations of functions

Maple allows you to define things like the product of two functions, their composition, etc.

> (sin^2)(x); sin(x)^2; a:=sin^2; The last item defines a function called a.

sin(x)^2

sin(x)^2

a := sin^2

> a(x); a(5.0); Here a is evaluated at x and at 5.0 (the decimal forces Maple to approximate)

sin(x)^2

.9195357646

> (cos*sin)(x); g:=cos*sin; Product expression versus product function.

cos(x)*sin(x)

g := cos*sin

> (cos@sin)(x); h:=cos@sin; Composition expression versus composite function.

cos(sin(x))

h := `@`(cos,sin)

> g(4); h(4); You can evaluate these new functions at a few points. Maple won't approximate until you ask it to.

cos(4)*sin(4)

cos(sin(4))

> evalf(%); Evaluate the last expression entered (not necessarily what lies just above in the worksheet!).

.7270351312

Plotting functions

> plot(f(x),x=-4..4,y=0..20); Plot the expression f(x) .

> plot(f,-4..4,0..20); Plot the function. The first range specified is for the argument, the second for the range.

[Maple Plot]