Desmond Madden
Desmond Madden

Reputation: 33

Cross Product answer isn't correct?

I'm having an issue with doing a function that takes 2 inputs: R (unit vector) and v (vector) and outputs a list of 3 vectors {vr,vp,vc}

vr = (v.R)R          
vp = v-vr           
vc = R*vp

R = {0.36,0.48,0.8}
v can equal i{1,0,0},j{0,1,0},k{0,0,1}

My issue is that with vc, it will give the incorrect answer at the position of the 1 in the v

  ``` 
   rotPrep[R_,v_]:= {Dot[v,R]R, v - Dot[v,R]R, Cross[R, v - Dot[v,R]R]};

   Print["{ir,ip,ic} = ", rotPrep[R,i]];

   Print["{jr,jp,jc} = ", rotPrep[R,j]];

   Print["{kr,kp,kc} = ", rotPrep[R,k]];

  ```

I seem to have i right, but j and k gives me 1.9984x10^-17 in the position 1 was in.

   {ir,ip,ic} = {{0.1296,0.1728,0.288},{0.8704,-0.1728,-0.288},{0,0.8,-0.48}} 
   {jr,jp,jc} = {{0.1728,0.2304,0.384},{-0.1728,0.7696,-0.384},{-0.8,1.9984x10^-17,0.36}} 
   {kr,kp,kc} = {{0.288,0.384,0.64},{-0.288,-0.384,0.36},{0.48,-0.36,-1.9984x10^-17}} 

Upvotes: 0

Views: 178

Answers (1)

Desmond Madden
Desmond Madden

Reputation: 33

As Bill said in the comments, this is the correct way of writing it

R = Rationalize[{0.36,0.48,0.8}]; 
rotPrep[R_,v_]:=N[{Dot[v,R]R, v - Dot[v,R]R, Cross[R, v - Dot[v,R]R]}]; 

Upvotes: 1

Related Questions