Function of polygonplots does not plot all polygons

99 Views Asked by At

Could anyone explain to me why my Maple-Code does not work properly?

 with(plots):
 plotSet := proc(M) 
 local n::posint, dispM; 
 n := nops({M}); 
 dispM := map(i -> 
                  polygonplot([[M[i], 0], [M[i+1], 0], [M[i+1], 1], [M[i], 1]], 
                  color = red),
              [$1 .. n]);
 display(dispM);
 end proc;

If I want to plot following:

 plotSet([0, 1/5], [2/5, 3/5]);

Maple just plots the first rectangle. Why doesn't it plot all rectangles?

1

There are 1 best solutions below

1
On

The short answer is that since you only declared one argument, Maple only sees one argument. That is, M is simply [0, 1/5]. Extra arguments are by default ignored by Maple procedures. You get around this by declaring M to be a sequence via

plotSet:= proc(M::seq(list))

But after that there are other problems with your procedure. See my comment.

Update: Make the procedure thus:

plotSet:= proc(M::seq(list)) 
local n::posint, dispM; 
     n:= nops({M}); 
     dispM:= map(i -> 
          plots:-polygonplot([[M[i][1], 0], [M[i][2], 0], [M[i][2], 1], [M[i][1], 1]], 
               color = red),
          [$1 .. n]);
     plots:-display(dispM);
end proc;

A better procedure is

plotSet:= proc(M::seq(list))
local m::list;
     plots:-display([
          seq(
               plots:-polygonplot(
                    [[m[1],0], [m[2],0], [m[2],1], [m[1],1]],
                    color= red
               ),
               m in M
          )
      ])
end proc: