Hello my friends
I know that my problem must solved here or at least you well give me a recommendations :
My problem is How I use multidimensional array in calculation of standard division; for good Explanation standard division calculated as following
for series of data take the shape of
X1.....X2.....average(x#)......(xi-X#)^2
3.......5..........4...................(4-3)^2
2.......4...........3..................(3-3)^2
1........3..........2................. (2-3)^2
------------------------------------
average=......3.........sum = ......2
standard division =sqrt(sum/(n-1))
my need is to use multidimensional array A(ij) as A(j) receiving data of X1
and A(j+1) receiving X2 and A(j+2) receiving average (X#) and so on
but A(i) receiving data of(3,2,1) , A(i+1) receiving data of (5,4,2) , A(i+2) receiving data of averages( 4,3,2) and so on
as above calculating value ( Xi -x#)^2 in (A(i+3)
then calculate sum as above and calculating standard division,
if we get the needed code then we will do further steps needed i will give you the calculations
I,m sorry for long post ...and thanks a lot for helping
Here's an example of some methods for working with a 2d array, in case that's what is baffling you.
The function below finds the average of the values in a 2d array, which is the 1st part needed for finding the standard deviation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
double avg_value(double* pA, int Nele)// takes a pointer to the array and the # of elements
{
double sum = 0.0;
for(int i=0; i<Nele; ++i)
sum += pA[i];
return sum/Nele;
}
int main()
{
double A[3][3] = {{3.0,2.0,1.0}, {5.0,4.0,2.0}, {4.0, 3.0, 2.0}};// a 2d array
double* pd = &A[0][0];// pointer to 1st element
cout << "Average value = " << avg_value(pd,9) << endl;// call function and display returned value
return 0;
}
You could now write a 2nd function to finish the calculation or add the remaining steps in the given function (so it returns the standard deviation instead of the average).
You're welcome. I hard coded the array values because my intent was to show how to work with an already filled array.
I assumed that you could get the array space allocated and the element values filled yourself.
Do you need help with this part too?
Are the array dimensions known? If not, how are they determined?
Is all data to be input by the user or input from a file?
These are issues that are separate from how to calculate standard deviation.
Show us some code and we can help you through it.
#include<cmath>
using namespace std;
int main()
{char q;
int n=0,m=0,i=0,j=0;
cin>>n;
cin>>m;
float data[n][m],sum=0,summ=0,avrn,tot=0,avrd=0,dev=0,s=0,avr=0,dif[n];
for (i=0;i<n;i++)
{
for(j=0;j<m;j++)
{cout<< " n "<<i+1<<" =";
cin>>data[i][j];