Message Boards Message Boards

0
|
2794 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Create a plot of vectors using a Do-Loop?

Posted 7 years ago

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}]
POSTED BY: Terry Ackerman
3 Replies

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.

POSTED BY: Sander Huisman
Posted 7 years ago

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}]
POSTED BY: Terry Ackerman

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

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract