Skip to Main Content Skip to Search
Product Documentation

plot::Sequencesequences

plot::Sequence(y(n), n = n_1..n_2) creates the points

(n_1, y(n_1))(n_1 + 1, y(n_1 + 1))Symbol::hellip(n_2, y(n_2))`.`

plot::Sequence(x(n), y(n), n = n_1..n_2) creates the sequence of points

(x(n_1), y(n_1))(x(n_1 + 1), y(n_1 + 1))Symbol::hellip(x(n_2), y(n_2))`.`

→ Examples

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
x, y are equivalent to the attributes XFunction, YFunction.

n

the index of the sequence: an identifier or an indexed identifier
n is equivalent to the attribute UName.

n1 .. n2

the range of the index n: real-valued expressions, possibly of the animation parameter a
n1 .. n2 is equivalent to the attributes URange, UMin, UMax.

See Also:

plot, plot::copy, plot::Curve2d, plot::Function2d, plot::PointList2d

Details:

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))

MuPAD graphics

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))

MuPAD graphics

Example 2

By giving two expressions, we can make plot::Sequence plot a sequence of points given by two expressions, for the x- and y-coordinate:

plot(plot::Sequence(sin(2*PI*n/60), cos(2*PI*n/60),
                    n = 1..60), Scaling=Constrained)

MuPAD graphics

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)

MuPAD graphicsimage

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)

-1.064963748

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)

MuPAD graphicsimage

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)

MuPAD graphicsimage

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

  


Recommended Products

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