Finding answers to system of equations

51 Views Asked by At

Let's say we have such a system structure of equations:

a(1,1)x(1) +a(2,1)x(2)....+a(n,1)x(n)=b(1)
a(1,2)x(1) +a(1,2)x(2)....+a(n,2)x(n)=b(2)
.
.
.
a(1,m)x(1) + a(2,m)x(2)...+a(n,m)x(n)=b(m)
where n,m are positive integers and A[1->n,1->m],B[1->m] are params.

Is there a fast way to determinate the unknown array X[1->n] ?

2

There are 2 best solutions below

3
On BEST ANSWER

Yes, this is a system of linear equations. You can solve this by solving the matrix equation $$\mathbf{Ax} = \mathbf{b}, $$

where $\mathbf{A}$ is an $n\times m$ matrix (or array), and $\mathbf{x}$ and $\mathbf{b}$ are vectors.

Depending on the structure of $\mathbf{A}$ you may solve this efficiently using particular factorization methods such as LU, LDL, or Cholesky-factorization. In general you could just use Gaussian Elimination.

3
On

I would like to point out that your setup is incorrect, per standard practice. That is, you have listed: $$ a(1,1)x(1) +a(2,1)x(2)....+a(n,1)x(n)=b(1)\\ a(1,2)x(1) +a(1,2)x(2)....+a(n,2)x(n)=b(2)\\ .\\ .\\ .\\ a(1,m)x(1) + a(2,m)x(2)...+a(n,m)x(n)=b(m)\\ $$

In every implementation of a matrix I've seen, though, the ordering is (ROW,COL). This means that your matrix should be setup where the first coefficient in the first equation is $a(1,1)$, the second would be $a(1,2)$, etc.

You're going to get the wrong answer if you try to take your $A$ matrix and solve it because you don't have it configured correctly. Granted, if you're doing this by hand, it probably won't be an issue because you'll just write the numbers in the correct spot, but if you try to take your $A$ matrix and pass it through an algorithm you are bound for disappointment.

What you have written is $A^T x = b$, where the superscript $^T$ denotes the transpose operator.

Lastly, I'd like to point out that in your setup you declare matrix $A$ to be an $n\times m$-sized matrix (but again, this is misleading as well because you have $m$ rows and $n$ columns, so it is actually an $m\times n$-sized matrix). If the number of rows of $A$ is less than the number of columns you can't find an answer; you have fewer equations than unknowns and will be left having to state the value of (number of columns - number of rows) variables as the remaining variables will all be dependent on those values.