0

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Pankaj Sejwal
  • 2,063
  • 14
  • 23
  • Your question was hard to read and incorrectly formatted. I edited it as best I could. Please familiarize yourself with the editing tools: http://mathematica.stackexchange.com/editing-help – 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

1 Answers1

7

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

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

Mathematica graphics

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • Alchemy as well as wizardry... – cormullion Jan 26 '13 at 18:46
  • @Mr.Wizard: thanks..that exactly what I wanted to know ! – Pankaj Sejwal Jan 27 '13 at 05:31
  • 1
    @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. http://mathematica.stackexchange.com/a/3146/121 – Mr.Wizard Jan 27 '13 at 05:46
  • @Mr.Wizard:thanks for suggestion on optimization...I will code more on it..thanks again :) – Pankaj Sejwal Jan 27 '13 at 06:01