Re: Functions with vector arguments
- To: mathgroup at smc.vnet.net
- Subject: [mg36233] Re: Functions with vector arguments
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 27 Aug 2002 02:07:55 -0400 (EDT)
- References: <akcpm8$557$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"anhjunk" <anhjunk at hotmail.com> wrote in message news:akcpm8$557$1 at smc.vnet.net... > Now an example that does not work : > g[u_,v_] := u-v > Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, > y1-y2} but instead one gets error messages Works fine for me. Please check that you have no existing definitions for the symbols used. Clear[g,x1,x2,y1,y2]; g[u_,v_]:=u-v g[{x1,y1},{x2,y2}] {x1-x2,y1-y2} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 > Some functions with vector arguments work as expected and some give > errors. I would appreciate if someone can clarify why. > > First an example of a function definition that works fine : > f[u_,v_] := u.v > Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 + > y1 y2. > > Now an example that does not work : > g[u_,v_] := u-v > Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, > y1-y2} but instead one gets error messages. > > Why ? And how do I fix g (i.e write a function that outputs the > difference of 2 vectors). > > Thanks >