Does anyone know how they would find the n-th power of the adjacency matrix?
Here is the matrix I am trying to write the code for
0 0 1 0
0 0 1 0
1 1 0 1
0 0 1 0
and the 2nd power adjacency matrix is:
1 1 0 1
1 1 0 1
0 0 3 0
1 1 0 1
I am not sure how I can calculate it with a perl code I only have a code for reading in my file
sub matrix_read_file {
my ($filename) = @_;
my @matrix;
open (my $F, '<', $filename) or die "Could not open $filename: $!";
while (my $line =<$F> ) {
chomp $line;
next if $line =~ /^\s*$/; # skip blank lines
my @row = split /\s+/, $line;
push @matrix, \@row;
}
close $F;
print "$matrix[2][1]\n"; #test to see if individual elements print
print "$matrix[1][2]\n";
return \@matrix;
}