(a - b) and I would like it squared, is there an equivalent to Matlab's
(a - b)^2?
The C math library (link) has some stuff like that. Nothing terribly special though - just all the basic functions (e^x, log, pow, trig, etc). So to answer your question:
Code:
#include <math.h> //#include <cmath> instead for C++ environments
...
double ans = pow(a, b); //double = a^b
but IMO it's just easier to write out the multiplication for squares.
sqrt( (a-mean)*(a-mean) + (b-mean)* (b-mean) + ... + (n-mean)*(n-mean))/n)
You could instead add the numbers in a loop. So instead of using variables a-n, you have an array of numbers.
Code:
double numbers[n];
//fill array with values here: numbers[0]=3, numbers[1] =6, etc.
double sum=0;
int i;
for (i=0; i<n; i++) {
sum+=(numbers[i]-mean)*(numbers[i]-mean);
}
double answer = sqrt(sum / n);