import vector:*; import io:*; /***************************** * Functions ****************************/ /*************************** * dot(vec u, vec v) * * This returns the dot product * of two vectors. This is equivalent * to multiplying the components of the * vector element by element, and then summing * the resulting vector. * ***************************/ template |T| dot(|vector| u, |vector| v) { if(u.size < v.size) { println("Error: Vectors not of same size"); print("Vector a is of size: "); println(u.size); print("Vector b is of size: "); println(v.size); } |T| ans = 0; for(|int| i = 0; i < lesser(u.size, v.size); i++;) { ans = ans + u.at(i) * v.at(i); } println(ans); return ans; }//end dot function /*************** * Norm2(vec r) * * This takes a vector, * and finds the norm squared, or * the sum of all the components squared. * * This is equivalent to dot(r,r) * **************/ template |J| norm2(|vector| r) { return(dot(r,r)); }//end norm function