Wednesday, 20 November 2013

C-Program to Check the matrix is orthogonal or not

know about orthogonal of a matrix : http://en.wikipedia.org/wiki/Orthogonal_matrix



#include<stdio.h>
#include<conio.h>
main()
{
    int m,n,i,j,k,sum=0;
    int a[20][20],t[20][20],p[20][20];
  printf("Enter the number of rows and columns(order)\t");
    scanf("%d%d",&m,&n);
    printf("Enter the elements of matrix\t");
for(i=0;i<m;i++)
    for(j=0;j<n;j++)
        scanf("%d",&a[i][j]);
  for(i=0;i<m;i++)
    {
      for(j=0;j<n;j++)
      {
          t[j][i]=a[i][j];
      }
    }
for(i=0;i<m;i++)
    {
      for(j=0;j<n;j++)
      {
          for(k=0;k<n;k++)
          sum=sum+a[i][k]*t[k][j];
    p[i][j]=sum;
        sum=0;
      }
    }
  for(i=0;i<m;i++)
    {
      for(j=0;j<m;j++)
        {
          if(i==j)
            if(p[i][j]!=1)
                   break;
else
            if (p[i][j]!=0)
                   break;
        }
       if(j!=m)
          break;
    }
    if(i!=m)
      printf("Given matrix is not orthogonal.\n");
    else
      printf("Given matrix is orthogonal.\n");
}



sakoncepts.blogspot.in
output

No comments:

Post a Comment