1
$\begingroup$

So I wish to perform a passive rotation in N dimensional space. Let me take N=5 for this question.

testvector=RandomVariate[NormalDistribution[],5];
testunitvector = UnitVector[5, 1];
basisrotation = Transpose[RotationMatrix[{testunitvec, testvector}]];
output=basisrotation.testvector;

I get something like

Out[] = {11.57583690, 0.*10^-9, 0.*10^-9, 0.*10^-9, 0.*10^-9}

while I expect to get something like this

Out[] = {11.57583690, 0., 0., 0., 0.}

no matter which precision I use. Is there any way to correct this? Thanks in advance!

$\endgroup$
3
$\begingroup$

RandomVariate takes the option WorkingPrecision. Any residual artifact can be removed with Chop.

testvector = RandomVariate[NormalDistribution[], 5, WorkingPrecision -> 20];

testunitvector = UnitVector[5, 1];

basisrotation = Transpose[RotationMatrix[{testunitvector, testvector}]];

Note that I corrected typo in definition of basisrotation

output = basisrotation.testvector // Chop

(*  {3.163849275428872542, 0, 0, 0, 0}  *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.