-
Notifications
You must be signed in to change notification settings - Fork 0
/
corelation.cpp
42 lines (37 loc) · 972 Bytes
/
corelation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double X[5] = {3, 7.3, 1.5, 4, 0}, Y[5] = {6, 10, 4, 9, 1}, Z[5] = {3, 3.1, 5, 10, 2};
double Xbar = 0, Ybar, Zbar;
for (int i = 0; i < 5; i++)
{
Xbar += X[i];
}
Xbar = Xbar / (sizeof(X) / sizeof(*X));
for (int i = 0; i < 5; i++)
{
Ybar += Y[i];
}
Ybar = Ybar / (sizeof(Y) / sizeof(*Y));
for (int i = 0; i < 5; i++)
{
Zbar += Z[i];
}
Zbar = Zbar / (sizeof(Z) / sizeof(*Z));
// cout << "Korelasi array X dan Y : ";
float penyebutx = 0, penyebuty = 0, pembilang = 0;
for (int i = 0; i < 5; i++)
{
pembilang += (X[i] - Xbar) * (Y[i] - Ybar);
}
for (int i = 0; i < 5; i++)
{
penyebutx += abs(X[i] - Xbar);
penyebuty += abs(Y[i] - Ybar);
}
float penyebut = penyebutx * penyebuty;
cout << "Korelasi X dan Y adalah : " << penyebut / pembilang;
return 0;
}