Given a matrix of size n*n. We have to calculate variance and standard-deviation of given matrix.
Input : 1 2 3 4 5 6 6 6 6 Output : variance: 3 deviation: 1 Input : 1 2 3 4 5 6 7 8 9 Output : variance: 6 deviation: 2
First mean should be calculated by adding sum of each elements of the matrix. After calculating mean, it should be subtracted from each element of the matrix.Then square each term and find out the variance by dividing sum with total elements.
Deviation: It is the square root of the variance.
1 2 3 4 5 6 7 8 9
Here mean is 5 and variance is approx 6.66
Below is code implementation:
Mean: 5 Variance: 6 Deviation: 2
This article is contributed by Himanshu Ranjan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Mathematics | Mean, Variance and Standard Deviation
- Program for Variance and Standard Deviation of an array
- Find combined mean and variance of two series
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Program to check diagonal matrix and scalar matrix
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Maximize sum of N X N upper left sub-matrix from given 2N X 2N matrix
- Circular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)
- Count frequency of k in a matrix of size n where matrix(i, j) = i+j
- Check if it is possible to make the given matrix increasing matrix or not
- Program to check if a matrix is Binary matrix or not
- Program to convert given Matrix to a Diagonal Matrix
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Maximum trace possible for any sub-matrix of the given matrix
- Minimum number of steps to convert a given matrix into Upper Hessenberg matrix
- Minimum steps required to convert the matrix into lower hessenberg matrix
- Minimum number of steps to convert a given matrix into Diagonally Dominant Matrix
- C++ program to Convert a Matrix to Sparse Matrix
- Convert given Matrix into sorted Spiral Matrix
- Create matrix whose sum of diagonals in each sub matrix is even