Just trying to determine if two vectors are independent or dependent. Instead of computing the cross product or dot product, faster to just go element by element and see if the common factor between all the elements is the same (?).
const areIndependent = (a: Array<number>, b: Array<number>) => {
let firstFactor = math.divide(a[0], b[0]);
for(let j = 1; j < a.length; j++){
if(math.divide(a[j],b[j]) !== firstFactor){
return true;
}
}
return false;
}
the above should work, but I realized that dividing by zero will be a problem. If the denominator is zero, how do I handle this properly? Not sure.
I think the code is OK as is. But we can add stuff to be more explicit:
this should be a lot faster than the cross product or dot product if you just want to find out if two vectors are linearly independent.