IVS-calculator
Loading...
Searching...
No Matches
profiling.cpp File Reference
#include <iostream>
#include "mathlib.h"
Include dependency graph for profiling.cpp:

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 7 of file profiling.cpp.

7 {
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}
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