### Need help coding a few math problems

I was given three math equations to figure out how much a graph is skewed.

The way the math problems were given to us were

 12345 \bar{d} = \frac{\sum_{i=1}^{n} d_i}{n} s = \sqrt{{\sum_{i=1}^n (d_i^2) - n \bar{d}^{2}} / {n-1}} 3 * (\bar{d} - M_d) / s

I have a general understanding of C++ it is just how these math problems are worded. I realized the \sum is a summation but not sure how to turn that into code.

This is currently what I have changed

 123456789101112 void skew () { double dBar; double s; double n; dBar = \sum_{i=1}^{n} d_i / (n); s = sqrt(\sum_{i=1}^n (d_i^2) - n dBar^(2) / (n-1)); } 

Pretty much I will have an array to read my input file and then figure out the skew. Your help is greatly appreciated.
^ nor sqrt works in C++, for that you have pow(x , y)

For instance:
 123 int x = 2, y = 3; cout << pow(x,y); // the result is 8, same as 2^8. 

Oh yes thank you. I will fix that.
Still don't know what I need for the sum
sum?

Here are a few examples:

 1234567891011 int x, y = 2, z = 4; x = y + z; // x = 6 x = y + pow(y,z); // x = 2 + 16 = 18 x = z + pow(y,y); // x = 4 + 4 = 8 x = z + pow(z, z); // x = 4 + 256 = 260 x = (z + pow(z,z))/(y + z); //x = 260/6 = 43.33 And since the variable is INT, x = 43, if you need the .33 declare it as a float. 

*flies away*
Last edited on
Btw... Do you mean this kind of sum? Σ?
For Σ you'll need to use some FOR's in your code.

for instance: Σ(1,5) 2^n = ? (Sigma of 2^n from i = 1 to n =5)

 12345678910111213141516 int res = 0; for(int n = 1; n <= 5; n++) { res += pow(2, n); //Same as (2^1)+(2^2)+...+(2^5) = 866 cout << res << endl; /* 1) 2, 2) 2 + 4 = 6, 3) 6 + 8 = 14, 4) 14 + 16 = 30 5) 30 + 32 = 62::: So in the screen you'll have something like this... 2 6 14 30 62 */ } cout << res; // Shows the result > 62 in the screen. 
Yes the sum is Σ. Thank you for the help. Hopefully I can get this correct.
Topic archived. No new replies allowed.