Welcome to my blog!

Meet the Author

A Student at National Institute of Science And Technology,an avid blogger and tech geek

Looking for something?

Subscribe to this blog!

Receive the latest posts by email. Just enter your email below if you want to subscribe!

Sitemap

Monday, 29 July 2013

Toeplitz matrix and its creation in c

                                                          Toeplitz matrix
defination:-

In linear algebra a Toeplitz matrix or diagonal-constant matrix is a matrix in which each desending diagonal from left to right is constant.  

lets consider a example which would make it clear how a toeplitz matrix looks like.


            [a_0 a_(-1) a_(-2) ... a_(-n+1); a_1 a_0 a_(-1) ... |; a_2 a_1 a_0 ... a_(-2); | ... ... ... a_(-1); a_(n-1) ... a_2 a_1 a_0].

And its matrix equation form is:-
 sum_(j=1)^na_(i-j)x_j=y_i

c++ code to form this matrix and add two such matrixes
                


CODING:




#include<stdio.h>
#include<stdlib.h>
int main()
{
int b[10][10],a[10],a1[10],c[10][10],d[10][10],i,j,x=0,max;       /*  initialization  */
printf("Enter the maximum nos of element you want to input \n");
scanf("%d",&max);
for(i=0;i<max;i++)                                                                    /* input to the 1st matrix  */
{
                  printf("enter the element of the fist array\n");
                  scanf("%d",&a[i]);
}
printf("The elements of the first toeplitz matrix is:\n"); 
for(i=0;i<max;i++)
{
                  for(j=0;j<max;j++)
                  {
                                    b[i][j]=a[x++];       /*passing up of single dimensional array into double array*/
                                    x=x%max;
                                    printf("%d",b[i][j]);
                  }
                  x=max-1-i;
                  printf("\n");
}
for(i=0;i<max;i++)                                                             /* input to 2nd matrix  */
{
                  printf("enter the element of the second array\n"); 
                  scanf("%d",&a1[i]);
}
printf("The element for the second toeplitz matrix:\n");
for(i=0;i<max;i++)                           /* arranging the element into the toeplitz matrix */
{
                  for(j=0;j<max;j++)
                  {
                                    c[i][j]=a1[x++];
                                    x=x%max;
                                    printf("%d",c[i][j]);
                  }
                  x=max-1-i;
                  printf("\n");
}
printf("The addition of the two toeplitz matrix is:\n");
for(i=0;i<max;i++)                                         /* addition of the two toeplitz matrix  */
{
                  for(j=0;j<max;j++)
                  {
                                    d[i][j]=b[i][j]+c[i][j];
                 
                  }
}
for(i=0;i<max;i++)                         /*  printing the addition of the two toeplitz matrix */
{
                  for(j=0;j<max;j++)
                  {
                                    printf("%d",d[i][j]);
                 
                  }
                  printf("\n");
}
system("pause");
return 0;
}


********************************************************************


































                                                
                                                

                                                        
                                         

No comments:

Post a Comment

UA-55614096-1