# Create a plot of vectors using a Do-Loop?

**URL:** <https://community.wolfram.com/t/create-a-plot-of-vectors-using-a-do-loop/10190>\
**Category:** Questions\
**Tags:** graphics-and-visualization\
**Created:** [March 21, 2017, 11:42am UTC](https://community.wolfram.com/t/create-a-plot-of-vectors-using-a-do-loop/10190 "2017-03-21T11:42:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![terryackerman](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@terryackerman](https://community.wolfram.com/u/terryackerman)\
**Post date:** [March 21, 2017, 11:42am UTC](https://community.wolfram.com/t/create-a-plot-of-vectors-using-a-do-loop/10190/1 "2017-03-21T11:42:18Z")

</div>

I am trying to create a plot of vectors using a Do-loop and  
“Graphics [{Arrow[{…”. Within the Do loop I calculate  
the beginning (X,Y) and ending coordinates (X1,Y1) for each vector.  
Can I use the “Graphics [{Arrow[{” command within a Do-Loop  
or do I first have to create a Table? Below is my code.  
Terry

```
A = {
{.79, 1.36}, {.93, 1.38}, {.58, .38}, {.87, .87}, {.83, .79}, 
{.31, .99}, {.60, .48}, {.60, .87}, {1.64, .15}, {1.11, 1.30}, 
{.53, .97}, {1.26, .39}, {2.37, .00}, {1.17, 1.76}, {.96, 1.26}, 
{.56, .46}, {1.17, .20}, {.63, .26}, {1.01, .47}, {.81, .77}};

DI = {-.90, -1.20, 1., -.97, -1.08, -1.53, -.61, -.60, 
  1.24, -.69, -1.31, .92, 2.39, -.06, -.48, -.82, -.82, 
  1.11, .66, -.15, -1.08}

Do[MDISC = Sqrt[A[[i, 1]]^2 + A[[i, 2]]^2];
 COSX = A[[i, 1]]/MDISC;
 COSY = A[[i, 2]]/MDISC;
 BIGD = -DI[[i]]/MDISC;
 X = BIGD*COSX;
 Y = BIGD*COSY;
 X1 = (MDISC + BIGD)*COSX;
 Y1 = (MDISC + BIGD)*COSY;
 Graphics[{Arrow[{{X, Y}, {X1, Y1}}]}], {i, 20}]

```

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [March 21, 2017, 2:34pm UTC](https://community.wolfram.com/t/create-a-plot-of-vectors-using-a-do-loop/10190/2 "2017-03-21T14:34:59Z")

</div>

Use **Table** rather than **Do** to store your results (Graphics in this case).

---

<div class="post-metadata">

**Author:** ![terryackerman](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@terryackerman](https://community.wolfram.com/u/terryackerman)\
**Post date:** [March 22, 2017, 3:46pm UTC](https://community.wolfram.com/t/create-a-plot-of-vectors-using-a-do-loop/10190/3 "2017-03-22T15:46:39Z")

</div>

Sander,  
That helps. I made the changes. But how to I get all of the vectors in the same plot and specify the range of the x and y axes? Here is my current code:

```
A = {{.79, 1.36}, {.93, 
    1.38}, {.58, .38}, {.87, .87}, {.83, .79}, {.31, .99}, {.60, \
.48}, {.60, .87}, {1.64, .15}, {1.11, 
    1.30}, {.53, .97}, {1.26, .39}, {2.37, .00}, {1.17, 1.76}, {.96, 
    1.26}, {.56, .46}, {1.17, .20}, {.63, .26}, {1.01, .47}, {.81, \
.77}};
DI = {-.90, -1.20, 1., -.97, -1.08, -1.53, -.61, -.60, 
  1.24, -.69, -1.31, .92, 2.39, -.06, -.48, -.82, -.82, 
  1.11, .66, -.15, -1.08}
Table[MDISC = Sqrt[A[[i, 1]] 2 + A[[i, 2]] 2];
 COSX = A[[i, 1]]/MDISC;
 COSY = A[[i, 2]]/MDISC;
 BIGD = -DI[[i]]/MDISC;
 X = BIGD*COSX;
 Y = BIGD*COSY;
 X1 = (MDISC + BIGD)*COSX;
 Y1 = (MDISC + BIGD)*COSY;
 Graphics[{Arrow[{{X, Y}, {X1, Y1}}]}], {i, 20}]

```

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [March 22, 2017, 3:49pm UTC](https://community.wolfram.com/t/create-a-plot-of-vectors-using-a-do-loop/10190/4 "2017-03-22T15:49:17Z")

</div>

Look up the documentation of **Show**. You can also NOT use **Graphics** inside the **Table** , and then use **Graphics** on the entire result of the **Table**.
