Recursively calculate the standard deviation

In summary, standard deviation is a measure of how spread out the data values are from the mean or average of the data set. It is important in statistics because it helps us understand the variability of the data and make more accurate predictions. The recursive formula for calculating standard deviation allows for real-time analysis and is more efficient for large data sets. However, it may require a large amount of computational power and may not be suitable for all types of data.
  • #1
anonim
40
2
TL;DR Summary
Standard Deviation
Code:
#include<stdio.h>
#include<math.h>
double foo(int n, int mean){
    double square;
    if(n==1){
        return(1);
    }
    if(n!=0){
        square=pow(n-mean,2);
        return( (sqrt(square)+foo(n-1,mean))/(sqrt(n-1))  );
    }}
int main(){
    int num;
    double mean;
    int i;
    int sum=0;
    printf("Enter the number: ");
    scanf("%d",&num);
    for(i=1; num>=i; i++){
        sum=sum+i;
    }
    mean=(double)sum/num;
    foo(num,mean);

    printf(" %lf ",foo(num,mean));
}
I want to calculate standard deviation. For example if the input is 6, I want to do this: sqrt( (6+5+4+3+2+1)/(5) ) . If the input is 6, output is going 2.100528. My code does not work properly.
 
Technology news on Phys.org
  • #2
anonim said:
Summary:: Standard Deviation

Code:
#include<stdio.h>
#include<math.h>
double foo(int n, int mean){
    double square;
    if(n==1){
        return(1);
    }
    if(n!=0){
        square=pow(n-mean,2);
        return( (sqrt(square)+foo(n-1,mean))/(sqrt(n-1))  );
    }}
int main(){
    int num;
    double mean;
    int i;
    int sum=0;
    printf("Enter the number: ");
    scanf("%d",&num);
    for(i=1; num>=i; i++){
        sum=sum+i;
    }
    mean=(double)sum/num;
    foo(num,mean);

    printf(" %lf ",foo(num,mean));
}
I want to calculate standard deviation. For example if the input is 6, I want to do this: sqrt( (6+5+4+3+2+1)/(5) ) . If the input is 6, output is going 2.100528. My code does not work properly.
This is not how the standard deviation is calculated.

Since your post seems to be a continuation of the thread in the Homework section, I am closing this thread.
 
  • Like
Likes jim mcnamara

1. What is the definition of standard deviation?

The standard deviation is a measure of how much the data values in a set deviate from the mean or average value. It tells us how spread out the data is and is calculated by taking the square root of the variance.

2. How is standard deviation calculated?

Standard deviation is calculated by taking the square root of the variance. The variance is calculated by finding the difference between each data value and the mean, squaring these differences, and then finding the average of these squared differences.

3. What is the purpose of recursively calculating standard deviation?

Recursive calculation of standard deviation is useful when dealing with large datasets or data that is constantly changing. It allows for a more efficient and accurate calculation of standard deviation by using previously calculated values instead of starting from scratch each time.

4. What are the limitations of recursively calculating standard deviation?

One limitation of recursively calculating standard deviation is that it can be time-consuming and resource-intensive. It also assumes that the data is normally distributed, which may not always be the case. Additionally, it may not be suitable for data with outliers or extreme values.

5. How can standard deviation be used in scientific research?

Standard deviation is a useful tool in scientific research as it allows for the comparison of data sets and helps identify patterns or relationships between variables. It can also be used to determine the precision and reliability of measurements and to make predictions about future data values.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
19
Views
2K
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
9
Views
963
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
1
Views
895
  • Programming and Computer Science
Replies
7
Views
857
  • Programming and Computer Science
Replies
4
Views
710
  • Programming and Computer Science
Replies
4
Views
880
  • Programming and Computer Science
Replies
2
Views
2K
Back
Top