3

I am trying to plot some vectors of the form [x,-y] for any point (x,y) so I tried this:

for i:1 while i<=21 do 
    (for j:1 while j<=21 do
      (draw2d(
        xrange=[0,50],
        yrange=[0,50],
        vector([i,j],[i,-j])
        )
       ));

But the gnuplot window is gets refreshed on each iteration so I tried to put the two loops after draw2d and right before "vector" but that didn't work either.

Arcadio
  • 33
  • 4

1 Answers1

3

draw2d (likewise draw3d) draws a whole "scene" which is described by its arguments. Everything in the arguments is one "scene". So to create a scene with different things in it, you want to make a list that has all the things you want, and then apply draw2d to it, i.e., tell Maxima to call draw2d with that list of arguments.

Here's an example to illustrate that. I'll create a list of all the vectors first. The vector graphic object takes some options, such as head_type and so on. I'll make a list with the options I want, and then append the options and the vectors list to get all the arguments I want. Finally I'll call draw2d to display the scene.

(%i2) load (draw) $
(%i3) myvectors: makelist (makelist (vector([i, j], [i, -j]), j, 1, 5), i, 1, 5);
(%o3) [[vector([1, 1], [1, - 1]), vector([1, 2], [1, - 2]), 
vector([1, 3], [1, - 3]), vector([1, 4], [1, - 4]), 
vector([1, 5], [1, - 5])], [vector([2, 1], [2, - 1]), 
vector([2, 2], [2, - 2]), vector([2, 3], [2, - 3]), 
vector([2, 4], [2, - 4]), vector([2, 5], [2, - 5])], 
[vector([3, 1], [3, - 1]), vector([3, 2], [3, - 2]), 
vector([3, 3], [3, - 3]), vector([3, 4], [3, - 4]), 
vector([3, 5], [3, - 5])], [vector([4, 1], [4, - 1]), 
vector([4, 2], [4, - 2]), vector([4, 3], [4, - 3]), 
vector([4, 4], [4, - 4]), vector([4, 5], [4, - 5])], 
[vector([5, 1], [5, - 1]), vector([5, 2], [5, - 2]), 
vector([5, 3], [5, - 3]), vector([5, 4], [5, - 4]), 
vector([5, 5], [5, - 5])]]
(%i4) vector_options: [head_length = 0.2, head_angle = 15, head_type = empty];
(%o4) [head_length = 0.2, head_angle = 15, head_type = empty]
(%i5) append (vector_options, myvectors);
(%o5) [head_length = 0.2, head_angle = 15, head_type = empty, 
[vector([1, 1], [1, - 1]), vector([1, 2], [1, - 2]), 
vector([1, 3], [1, - 3]), vector([1, 4], [1, - 4]), 
vector([1, 5], [1, - 5])], [vector([2, 1], [2, - 1]), 
vector([2, 2], [2, - 2]), vector([2, 3], [2, - 3]), 
vector([2, 4], [2, - 4]), vector([2, 5], [2, - 5])], 
[vector([3, 1], [3, - 1]), vector([3, 2], [3, - 2]), 
vector([3, 3], [3, - 3]), vector([3, 4], [3, - 4]), 
vector([3, 5], [3, - 5])], [vector([4, 1], [4, - 1]), 
vector([4, 2], [4, - 2]), vector([4, 3], [4, - 3]), 
vector([4, 4], [4, - 4]), vector([4, 5], [4, - 5])], 
[vector([5, 1], [5, - 1]), vector([5, 2], [5, - 2]), 
vector([5, 3], [5, - 3]), vector([5, 4], [5, - 4]), 
vector([5, 5], [5, - 5])]]
(%i6) apply (draw2d, %);

Of course, you can redo the example with the number of vectors equal to 21^2 instead of 5^2, and you can change the options as you want. You can also create other graphic objects and append them to the arguments list and then apply draw2d to all the arguments.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • https://commons.wikimedia.org/wiki/File:N-th_arm_stars.svg here is the example image with code – Adam Nov 12 '20 at 18:53