[Date Index]
[Thread Index]
[Author Index]
Re: Re: Generating Two Unit Orthogonal Vectors (correction)
*To*: mathgroup at smc.vnet.net
*Subject*: [mg36486] Re: [mg36428] Re: Generating Two Unit Orthogonal Vectors (correction)
*From*: Gianluca Gorni <gorni at dimi.uniud.it>
*Date*: Mon, 9 Sep 2002 00:29:23 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
The vectors that NullSpace gives do not need to be orthogonal to
each other. What about the following variant, that adds one vector
at a time? It may not be fast enough for serious number crunching.
OrthogonalComplement[v__ /; MatrixQ[{v}]] :=
With[{n = Length[NullSpace[{v}]]},
Take[Nest[Join[{First[NullSpace[#]]}, #] &, {v}, n], n]];
OrthonormalComplement[v__ /; MatrixQ[{v}]] :=
Map[#/Sqrt[#.#] &, OrthogonalComplement[v]];
When the input of OrthogonalComplement is integer, I expect the output
to be integer too:
OrthogonalComplement[{1, 2, 3}]
{{1, -5, 3}, {-3, 0, 1}}
Gianluca Gorni
> From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
To: mathgroup at smc.vnet.net
> Date: Fri, 6 Sep 2002 03:17:01 -0400 (EDT)
> Subject: [mg36486] [mg36428] Re: Generating Two Unit Orthogonal Vectors (correction)
>
> OrthogonalUnitVectors that I sent a few minutes ago doesn't do what I
> thought it would.
> After making either definition below I get the following:
>
> In[2]:=
> s1=OrthogonalUnitVectors[{1,0,1/2,1,0},{0,1,-1,1/2,2}]
>
> Out[2]=
> {{0, -2/Sqrt[5], 0, 0, 1/Sqrt[5]}, {-2/3, -1/3, 0, 2/3, 0}, {-1/3, 2/3,
> 2/3, 0, 0}}
>
>
> The dot products below aren't zero, so the vectors aren't orthogonal. What
> went wrong?
>
>
> In[3]:=
> Part[s1,1].Part[s1,2]
>
> Out[3]=
> 2/(3*Sqrt[5])
>
>
> In[4]:=
> Part[s1,1].Part[s1,3]
>
> Out[3]=
> -4/(3*Sqrt[5])
>
>
> --------------
>> Hugh Goyder and David Park gave a most elegant function to find two
>> vectors that are orthogonal to one vector in 3D. The key to coming up
>> with the elegant solution is an understanding of Mathematica's NullSpace
>> function. We can easily make the version from Hugh and David much more
>> general with the version below.
>> -------------
>> OrthogonalUnitVectors[vect__?VectorQ]:=
>> #/Sqrt[#.#]&/@NullSpace[{vect}]
>>
>> -------------
>> The version above will give a set of unit orthogonal vectors if given any
>> number of vectors in any dimension.
>> So besides giving it a 3D vector we can give it the following:
>> OrthogonalUnitVectors[{2,1,0,-1,1}]
>> or
>> OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}]
>>
>> ------------
>> But the short version above isn't very robust.
>> (1) Clear[x,y,z];NullSpace[{{x,y,z}}]
>> returns two vectors orthogonal to {x,y,z}, but the two vectors
>> NullSpace returns aren't orthogonal to each other.
>> So (OrthogonalUnitVectors) should only work with numeric vectors.
>>
>> (2) We should ensure all the vectors have the same dimension and length
>>> 1.
>>
>> I give a less concise version below that corrects these problems.
>> ------------
>>
>> OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/;
>> (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):=
>> #/Sqrt[#.#]&/@NullSpace[{vect}]
>>
>> --------------
>> Regards,
>> Ted Ersek
>> Get Mathematica tips, tricks from
>> http://www.verbeia.com/mathematica/tips/Tricks.html
>>
>
Prev by Date:
**Re: A faster alternative to ListIntegrate?**
Next by Date:
**RE: Re: Re: word processing with mathematica**
Previous by thread:
**Re: Generating Two Unit Orthogonal Vectors (correction)**
Next by thread:
**I need to do one graphic in Origin 5.0**
| |