IVS-calculator
Loading...
Searching...
No Matches
profiling.cpp
Go to the documentation of this file.
1#include <iostream>
2#include "mathlib.h"
3
4using namespace std;
5using namespace mathlib;
6
7int main() {
8
9 MathError err;
10 double mean = 0.0;
11 double M2 = 0.0;
12 int n = 0;
13 double x;
14
15 while(cin >> x) {
16
17 n++;
18
19 double delta = subtract(x, mean);
20 mean = add(mean, divide(delta, (double)n, err));
21 M2 = add(M2, multiply(delta, subtract(x, mean)));
22 }
23
24 if(n < 2) {
25 cout << "Error: not enough data" << endl;
26 return 1;
27 }
28
29 double variance = divide(M2, subtract((double)n, 1.0), err);
30 double stddev = root(variance, 2, err);
31
32 cout << stddev << endl;
33
34 return 0;
35}
Mathematical library for calculator project.
double root(double base, int n, MathError &err)
Implementation of function root.
Definition mathlib.cpp:85
double add(double a, double b)
Implementation of function add.
Definition mathlib.cpp:9
double multiply(double a, double b)
Implementation of function multiply.
Definition mathlib.cpp:25
MathError
Definition mathlib.h:11
double divide(double a, double b, MathError &err)
Implementation of function divide.
Definition mathlib.cpp:33
double subtract(double a, double b)
Implementation of function subtract.
Definition mathlib.cpp:17
int main()
Definition profiling.cpp:7