<p>Maybe this helps. One method to do this is to use least squares (as was mentioned by @cc7768).
Matlab does this by default when using the <code>\</code> operator.
This is also useful because it's sensible even if the system is overidentified as in the following example:</p>

<pre><code>A = [1 22; 2 100; 7 6]
b = [1 2 5]'
A\b
</code></pre>

<p>produces</p>

<pre><code>ans =

    0.7108
    0.0061
</code></pre>

<p>. In Python, this can be done with</p>

<pre><code>import numpy
from numpy import linalg
A = numpy.matrix("1 22; 2 100; 7 6")
b = numpy.matrix("1 2 5").T
linalg.lstsq(A,b)[0]
</code></pre>

<p>which gives</p>

<pre><code>matrix([[ 0.71084144],
        [ 0.00611577]])
</code></pre>

<p>.</p>

CC BY-SA 3.0
2015-03-06T23:37:32.420Z
Instead of Matlab you could stick with open source and use [Julia](http://julialang.org/) ;) Python also has this functionality through scipy's solve method `scipy.linalg.solve`.
cc7768
CC BY-SA 3.0
2015-03-06T23:36:33.763Z
2015-03-06T23:36:33.763Z
jmbejara
<p><em>Following is a question that did not receive attention at math.SE at all. I am aware that is would be better suited there, but given its Economic background, perhaps it will get more attention here. If not, I'm happy to call this a failed attempt and delete it</em>.</p>

<p>I need to solve $Ag=b$ for $b$, where $A$ is not symmetric.</p>

<p>$$A g = b \\
A = \left(\begin{matrix} A_1 \\ E_{IJ} \otimes \mathbb 1  \end{matrix}\right)$$</p>

<p>For some positive integers $I, J$: $A$ has size $(IJ\cdot J)\times IJ$, $g$ has size $IJ \times 1$, and $b$ has size $IJ \times 1$. $A$ is vertically stacked $A_1, A_2$, where $A_1$ is $IJ\times IJ$.  $\mathbb 1$ is $J\times 1$ vector of ones, and $E$ is the identity matrix. </p>

<p>I need to solve this for $g$ on a computer for the case where $J$ small and $I$ large. I am fairly certain (through the way I get $A_1$ and $A_2$) that with $A_1$ being singular, my system of equations is exactly identifying $g$.</p>

<p>I'm used to the case where $A$ is symmetric and invertible. How do I proceed here?</p>

CC BY-SA 3.0
2015-03-06T22:02:50.443Z
I don't understand. If $E_{IJ}$ is the (IJ x IJ) identity and $1$ is $1 X J$, then it seems that the kronecker product $E_{IJ} \otimes 1$ should be $IJ \times IJ^2$. If $A_1$ is $IJ \times IJ$, then there seems to be a conformity problem.
jmbejara
CC BY-SA 3.0
2015-03-06T22:35:31.597Z
I don't think that's correct. You probably mean that $1 \otimes E_{IJ}$ should be $J* IJ \times IJ$. If A is an m × n matrix and B is a p × q matrix, then the Kronecker product $A \otimes B$ is the mp × nq block matrix.
jmbejara
CC BY-SA 3.0
2015-03-06T22:44:35.927Z
@jmbejara yes, I agree - but the matrices are still conform.
FooBar
CC BY-SA 3.0
2015-03-06T22:53:03.177Z
Yes, now that the notation is fixed. So, what exactly is the question? If the system is exactly identified and you just want to solve this on a computer, `A\b` in Matlab will solve this using an appropriate method. Do you want something more?
jmbejara
CC BY-SA 3.0
2015-03-06T22:55:14.220Z
@jmbejara `A` is not symmetric and not invertible. I am not using Matlab. What would be an "appropriate method" here? Standard "linsolve" methods that I use in Python require invertibility.
FooBar
CC BY-SA 3.0
2015-03-06T23:23:03.297Z
Note: I'm pretty sure if the system is singular there won't necessarily be a unique solution (Edit: It will have either infinite or possibly none -- see [this question](http://math.stackexchange.com/questions/93186/solving-systems-of-linear-equations-when-matrix-of-coefficients-is-singular). Also recommended was least squares).  That being said, if there is a method to solve it then it will be listed [here](http://www.netlib.org/lapack/lug/node38.html)
cc7768
CC BY-SA 3.0
2015-03-06T23:27:57.953Z
@cc7768 *the system* is not singular. $A_1$ is singular, $A$ is not. I can expand on my question on why I am pretty certain about that. I'll have a look at that link once I have sufficient time.
FooBar
CC BY-SA 3.0
2015-03-06T23:36:09.983Z
I could be way off (I sometimes make bold dumb claims when it comes to linear algebra), but if $A$ isn't invertible then isn't it singular?
cc7768
CC BY-SA 3.0
2015-03-07T02:50:38.593Z
Notation is still unclear. As it is written now, $A_2$ will be $IJ^2 \times IJ$, and thus $A$ will be $IJ(J+1) \times IJ$. More importantly, $b$ must have as many elements as $A$ has rows. The system is overdetermined, so I'd expect typically no exact solution (unless $b$ has also some special structure?).
ivansml
<general-equilibrium>
Solving Ag=b with non symmetric A
FooBar
# Solving Ag=b with non symmetric A

(Asked by: username_0 on 2015-03-06)

*Following is a question that did not receive attention at math.SE at all. I am aware that is would be better suited there, but given its Economic background, perhaps it will get more attention here. If not, I'm happy to call this a failed attempt and delete it*.

I need to solve $Ag=b$ for $b$, where $A$ is not symmetric.

$$A g = b \\
A = \left(\begin{matrix} A\_1 \\ E\_{IJ} \otimes \mathbb 1 \end{matrix}\right)$$

For some positive integers $I, J$: $A$ has size $(IJ\cdot J)\times IJ$, $g$ has size $IJ \times 1$, and $b$ has size $IJ \times 1$. $A$ is vertically stacked $A\_1, A\_2$, where $A\_1$ is $IJ\times IJ$. $\mathbb 1$ is $J\times 1$ vector of ones, and $E$ is the identity matrix.

I need to solve this for $g$ on a computer for the case where $J$ small and $I$ large. I am fairly certain (through the way I get $A\_1$ and $A\_2$) that with $A\_1$ being singular, my system of equations is exactly identifying $g$.

I'm used to the case where $A$ is symmetric and invertible. How do I proceed here?

**Tags:** general-equilibrium

> **Comments:**
> **username_1**: I don't understand. If $E_{IJ}$ is the (IJ x IJ) identity and $1$ is $1 X J$, then it seems that the kronecker product $E_{IJ} \otimes 1$ should be $IJ \times IJ^2$. If $A_1$ is $IJ \times IJ$, then there seems to be a conformity problem.  
> **username_1**: I don't think that's correct. You probably mean that $1 \otimes E_{IJ}$ should be $J* IJ \times IJ$. If A is an m × n matrix and B is a p × q matrix, then the Kronecker product $A \otimes B$ is the mp × nq block matrix.  
> **username_0**: @username_1 yes, I agree - but the matrices are still conform.  
> **username_1**: Yes, now that the notation is fixed. So, what exactly is the question? If the system is exactly identified and you just want to solve this on a computer, `A\b` in Matlab will solve this using an appropriate method. Do you want something more?  
> **username_0**: @username_1 `A` is not symmetric and not invertible. I am not using Matlab. What would be an "appropriate method" here? Standard "linsolve" methods that I use in Python require invertibility.  
> **username_2**: Note: I'm pretty sure if the system is singular there won't necessarily be a unique solution (Edit: It will have either infinite or possibly none -- see [this question](http://math.stackexchange.com/questions/93186/solving-systems-of-linear-equations-when-matrix-of-coefficients-is-singular). Also recommended was least squares).  That being said, if there is a method to solve it then it will be listed [here](http://www.netlib.org/lapack/lug/node38.html)  
> **username_0**: @username_2 *the system* is not singular. $A_1$ is singular, $A$ is not. I can expand on my question on why I am pretty certain about that. I'll have a look at that link once I have sufficient time.  
> **username_2**: I could be way off (I sometimes make bold dumb claims when it comes to linear algebra), but if $A$ isn't invertible then isn't it singular?  
> **username_3**: Notation is still unclear. As it is written now, $A_2$ will be $IJ^2 \times IJ$, and thus $A$ will be $IJ(J+1) \times IJ$. More importantly, $b$ must have as many elements as $A$ has rows. The system is overdetermined, so I'd expect typically no exact solution (unless $b$ has also some special structure?).  

---

## 1 answers

### Answer by username_1 on 2015-03-06. Score: 2

Maybe this helps. One method to do this is to use least squares (as was mentioned by @username_2).
Matlab does this by default when using the `\` operator.
This is also useful because it's sensible even if the system is overidentified as in the following example:

```
A = [1 22; 2 100; 7 6]
b = [1 2 5]'
A\b

```

produces

```
ans =

    0.7108
    0.0061

```

. In Python, this can be done with

```
import numpy
from numpy import linalg
A = numpy.matrix("1 22; 2 100; 7 6")
b = numpy.matrix("1 2 5").T
linalg.lstsq(A,b)[0]

```

which gives

```
matrix([[ 0.71084144],
        [ 0.00611577]])

```

.

> **Comments:**
> **username_2**: Instead of Matlab you could stick with open source and use [Julia](http://julialang.org/) ;) Python also has this functionality through scipy's solve method `scipy.linalg.solve`.  

---

