#Graphing
#Standard Coordinates
# Maple can construct many kinds of graphs, a feature that you can use to
# visualize mathematical objects and processes. The command
plot( sin(3*x), x = -Pi..Pi );
# produces a plot containing the curve
# y = sin(3 x)
# for x in the interval from -Pi to Pi. No space is allowed between the
# double-dots in a plot command. Scales on the x-axis and y-axis are
# chosen in the maple engine. To change this behavior:
plot( sin(3*x), x = -Pi..Pi, scaling = constrained );
# Sometimes it is useful to restrict the range over which y varies. We
# get a misleading graph from
plot( tan(x), x = -5..5 );
# It does not accurately represent the vertical asymptotes of y = tan(x).
# Better results are obtained with
plot( tan(x), x = -5..5, y = -5..5 );
# We can plot several curves at once. To plot y = sin(x) and y = sin(3
# x) together we code
plot( { sin(x), sin(3*x) }, x = -Pi..Pi );
# The curve equations are inside set-delimiters of curly braces
plot(1+x^2,x=0.1 .. 0.8);
# Decimal points can conflict with double-dot range parsing
# [compare x=.1...8]
# Now the first argument of plot is a set of expressions to be graphed.
# Sets are enclosed in curly braces and individual items are separated by
# commas.
# We could also use the display command found in the plots package:
with(plots):
plot1 := plot( x^2, x = 0..4 ): # Don't display plot data, use colon
plot2 := plot( 3*x^2 - 2, x = 0..4 ):
display( [ plot1, plot2 ] );
#Parametric Equations
# A curve in the plane can be described as the graph of a function, as in
# the graph of
# 1 / 2\
# y = - sqrt\4 - x /
# 2
# for x in the interval from -1 to 1. It can be given parametrically as
#
# (x(t), y(t)) = (2 cos(t), sin(t))
#
# for t in the interval from 0 to Pi. Often we interpret such a curve as
# the path traced by a moving particle at time t . Use the plot command
# to draw a curve from this parametric description:
plot( [2*cos(t), sin(t), t = 0..Pi] );
# unconstrained, distorted graphic
plot( [2*cos(t), sin(t), t = 0..Pi], scaling = constrained);
# constrained is not distorted
#Polar Coordinates
# Polar plots are a special kind of parametric plot. The polar
# coordinates ( r, theta ) of points on a curve can be given as a
# function of some parameter t. In many cases the parameter is just the
# angle theta. Consider the ellipse defined in standard coordinates by
#
# x^2 + 4 y^2 = 4
#
# To find an equation relating the polar coordinates r and theta of a
# typical point on this ellipse, we make the substitution x = r cos(t)
# and y = r sin(t), where t = theta.
subs( x = r*cos(t), y = r*sin(t), x^2 + 4*y^2 = 4);
simplify( % );
solve( %, r );
# We find that the ellipse is the collection of points whose polar
# coordinates ( r, theta ) satisfy
#
# 2 4
# r = -----------------,
# 2
# 4 - 3 cos(theta)
#
# and the following commands draw the right half of the ellipse:
r := 2/sqrt( 4 - 3*cos(t)^2 ):
plot( [ r, t, t = -Pi/2..Pi/2 ], coords = polar );
# Here are some more of examples of polar plots that you can try:
plot( [ 1, t, t = 0..2*Pi], coords=polar ):
plot( [t, t, t = 0..2*Pi], coords=polar ):
plot( [ sin(4*t), t, t = 0..2*Pi], coords=polar ):
# a more realistic picture is obtained with scaling = constrained.
#Plotting Data
# Maple can plot data consisting of pairs of x and y values. For
# example,
data := [ [0, 0.53], [1, 1.14], [2, 1.84], [3, 4.12] ];
# defines data as a sequence of five points, ( x, y ) = (0, 0.53), etc.
# The result is a double list: something enclosed in square brackets,
# with comma-separatd elements in square brackets. Lists are used for
# collections of objects where the order matters.
data[1]; data[2]; data[3]; data[4];
# Individual items are accessed this way
data[3][2];
# To access the second coordinate of the third data point
# To plot the points in a double-list we use commands like
plot( data, style = point, symbol = circle, color = black);
plot( data, style = line, view = [0..4, 0..5] );
plot( data, style = line, title = "Experiment 1" ):
# Here the double quote is used to specify a plot title string. See
# ?plot[options] for more information, e.g., about symbols and line
# styles available. You could also try ?readdata and ?stats to find out
# how to read a file of data points into a Maple session.