-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
C++20 STL Cookbook
By :
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:
Figure 11.2 – Error sum definition
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.
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:
main() function we define our vectors and a handy index variable:int main() {
constexpr size_t vlen{ 100 };
...