Biotechnology Forums
PERL Program - Matrix Transpose - Printable Version

+- Biotechnology Forums (https://www.biotechnologyforums.com)
+-- Forum: Biotechnology Discussion (https://www.biotechnologyforums.com/forum-1.html)
+--- Forum: Bioinformatics (https://www.biotechnologyforums.com/forum-5.html)
+--- Thread: PERL Program - Matrix Transpose (/thread-7911.html)



PERL Program - Matrix Transpose - binu - 04-25-2017

print "Enter 3*3 Array Elements : ";
for($row=0; $row<3 ; $row++) 
{
  for($col=0; $col<3 ; $col++) 
  {
    $matrix[$row][$col] = <STDIN>;
  }
}

# Print the original matrix
print "Entered Matrix is : \n";
for($row=0; $row<3 ; $row++) 
{
  for($col=0; $col<3 ; $col++) 
  {
    printf("%3d", $matrix[$row][$col]);
  }
  print "\n";
}

#Transposing the matrix
for($row=0; $row<3 ; $row++) 
{
  for($col=0; $col<3 ; $col++) 
  {
    $matrix_transpose[$row][$col] = $matrix[$col][$row];
  }
}

# Print the matrix in 3 integer spaces : "%3d"
print "Transpose of the Matrix is :\n";
for($row=0; $row<3 ; $row++) 
{
  for($col=0; $col<3 ; $col++) 
  {
    printf("%3d", $matrix_transpose[$row][$col]);
  }
  print "\n";
}

# Check for Symmetric Matrix
$isSymmetric = 0;
for($row=0; $row<3 ; $row++) 
{
  for($col=0; $col<3 ; $col++) 
  {
if ($matrix[$row][$col] != $matrix[$col][$row])
{ $isSymmetric = 1; print $isSymmetric; }
  }
}
if($isSymmetric==0)
{ print("Matrix is symmetric. \n"); }
else
{ print("Matrix is not symmetric. \n"); }