Saturday, 4 April 2020

How to code mean deviation and standard deviation with c programming

How to calculate mean 


Let we have some observation :- 12, 21, 9, 5, 7, 54
Their some is 12+ 21+ 9+ 5+ 7+ 54= 108  .and  we have total no of given data is 6.
So the mean of the given data is 108 ÷ 6 =18.

Formula of Mean
Mean of a given data


Mean Deviation:
Mean deviation of an observation is arithmetic meanof it's values from a central value.

⇾Mean deviation from mean
⇾Mean deviation from median 
⇾Mean deviation from mode
        x=x1, x2............... xn
             suppose mean of the given data = A

so,  deviation=di=Xi-A


As we discussed in above example how to get mean of a given data  i.e A=18
    so now we want to find out deviation of the given data--
    here  x1=12 , x2=21 ,  x3=9 , x4=5 ,  x5=7 ,  x6=54

d1 = 12-18 = -6 ,   d2= 21-18=3 ,   d3=9-18=-9 ,   d4=5-18=-13 ,  d5=7-18=-11 , d6=54-18=26.

Mean deviation of the given data is find using given formula:
Standard deviation formulla
mean deviation

here n=no. of data ,  di=deviation , A=mean of the data


simply we can see:--
How to find mean deviation in simple way
mean deviation in simple form

So now from given data
       

                                            

Variance: 
Variance of a values of a variate is arithmetic mean of square of deviation of it's values from arithmetic mean of the variable.
Variance of variable x is denoted by σx or V(x).  
   
Add caption

Now from given data  12,21,9,5,7,54 we have to find mean of square and square of their mean -     
How to find square of mean
Mean of square value and square of mean 
          
so ,  V(x)= 609.3333- 324 =285.33    



 # Standard deviation:

positive square root of variance of a variate is defined as std deviation.                                               
  standard deviation formula
standard deviation

Now from above example standard deviation =



Now we will see how to code for standard deviation through 'c'


  1#include<stdio.h>
  2. #include<math.h>
  3. int main( )
  4. {
  5.  int sum;
  6.  float avg,sd;
  7. stddev(&sum,&avg,&sd);
  8. printf("sum=%d ,average=%f,standard
      deviation=%f",sum,avg,sd);
  9.  }

 10. stddev(int *sum,float *avg,float *sd)
 11. {
 12.  int a,b,c,d,e;
 13.  printf("Enter five integers: ");
 14.  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
 15.  *sum=a+b+c+d+e;
 16. *avg=*sum/5;
 18. *sd=sqrt ((a*a+b*b+c*c+d*d+e*e)/5)-(*avg)*(*avg));
19.   }

//Execution process:
Here we use  #include<math.h> because mathh is a header file in the standard library of the C programming language designed for basic mathematical operations. ... 
Mathematical library functions that operate on integers, such as abs , labs , div , and ldiv , are instead specified in the stdlib. h header. Here we use because of square root.
Here we use concept of pointer and passe the address of arguments and use basic coding
knowledge to implement the mathematical formula into code.                                         
                                                           







No comments:

Post a Comment

If you have any doubt don't hesitate to write in comment section.I will always answer your doubt.

Periodic properties ( types of bonds)

Why we study periodic properties Here we will continue periodicity of a periodic table . In the last post we have seen the important conc...