Re: Oh why is life never easy? Need help with |vector|
- Subject: [mg2798] Re: Oh why is life never easy? Need help with |vector|
- From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
- Date: Sun, 17 Dec 1995 02:08:39 -0500
- Approved: usenet@wri.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: University of Colorado, Boulder
In article <4ar5ut$2hq at dragonfly.wri.com>, ULI WORTMANN <ULI12 at HOMER.geol.chemie.tu-muenchen.de> wrote: >Hi All, > >I need to calculate v0 = v / |v| where v is a vector of size 3. >However, |v|, which is a scalar, is for some reason (I don't >understand) treated like a vector (at least VectorQ[|v|] gives >TRUE). Obviously, it is impossible to divide two vectors of different >length. > > |v| is defined as: > absvec[u_] := > Module[{a}, > {a = Sqrt[(u[[1]]^2+u[[2]]^2+u[[3]]^2)]}] The problem is that the body of your calculation is wrapped in list braces, so the result comes back wrapped in list braces, which is a vector of length 1. Anyway, a much better way to calculate the magnitude of a vector is like this: absvec[u_] := Sqrt[Plus @@ (u^2)] This function works on vectors of any length. Dave Wagner Principia Consulting (303) 786-8371 dbwagner at princon.com http://www.princon.com/princon