/* Orthogonality test */
#include<stdio.h>
#include<math.h>
int main()
{
int matrix[10][10], transpose[10][10], e[20] [20];
int m, n, c, r, k,flag=1;
printf("Enter the number of rows and columns of matrix:\n");
scanf("%d%d", &m, &n);
printf("Enter the %d elements of matrix:\n", m*n);
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("\nEnter value in %dth row and %dth column:", r+1, c+1);
scanf("%d", &matrix[r][c]);
}
}
printf("your matrix:\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("%10d" , matrix[r][c]);
}
printf("\n\n");
}
/*To determine transpose of entered matrix*/
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
transpose[c][r]=matrix[r][c];
}
}
printf("Transpose of entered matrix :\n");
for(r=0;r<n;r++)
{
for(c=0;c<m;c++)
{
printf("%10d", transpose[r][c]);
}
printf("\n\n");
}
/*multiplication of entered matrix with its transpose*/
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
e[r] [c]=0;
for(k=0;k<n;k++)
e[r] [c]=e[r] [c]+matrix[r] [k]*transpose[k] [c];
}
}
printf("Product matrix ([A]*Transpose[A]) is:\n");
for(r=0;r<n;r++)
{
for(c=0;c<n;c++)
printf("%10d\t", e[r] [c]);
printf("\n");
}
/*checking for orthogonality*/
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
if(e[r][c]!=1 && e[c][r]!=0)
{
flag=0;
break;
}
}
}
if(flag==1)
printf("The entered matrix is Orthogonal.\n");
else
printf("The entered matrix is not Orthogonal.\n");
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int matrix[10][10], transpose[10][10], e[20] [20];
int m, n, c, r, k,flag=1;
printf("Enter the number of rows and columns of matrix:\n");
scanf("%d%d", &m, &n);
printf("Enter the %d elements of matrix:\n", m*n);
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("\nEnter value in %dth row and %dth column:", r+1, c+1);
scanf("%d", &matrix[r][c]);
}
}
printf("your matrix:\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("%10d" , matrix[r][c]);
}
printf("\n\n");
}
/*To determine transpose of entered matrix*/
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
transpose[c][r]=matrix[r][c];
}
}
printf("Transpose of entered matrix :\n");
for(r=0;r<n;r++)
{
for(c=0;c<m;c++)
{
printf("%10d", transpose[r][c]);
}
printf("\n\n");
}
/*multiplication of entered matrix with its transpose*/
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
e[r] [c]=0;
for(k=0;k<n;k++)
e[r] [c]=e[r] [c]+matrix[r] [k]*transpose[k] [c];
}
}
printf("Product matrix ([A]*Transpose[A]) is:\n");
for(r=0;r<n;r++)
{
for(c=0;c<n;c++)
printf("%10d\t", e[r] [c]);
printf("\n");
}
/*checking for orthogonality*/
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
if(e[r][c]!=1 && e[c][r]!=0)
{
flag=0;
break;
}
}
}
if(flag==1)
printf("The entered matrix is Orthogonal.\n");
else
printf("The entered matrix is not Orthogonal.\n");
return(0);
}
Comments
Post a Comment