#!/usr/bin/perl ### TO PRODUCE THE INVERSE OF A SQUARE MATRIX (ANY SIZE) in PERL: use warnings; use math_module; ################################## # Inverse matrix calculation: ################################## print"\n Enter the Number of Rows i.e. 4 here: "; $n= ; chomp$n; $N=$n; ## Input the matrix text file: print "\n\n Please type the filename(.txt) i.e. d1.txt: "; $DNAfilename = ; chomp $DNAfilename; ## To remove white space: $DNAfilename=~ s/\s//gis; # open the file, or exit unless ( open(DNAFILE, $DNAfilename) ) { print "Cannot open file \"$DNAfilename\"\n\n"; exit; } # Line 10 @a = ; @m2=@a; print"\n The contents of input matrix file are (array m2):\n\n @m2\n"; ### Data Ends Here ########################### @inv=math_module::get_inverse($N,@m2); ############################################## # Checking if the inverse matrix is correct: ############################################## for ($i=0; $i<$N; $i++) { for ($j=0; $j<$N; $j++) { $t=0; for($k=0; $k<$N; $k++) { $t=$t+ $m2[$i][$k]*$inv[$k][$j]; } } } ################################################# # Output inverse matrix: ################################################## print "\n\n The Inverse Matrix is:\n\n"; ## Use of for LOOP: for ($i=0; $i<$N; $i++) { for ($j=0; $j<$N; $j++) { print $inv[$i][$j]; print " "; } print "\n\n"; } exit;