Calculate the error sum of two vectors
Given two similar vectors that differ only by quantization or resolution, we can use the inner_product()
algorithm to calculate an error sum, defined as:
Where e is the error sum, the sum of the square of the difference between a series of points in two vectors.
We can use the inner_product()
algorithm, from the <numeric>
header, to calculate the error sum between two vectors.
How to do it…
In this recipe we define two vectors, each with a sine wave. One vector
has values of type double
and the other has type int
. This gives us vectors that differ in quantization, because the int
type cannot represent fractional values. We then use inner_product()
to calculate the error sum between the two vectors:
- In our
main()
function we define our vectors and a handyindex
variable:int main() { constexpr size_t vlen{ 100 }; ...