School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

Linux & UNIX Source Code

  

Python Source Code


You're Browsing As A Guest! Register Now...
Become an Expert!

Join 353,886 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,179 people online right now.Registration is fast and FREE... Join Now!




Coefficient of Variation

Finds out the coefficient of variation of grouped data.

Submitted By: atik97
Actions:
Rating:
Views: 572

Language: Python

Last Modified: February 20, 2009

Snippet


  1. from math import *
  2. from Numeric import *
  3. n=input("Enter number of classes:")
  4. h=input("Enter class interval:")
  5. af=zeros(n,Float)    #assigning empty array
  6. ax=zeros(n,Float)    #assigning empty array
  7. sum_f=0
  8. sum_x=0
  9. sum_fx=0
  10. sum_dd=0
  11. for i in range(n):
  12.     print "Enter values for class %s"%(i+1)
  13.     l=input("Lower limit:")
  14.     f=input("Frequency:")
  15.     u=l+h    #upper limit
  16.     x=(l+u)/2    #mean of lower & upper limit
  17.     sum_x=sum_x+x    #cumulative sum of x
  18.     fx=f*x    #product of frequency & mean value of a class
  19.     sum_fx=sum_fx+fx
  20.     ax[i]=x    #assigns x to array
  21.     af[i]=f    #assigns frequency to array
  22.     sum_f=sum_f+f    #cumulative sum of frequency
  23. mx=sum_fx/sum_f    #mean value of given data group
  24. for i in range(n):
  25.     dn=ax[i]-mx    #deviation about mean
  26.     dd=af[i]*pow(dn,2)
  27.     sum_dd=sum_dd+dd
  28. sd=sqrt(sum_dd/sum_f)    #standard deviation
  29. cv=(sd*100)/mx    #coefficient of variation
  30. print "The coefficient of variation is %s"%cv

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month