Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to output an arrow based on input from user and I tried writing this small function to achieve this:

g[{matric}] := 
 For[i = 1, i < Length[mat], i++, 
  Graphics[{Arrow[{{0, 0}, {matric[[1]], matric[[2]]}}]}, Axes -> True, 
   AspectRatio -> Automatic]]

To call it: g[mat[[1]]]

which is not working !!

I want to send array as list for example {{1,2},{3,4}} and create its output as arrow but I don't know how to break this list.

The second problem is that I can generate plots using Apply[f,arg,{1}] but it gives different plots for different elements in the list,so how can I combine them together in one plot.

I know about Show command but I just wanted to know if there is any other way too.

share|improve this question
Your question was hard to read and incorrectly formatted. I edited it as best I could. Please familiarize yourself with the editing tools: – Mr.Wizard Jan 26 '13 at 18:34
Your main issues are your syntax (you've missed the underscore in the function definition) and the use of unnecessary For loops. – Verbeia Jan 26 '13 at 22:10
up vote 7 down vote accepted

Doing my best to interpret what you want:

g[matrix_] :=
 Graphics[{Arrow[{{0, 0}, #}]}, Axes -> True, AspectRatio -> Automatic] & /@ matrix

g[{{1, 2}, {3, 4}}]

Mathematica graphics

Notice the pattern matrix_ on the left-hand side and read Defining Functions.

To combine these properly simply use a single Graphics object with multiple Arrrows:

arrows[matrix_] := Arrow[{{0, 0}, #}] & /@ matrix

 arrows[{{1, 2}, {3, 4}}],
 Axes -> True,
 AspectRatio -> Automatic

Mathematica graphics

share|improve this answer
Alchemy as well as wizardry... – cormullion Jan 26 '13 at 18:46
@Mr.Wizard: thanks..that exactly what I wanted to know ! – Rorschach Jan 27 '13 at 5:31
@rafiki I'm glad I could help. It was not included in your answer but you would do well to learn about patterns and pattern matching. In this case it may be wise to match a more specific matrix before it is passed to the inner Function to make sure that the data given to Arrow is not invalid: arrows[matrix : {{_, _} ..}?(MatrixQ[#, NumericQ] &)] := -- this is a complicated pattern, somewhat intentionally: your effort to understand it may teach you several different aspects of Mathematica patterns and programming. Ask if you need help. – Mr.Wizard Jan 27 '13 at 5:46
@Mr.Wizard:thanks for suggestion on optimization...I will code more on it..thanks again :) – Rorschach Jan 27 '13 at 6:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.