# Comparing machine output quality

Suppose you have three machines producing details and you know the should-values of the perfect detail. You select 12 details produced by each machine at random and measure their values. Now you want to find out which machine produces the highest-quality details, given your measurements. Here is an example how you could proceed.

```#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; double stdev(const vector<double>& values, const double mean) { size_t n = values.size(); double sum = 0, temp; for (size_t i = 0; i < n; i++){ temp = values[i] - mean; sum += temp*temp; } return sqrt(sum / (n-1)); } int main() { double min_stdev, max_stdev; vector<double> should_values = {22, 29, 37}, stdevs; vector<vector<double>> machine_measurements = { {30, 26, 28, 23, 22, 25, 19, 21, 25, 27, 19, 21}, {23, 26, 28, 29, 31, 29, 27, 33, 28, 31, 33, 24}, {43, 29, 34, 37, 38, 36, 32, 36, 39, 41, 37, 43} }; vector<double>::const_iterator min_it, max_it; int min_idx, max_idx; for(size_t i = 0; i < machine_measurements.size(); i++) { stdevs.push_back(stdev(machine_measurements[i], should_values[i])); } min_stdev = *min_element(begin(stdevs), end(stdevs)); max_stdev = *max_element(begin(stdevs), end(stdevs)); min_it = find(begin(stdevs), end(stdevs), min_stdev); if (min_it != end(stdevs)) { min_idx = *min_it - 1; } max_it = find(begin(stdevs), end(stdevs), max_stdev); if (max_it != end(stdevs)) { max_idx = *max_it - 1; } cout << "Machine " << min_idx << " produces the highest quality details (std: " << min_stdev << "), while machine " << max_idx << " produces the lowest quality details (std: " << max_stdev << ")." << endl; /* Machine 2 produces the highest quality details (std: 3.24738), while machine 3 produces the lowest quality details (std: 4.18873). */ return 0; }```

In other words, the machine that shows the least variability in relation to its should-value has the highest quality. Standard deviation is a measure that allows us to examine this, if we used the should-value as a mean. Here we looked only at a single criteria, where in reality each detail would have multiple interesting features.