अवधारणा
दो दी गई दो अलग-अलग श्रृंखलाओं के संबंध में arr1[b] और arr2[a] आकार b और a। हमारा काम संयुक्त श्रृंखला का माध्य और विचरण निर्धारित करना है।
इनपुट
Arr1[] = { 24, 46, 35, 79, 13, 77, 35 }; Arr2[] = { 66, 68, 35, 24, 46 };
आउटपुट
Mean1: 44.1429 Mean2: 47.8 StandardDeviation1: 548.694 StandardDeviation2: 294.56 Combined Mean: 45.6667 d1 square: 2.322 d2_square: 4.5511 Combined Variance: 446.056
विधि
अब मान लीजिए,
n1='क्षेत्र 1' में प्रेक्षणों की संख्या
n2='क्षेत्र 1' में प्रेक्षणों की संख्या
X1=क्षेत्र का माध्य 1.
X2=क्षेत्र 2 का माध्य।
स<उप>1उप> =क्षेत्र 1 का मानक विचलन 1.
स<उप>2उप> =क्षेत्र 2 का मानक विचलन।
स<उप>1उप> 2 =क्षेत्र का विचरण 1.
स<उप>2उप> 2 =क्षेत्र 2 का प्रसरण।
मान लीजिए X=कुल समूह का माध्य
तो d1 =X - X1
और घ<उप>2उप> =एक्स - एक्स2
कुल समूह X के माध्य की गणना इस प्रकार करें
(n1*X1+n2*X2)/(n1+n2)
कुल समूह के प्रसरण की गणना
. के रूप में करेंn1*(एस<उप>1उप> 2 +डी<उप>1उप> 2 )+n2*(S2 2 +डी<उप>2उप> 2 )/(n1+n2)
उदाहरण
// C++ program to find combined mean // and variance of two series. #include <bits/stdc++.h> using namespace std; // Shows function to find mean of series. float mean(int Arr[], int b){ int sum1 = 0; for (int i = 0; i < b; i++) sum1 = sum1 + Arr[i]; float mean = (float)sum1 / b; return mean; } // Shows function to find the standard // deviation of series. float sd(int Arr[], int b){ float sum1 = 0; for (int i = 0; i < b; i++) sum1 = sum1 + (Arr[i] - mean(Arr, b)) * (Arr[i] - mean(Arr, b)); float sdd = sum1 / b; return sdd; } //Shows function to find combined variance // of two different series. float combinedVariance(int Arr1[], int Arr2[], int b, int a){ // Here, mean1 and mean2 are the mean // of two arrays. float mean1 = mean(Arr1, b); float mean2 = mean(Arr2, a); cout << "Mean1: " << mean1 << " mean2: " << mean2 << endl; // Here, sd1 and sd2 are the standard // deviation of two array. float sd1 = sd(Arr1, b); float sd2 = sd(Arr2, a); cout << "StandardDeviation1: " << sd1 << " StandardDeviation2: " << sd2 << endl; // Here, combinedMean is variable to store // the combined mean of both array. float combinedMean = (float)(b * mean1 + a * mean2) / (b + a); cout << "Combined Mean: " << combinedMean << endl; // Here, d1_square and d2_square are // the combined mean deviation. float d1_square = (mean1 - combinedMean) *(mean1 - combinedMean); float d2_square = (mean2 - combinedMean) *(mean2 - combinedMean); cout << "d1 square: " << d1_square<< " d2_square: " << d2_square << endl; // Here, combinedVar is variable to store // combined variance of both array. float combinedVar = (b * (sd1 + d1_square) + a *(sd2 + d2_square)) / (b + a); cout << "Combined Variance: " << combinedVar; } // Driver function. int main(){ int Arr1[] = { 24, 46, 35, 79, 13, 77, 35 }; int Arr2[] = { 66, 68, 35, 24, 46 }; int b = sizeof(Arr1) / sizeof(Arr1[0]); int a = sizeof(Arr2) / sizeof(Arr2[0]); // Shows function call to combined mean. combinedVariance(Arr1, Arr2, b, a); return 0; }
आउटपुट
Mean1: 44.1429 mean2: 47.8 StandardDeviation1: 548.694 StandardDeviation2: 294.56 Combined Mean: 45.6667 d1 square: 2.322 d2_square: 4.5511 Combined Variance: 446.056