Linear Algebra and the C Language/a06o
Cross product: Code study
In this function, I'm using row vectors. In mathematics, vectors are considered column vectors. That's why I'm using *_T (Transpose) to display vectors.
I copy the vectors U and V into the matrix A. Then I calculate the cofactor expansion along the first row of A to obtain UxV.
/* ------------------------------------ */
/* ------------------------------------ */
double **UxV_mR(
double **U_T,
double **V_T,
double **UxV_T
)
{
double **A = i_mR(R3, C3);
// u and v -> A
c_r_mR(U_T, R1, A, R2);
c_r_mR(V_T, R1, A, R3);
// cofactor(detA) -> (u x v)
c_s_mR(cofactor_R(A, R1, C1), UxV_T, R1, C1);
c_s_mR(cofactor_R(A, R1, C2), UxV_T, R1, C2);
c_s_mR(cofactor_R(A, R1, C3), UxV_T, R1, C3);
f_mR(A);
return(UxV_T);
}
/* ------------------------------------ */
/* ------------------------------------ */