Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Is it possible to get the inverse of a square matrix to be input as a text file using STDIN?

by 2teez (Priest)
on Nov 08, 2012 at 04:56 UTC ( #1002812=note: print w/ replies, xml ) Need Help??


in reply to Is it possible to get the inverse of a square matrix to be input as a text file using STDIN?

Hi, supriyoch_2008,

  • Please you may use strict in your script.
  • Replace these lines in inv2.pl:
    ## Input the matrix text file: print "\n\n Please type the filename(.txt) i.e. d1.txt: "; $DNAfilename = <STDIN>; 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 = <DNAFILE>; @m2=@a;
    with these:
    my @m2; ## Input the matrix text file: print "\n\n Please type the filename(.txt) i.e. d1.txt: "; chomp( my $filename = <STDIN> ); open my $fh, '<', $filename or die "can't open file $!"; while (<$fh>) { push @m2, [ split /,/, $_ ]; } close $fh or die "can't close file: $!";
Note:
Ofcourse, your script(s) can be improved upon, but these should give you what you want to start with.
Hope it helps.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: Is it possible to get the inverse of a square matrix to be input as a text file using STDIN?
Select or Download Code
Re^2: Is it possible to get the inverse of a square matrix to be input as a text file using STDIN?
by supriyoch_2008 (Scribe) on Nov 09, 2012 at 04:25 UTC

    Hi, 2teez,

    Thanks for your suggestions with code. I shall try.

    Regards

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-07-29 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls