Statistics, mean, stanard deviation (population/sample), sum and range
Here is a quick example of how to calculate a few common statistical functions on a list of numbers. You can generate the list any way you like. I have generated the list by drawing a sample of 10 numbers from a uniform distribution. The list is then stored in the variable $m1.
# Generates a sample of 10 numbers from a uniform distribution on the range 0 to 5 $m1 = maple(" randomize(): #initialise random seed A:=Statistics[RandomVariable](Uniform(0,5)): # uniform on a range 0 to 5 nums:=Statistics[Sample](A,10); #pull 10 numbers from the sample convert(nums,list) # converts the vector of numbers to a list ");
If you want to define your own list of numbers you can define $m1 as something like
$m1="[1.2, 4.4, 5.0, 2.5, 3.4, 4.6, 8.6, 7.8, 1.7, 0.4]";
You can then calculate the various quantities on the list stored in $m1. Note: As a check, in the following I have calculated the sample and population standard deviations using built in functions and the explicit formulas.
$m2=maple(" #mean mu:=Statistics[Mean]($m1); #sample s.d. s0:=Statistics[StandardDeviation]($m1); s1:=sqrt(add(i, i = map( x-> (x-mu)^2, $m1))/(nops($m1)-1)); #explicit #population s.d. sigma0:=evalf(Statistics[StandardDeviation]($m1)*sqrt((nops($m1)-1)/nops($m1))); sigma1:=sqrt(add(i, i = map( x-> (x-mu)^2, $m1))/(nops($m1))); #explicit #sum sum0:=add(i,i=$m1); #range range0:=abs(max($m1)-min($m1)); # return values mu,s0,s1,sigma0,sigma1,sum0,range0 "); #use switch to get the values from the maple call $mean=switch(0,$m2); $s0=switch(1,$m2); $sigma0=switch(3,$m2); $sum0=switch(5,$m2); $range0=switch(6,$m2);
The resultant variable in the algorithm section should now be set to something like the following