Share your knowledge at the LQ Wiki.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Try solver System of linear algebraic equations in Shell Bash
 User Name Remember Me? Password
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 10-03-2012, 04:49 AM #1 newbieseos LQ Newbie   Registered: Oct 2012 Posts: 2 Rep: Try solver System of linear algebraic equations in Shell Bash I want to try solving system of linear algebraic equations in Shell bash but i have any problems Value input is matrix and I dont know how to input matrix in Shell because that is dont support 2-dimensional array Please help me. Thank you so much
 10-03-2012, 05:37 AM #2 pan64 Guru   Registered: Mar 2012 Location: Hungary Distribution: debian i686 (solaris) Posts: 5,152 Rep: you would better try to use awk/perl or another language, bash does not really support it and is hard to implement.
10-03-2012, 05:52 AM   #3
porphyry5
Member

Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch
Posts: 424

Rep:
Quote:
 Originally Posted by newbieseos I want to try solving system of linear algebraic equations in Shell bash but i have any problems Value input is matrix and I dont know how to input matrix in Shell because that is dont support 2-dimensional array Please help me. Thank you so much
Suppose your matrix is 3x3. As a one-dimensional array this requires 9 cells. So you can compute the one-dimensional array cell corresponding to M[a, b] by M[a*3+b], e.g.
Code:
```~ \$ x=(1 2 3 4 5 6 7 8 9)
~ \$ a=2
~ \$ b=2
~ \$ echo \${x[\$a*3+\$b]}   # the 9th cell
9
~ \$ a=0
~ \$ b=1
~ \$ echo \${x[\$a*3+\$b]}   # the 2nd cell
2```

 10-03-2012, 05:55 AM #4 sycamorex LQ Veteran Contributing Member   Registered: Nov 2005 Location: London Distribution: Slackware64-current Posts: 5,607 Blog Entries: 1 Rep: Another suggestion would be to use Python. It has lots of maths modules.
 10-03-2012, 06:34 AM #5 newbieseos LQ Newbie   Registered: Oct 2012 Posts: 2 Original Poster Rep: Thanks for all your replying
 10-03-2012, 06:57 AM #6 Snark1994 Senior Member   Registered: Sep 2010 Location: Wales, UK Distribution: Arch Posts: 1,632 Blog Entries: 3 Rep: Or languages like MATLAB which are designed exactly for things such as this...
10-05-2012, 11:45 PM   #7
hydraMax
Member

Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep:
Quote:
 Originally Posted by newbieseos I want to try solving system of linear algebraic equations in Shell bash but i have any problems Value input is matrix and I dont know how to input matrix in Shell because that is dont support 2-dimensional array Please help me. Thank you so much
Abort now before you lose your sanity. Bash sucks at doing anything beside executing independent programs sequentially or tying together I/O streams. In particular, Bash does weird things with arrays that you will find harder to figure out than your original problem.