Up to Main Lab Page | Next Lesson - Working with Functions | Previous Lesson - Functions |
Maple has the ability to create plots of functions and expressions which we
define. This is done through the plot
function.
The syntax is plot(expression, range [, parameters])
function is the function we which plotted.
range is the range of values to be plotted.
parameters is an optional list of parameters for plot.
Thus to plot the function x2 from -1 to 1:
> plot(x^2, x = -1..1);
The range and plot variable is indicated by x=-1..1. This tells Maple that we
want x to be the plotted variable, -1 is the lower limit and 1 is the upper
limit.
The double dots '..' is generally used by Maple to indicate a range.
NOTE: This is not an assignment of x, we do not write 'x:=-1..1'.
The default is an inline plot, you can tell Maple to plot things in a seperate window by selecting |Options| |Plot Display| |Window|.
We can also use previously defined functions and expressions for the function
parameter.
> f:=x->x^2;
> plot(f(x), x = -1..1);
Note that if a function is not defined over a range then it is not plotted over
that range. For example try
> plot(sqrt(y),y=-1..1);
There are no negative x values plotted since sqrt is not defined for negative x
values.
If you want to plot two functions on the same graph you can enclose them in
parenthasise. Thus
> f:=x->x^2;
> g:=x->2*x;
> plot({f(x), g(x)}, x = -1..1);
will plot f and g on the same graph from -1 to 1.
We can tell Maple that the function is discontinuous by using the
discont
parameter in plot. Try
> plot(trunc(x), x=-3..3, discont=true);
f(x)
= {
x
if x < 0
x2 + 1
if 0 <= x < 1
x2
Otherwise
f(x)
= {
ex
if x < 0
sin2(x)
if 0 <= x < PI
sqrt(cos(x))
Otherwise
To see other parameters avalaible for plot try
> ?plot[options]
infinity
:While this can be useful it is generally discouraged. The reason for this is that in order to fit an infinite range on the x axis Maple has to squeeze the ends. Thus the plot may look nothing like the original function. Even in this simple example the ends of the plot do not look right, they start to curve away and down, rather than up (they appear cancave up rather than concave down). For this reason Maple does not print values on the axes when doing an infinite plot.
To see an example of this try plotting sin(x) on an infinite range and notice
how the ends bunch up, rather than giving a smooth sinusoidal curve out to
infinity.
Notice how the ends bunch up, rather than giving a smooth sinusoidal curve out to
infinity.
If we try
> f(0);
This is a general problem of scale, the fine detail was lost because the scale of the detail was far less than the scale of the graph, yet we are often interested in where graphs cross the x axis, and in turning points of a graph.
For another similar problem consider the plot
> plot(1/(1-x)^2, x=-infinity..infinity);
While the behaviour at infinity seems correct, this plot shows a peak at x = 1,
but we know that in fact the function is unbounded at x = 1, i.e. this peak is infinite.
If we try
> plot(1/(1-x)^2, x=0..2);
The scale of the peak completely overshadows the nearby behaviour.
About the best we can get is
> plot(1/(1-x)^2,x=0..2, 0..50);
Up to Main Lab Page | Next Lesson - Working with Functions | Previous Lesson - Functions | Top of this Lesson |