| Contents | Index |
plot::Sequence(y(n), n =
) creates the points
![]()
plot::Sequence(x(n), y(n), n =
) creates the sequence of points
![]()
Calls:
plot::Sequence(y, n = n1 .. n2, <a = amin .. amax>, Options)
plot::Sequence(x, y, n = n1 .. n2, <a = amin .. amax>, Options)
Parameters:
|
x, y: |
real-valued arithmetical expressions in n and possibly the animation parameter a. |
|
n: |
the index of the sequence: an identifier or an indexed identifier. |
|
n1 .. n2: |
the range of the index n: real-valued expressions, possibly of the animation parameter a. |
See Also:
plot, plot::copy, plot::Curve2d, plot::Function2d, plot::PointList2d
Details:
plot::Sequence creates graphs of sequences, i.e., functions and curves defined over (some subset of) the integers.
plot::Sequence(y(n), n =
) is functionally equivalent to the call plot::PointList2d([[n, y(n)] $ n =
), and plot::Sequence(x(n), y(n), n =
) creates the same image as plot::PointList2d([[x(n), y(n)] $ n =
). See example 2 for some extra functionality.
Example 1
When given one expression and a range, plot::Sequence plots the sequence in function style:
plot(plot::Sequence((-1)^n/n, n=1..10))

plot::Sequence accepts a variety of attributes to influence the appearance of the plot:
plot(plot::Sequence((-1)^n/n, n=1..10,
PointStyle = FilledDiamonds,
PointSize = 4*unit::mm,
Color = RGB::Red),
plot::Sequence(1/n, n=1..10,
PointsVisible = FALSE,
LinesVisible = TRUE),
plot::Sequence(-1/n, n=1..10,
PointsVisible = FALSE,
LinesVisible = TRUE))

Example 2
By giving two expressions, we can make plot::Sequence plot a sequence of points given by two expressions, for the
- and
-coordinate:
plot(plot::Sequence(sin(2*PI*n/60), cos(2*PI*n/60),
n = 1..60), Scaling=Constrained)

In contrast to the plot::PointList2d call listed above as equivalent, plot::Sequence allows to easily animate the number of points:
plot(plot::Sequence(sin(2*PI*n/60), cos(2*PI*n/60),
n = 1..nmax, nmax = 1..60),
Scaling=Constrained, Frames = 60, TimeRange = 1..60)


Example 3
By including the animation parameter in the expressions x and y, more complex animations are possible. As an example, we animate Newton iteration for different starting values. First of all, we define the iteration step which maps an approximation to its refinement:
newton := x -> x - f(x)/f'(x):
For concrete calculations, we will need to use a specific function f:
f := x -> sin(2*x) + x^2:
To get successive iteration steps, we will employ the function iteration operator @@. For example, the third improvement of the starting value 1.0 is calculated as follows:
(newton@@3)(1.0)
![]()
For our animation, we want to show the approximations, the corresponding function values, and the order in which the approximations are found. Additionally, we display the function itself:
function := plot::Function2d(f, x = -2..2):
steps := plot::Sequence((newton@@n)(x0), f((newton@@n)(x0)),
n = 0..5, x0 = -1.25..1.5,
Color = RGB::Green,
LinesVisible = TRUE):
plot(function, steps,
ViewingBox = [-2..2, -1..5], PointSize = 2.5)


To further increase the number of iteration steps, we should reuse previously computed approximations. To this end, we use a function with option remember:
newtonIter := proc(x0, n)
option remember;
begin
if domtype(n) <> DOM_INT then
return(procname(args()));
end_if;
if iszero(n) then x0
else newton(newtonIter(x0, n-1));
end_if;
end_proc:
Additionally, we use plot::Point2d to display the initial point in a different color.
steps := plot::Sequence(newtonIter(x0, n), f(newtonIter(x0, n)),
n = 0..10, x0 = -1.25..1.5,
Color = RGB::Green,
LinesVisible = TRUE):
start := plot::Point2d(x0, f(x0), x0 = -1.25..1.5):
plot(function, steps, start,
ViewingBox = [-2..2, -1..5], PointSize = 2.5)


Since f was evaluated in our object definitions, we will need to reissue the corresponding commands when changing f.

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |