summaryrefslogtreecommitdiff
path: root/2.3-1/src/c/statisticsFunctions/center/zcentera.c
blob: 22ce70d70b49a7d434644fd6c3a3031882d2350a (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ones.h>
#include "addition.h"
#include "subtraction.h"
#include "multiplication.h"
#include "division.h"
#include "center.h"
#include "doubleComplex.h"
#include "sqrt.h"

void zcentera (doubleComplex* inp, int row, int col, doubleComplex* out)
{
    doubleComplex sum = 0, xbar = 0, sigma = 0;
    for(int i = 0; i < row*col; i++)		// Findinag the maen of all the elements of the matrix
        sum = zadds(sum,inp[i]);
    xbar = zrdivs(sum,(row*col));
    
    doubleComplex one[row*col];			// Creating a matrix of ones
    zonesa(one,row,col);

    doubleComplex prod[row*col];
    for(int i = 0; i < row*col; i++)		// Applying the formula (x(i,j)-xbar)/sigma
        prod[i] = zmuls(one[i],xbar);

    for(int i = 0; i < row*col; i++)
        out[i] = zdiffs(inp[i], prod[i]);
}