MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Oh why is life never easy? Need help with |vector|

ULI12 at (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        FIN-02044 VTT                        
web:      Finland

  • Prev by Date: Infinity
  • Next by Date: Re: Bug ListPlot?
  • Previous by thread: Oh why is life never easy? Need help with |vector|
  • Next by thread: Re: Oh why is life never easy? Need help with |vector|