Plot multiple data with DiscretePlot

134 Views Asked by At

Currently, I'm plotting a single discrete function f known on a discrete set t using the following code:

t := Vector(3, [0.1, 0.2, 0.3])
f := Vector(3, [1, 2, 3])
DiscretePlot(t, f)

Now, suppose I've got a second function g known at the same set t. How can I plot f and g in the same plot?

1

There are 1 best solutions below

0
On BEST ANSWER

Here are a few different ways to accomplish that.

restart;
with(DynamicSystems):

t := Vector(3, [0.1, 0.2, 0.3]):

f := Vector(3, [1, 2, 3]):
g := Vector(3, [1, 4, 9]):
h := Vector(3, [1, 8, 27]):

plots:-display(
  DiscretePlot(t, f, color=red),
  DiscretePlot(t, g, color=green),
  DiscretePlot(t, h, color=blue)
);

col_list := [red,green,blue]:
dat_list := [f,g,h]:

plots:-display(zip((a,b)->DiscretePlot(t,a,color=b),
               dat_list, col_list));

plots:-display(seq(DiscretePlot(t, dat_list[i],
                                color=col_list[i]),
               i=1..3));