summaryrefslogtreecommitdiff
path: root/macros/gftrunc.sci
blob: 5381d1c3f6d36ef709373304da90b2c9ee07918b (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
37
38
39
40
41
42
43
44
45
function at=gftrunc(a)
//This function is used to truncate the higher order zeroes in the given polynomial equation
//
//  Calling Sequence
//AT=GFTRUNC(A)
//   
//  Description
//A is considered to be matrix that gives the coefficients of polynomial GF(p) in ascending order powers
//A = [1 2 3] denotes 1 + 2 x + 3 x^2    
//AT=GFTRUNC(A) returns a matrix which gives the polynomial GF(p) truncating the input matrix 
//that is if A(i)=0, where i > d + 1, where d is the degree of the polynomial, that zero is removed
//    
//Examples
//A= [ 0 0 1 4 0 0]
//c = gftrunc([0 0 1 2 3 0 0 0 4 5 0 1 0 0])
//
//Authors
//Pola Lakshmi Priyanka, IIT Bombay

//*************************************************************************************************************************************//
// Check number of input arguments
[outa,inpa]=argn(0) 

if inpa~=1 then
    error('comm:gftrunc: Invalid number of input arguments')
end

[row_a,col_a]=size(a);
if row_a~=1 then
    error('comm:gftrunc: Input argument should be a row vector')
end
    for j=1:col_a
        if ( abs(a(1,j))~=a(1,j) | floor(a(1,j))~=a(1,j) )
                error('comm:gftrunc:Elements Of A should be Positive Integers');
        end
    end
at=a;
for i=col_a:-1:1
    if a(1,i)~=0 then
        break;
    else
        at=[at(1:i-1)]
    end
end
endfunction