0
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Your question was hard to read and incorrectly formatted. I edited it as best I could. Please familiarize yourself with the editing tools: mathematica.stackexchange.com/editing-help $\endgroup$ Commented Jan 26, 2013 at 18:34
  • $\begingroup$ Your main issues are your syntax (you've missed the underscore in the function definition) and the use of unnecessary For loops. $\endgroup$ Commented Jan 26, 2013 at 22:10

1 Answer 1

7
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ Alchemy as well as wizardry... $\endgroup$ Commented Jan 26, 2013 at 18:46
  • $\begingroup$ @Mr.Wizard: thanks..that exactly what I wanted to know ! $\endgroup$ Commented Jan 27, 2013 at 5:31
  • 1
    $\begingroup$ @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. mathematica.stackexchange.com/a/3146/121 $\endgroup$ Commented Jan 27, 2013 at 5:46
  • $\begingroup$ @Mr.Wizard:thanks for suggestion on optimization...I will code more on it..thanks again :) $\endgroup$ Commented Jan 27, 2013 at 6:01

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.