#!/usr/bin/perl use warnings; use math_module; ### TO PRODUCE THE INVERSE OF A SQUARE MATRIX in PERL: # In a square matrix the number of rows and columns are equal. # Here we intend to get the inverse of a 4x4 square matrix. ###################################################### print"\n Here we intend to get the inverse of a 4x4 square matrix.\n"; print"\n Enter the Number of Rows i.e 4: "; $n= ; chomp$n; $N=$n; # Input the matrix below: $m2[0]=[3,2,1,1]; $m2[1]=[1,0,2,2]; $m2[2]=[4,1,3,3]; $m2[3]=[1,2,3,4]; ### 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]; } } } ################################################# 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;