Re: Oh why is life never easy? Need help with |vector|
- To: mathgroup at smc.vnet.net
- Subject: [mg2800] Re: [mg2771] Oh why is life never easy? Need help with |vector|
- From: Elias Saab <mathes at esaab.math.missouri.edu>
- Date: Mon, 18 Dec 1995 00:42:09 -0500
Your original code had {} around the answer. Take
them out and your problem will be solved.
Of course Mma will consider what you have
{a = Sqrt[(u[[1]]^2+u[[2]]^2+u[[3]]^2)]}
as a vector.
Try this code:
absvec[u_] :=
Module[{a},
a = Sqrt[(u[[1]]^2+u[[2]]^2+u[[3]]^2)]]
In fact one can define |v| as Sqrt[ v . v]
Elias Saab
On Sat, 16 Dec 1995, 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]
>
> To bad I have no idea what's wrong with this code. Any input is
> appreciated.
>
> ThanX
> Uli
> --
> Uli Wortmann
>
> Dept. of Geology Fax (Germany) 89 3209 3168
> Tech. Univ. Munich Fon 3232
> email: uli at homer.geol.chemie.tu-muenchen.de
>