summaryrefslogtreecommitdiff
path: root/2.3-1/src/c/matrixOperations/toeplitz/ztoeplitza.c
blob: 117f818937dcd09f9777950df0de2d84d2a24edc (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
30
31
32
33
34
35
36
#include <stdio.h>
#include "toeplitz.h"
#include "doubleComplex.h"
#include "stdlib.h"
#include "string.h"
#include "cat.h"


/*Function to build a Toeplitz Matrix for inputs of DoubleComplex datatype*/


void ztoeplitza(doubleComplex* inp1,int size1,doubleComplex* inp2,int size2,doubleComplex* oup)
{
    if ((zreals(inp1[0])!=zreals(inp2[0]))&&(zimags(inp1[0])!=zimags(inp2[0])))
    {
        printf("Error!The first elements of the Vectors are not equal.");	// First element of both input vectors must be equal for Toeplitz.
        return;
    }
    int i, j;

    for(i=0;i<size1*size2;i++) oup[i] = 0;	// Initializing the output matrix with zeros.

    for (i = 0; i<size1; i++)
    {
        for (j = 0; j<size2; j++)
        {
            oup[j*size1] = inp2[j];		// Elements of the second input vector are copied to the first row of the Toeplitx Matrix.
        }
        oup[i] = inp1[i];			// Elements of the first input vector are copied to the first column of the Toeplitx Matrix.
    }
    for (i = size2+1; i<size1*size2; i++)	// Loop to build the rest of the Toeplitz matrix.
    {
        if (zreals(oup[i]) == 0 && zimags(oup[i]) == 0)
        oup[i] = oup[i-size2-1];
    }	
}