Sunday 7 April 2013

Orthogonality in matrix c program with output


CHECKING FOR ORTHOGONALITY IN MATRIX


#include<stdio.h>
#include<conio.h>
void main()
{
int m, n, p, c, d, k, sum = 0;
int matrix[10][10], transpose[10][10], product[10][10];
clrscr();
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix\n");
for (  c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d",&matrix[c][d]);
for( c = 0 ; c < m ; c++ )
{
for( d = 0 ; d < n ; d++ )
{
transpose[d][c] = matrix[c][d];
}
}
for ( c = 0 ; c < m ; c++ )
{   for ( d = 0 ; d < n ; d++ )
{
for ( k = 0 ; k < n ; k++ )
{
sum = sum + matrix[c][k]*transpose[k][d];
}
product[c][d] = sum;
sum = 0;
}
}
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < m ; d++ )
{
if ( c == d )
{
if ( product[c][d] != 1 )
break;
}
else
{
if (product[c][d] != 0 )
break;
}
}
if ( d != m )
break;
}
if ( c != m )
printf("Matrix is not orthogonal.\n");
else
printf("Matrix is orthogonal.\n");
getch();
}

 

Output:

Enter the number of rows and columns of matrix
3 3

Enter the elements of matrix
1
2
3
4
5
6
7
8
9
 
Matrix is not orthogonal.
 

No comments:

Post a Comment