Re: Oh why is life never easy? Need help with |vector|
- To: mathgroup at smc.vnet.net
- Subject: [mg2795] Re: Oh why is life never easy? Need help with |vector|
- From: Jorma.Virtamo at vtt.fi (Jorma Virtamo)
- Date: Sun, 17 Dec 1995 02:08:07 -0500
ULI12 at HOMER.geol.chemie.tu-muenchen.de (ULI WORTMANN) 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)]}] > > and called as u = 1/absvec[v] > The problem is that you have made the result a (one element) list by explicitly enclosing the body of the Module in curly brackets. Just leave the brackets out and everything works fine. By the way, the use of variable a, or the Module for that matter, does not serve any useful purpose here. You could simply write absvec[u_] := Sqrt[u.u] -- Jorma Virtamo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jorma Virtamo VTT Information Technology phone: +358 0 456 5612 Telecommunications fax: +358 0 455 0115 P.O. Box 1202 email: jorma.virtamo at vtt.fi FIN-02044 VTT web: http://www.vtt.fi/tte/ Finland