LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Try solver System of linear algebraic equations in Shell Bash (https://www.linuxquestions.org/questions/programming-9/try-solver-system-of-linear-algebraic-equations-in-shell-bash-4175430241/)

newbieseos 10-03-2012 03:49 AM

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

pan64 10-03-2012 04:37 AM

you would better try to use awk/perl or another language, bash does not really support it and is hard to implement.

porphyry5 10-03-2012 04:52 AM

Quote:

Originally Posted by newbieseos (Post 4795804)
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


sycamorex 10-03-2012 04:55 AM

Another suggestion would be to use Python. It has lots of maths modules.

newbieseos 10-03-2012 05:34 AM

Thanks for all your replying

Snark1994 10-03-2012 05:57 AM

Or languages like MATLAB which are designed exactly for things such as this...

hydraMax 10-05-2012 10:45 PM

Quote:

Originally Posted by newbieseos (Post 4795804)
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.


All times are GMT -5. The time now is 06:54 AM.