I am trying to do the following mathematical operation with two vectors:
v1 = [a1][a2][a3][a4][a5]
v2 = [b1][b2][b3][b4]b5]
Want to compute:
You could look into std::valarray. It's designed to allow mathematical operations on every element in the array.
std::transform( v1.begin()+1, v1.end(),
v2.begin()+1, v.begin(), // assumes v1,v2 of same size > 1,
// v one element smaller
std::multiplies<int>() ); // assumes values are 'int'
You can replace v.begin()
with std::back_inserter(v) if v
is empty, you should reserve()
memory upfront to avoid multiple allocations.