# Division matrix

Joshua Landau joshua.landau.ws at gmail.com
Tue Nov 13 02:59:19 CET 2012

```On 13 November 2012 01:00, Cleuson Alves <cleuson.o at gmail.com> wrote:

> Hello, I need to solve an exercise follows, first calculate the inverse
> matrix and then multiply the first matrix.
>

This list isn't to give answers for homeworks, and this sounds like one. We
*do* give help to those who have a specific problem and who preferably show
that they are trying to help up help them.

> I await help.
>

For what?! You haven't asked a question.
1) What do you need. Answer precisely, preferably giving an example output
for the input you want
2) What techniques have you tried? You have given code below in an
extremely un-obvious manner. What does it do, crash? Is it the wrong
output? What is wrong about the output?
3) What do you *think* has gone wrong? What about the output seems to be
wrong?

> Thank you.
> follows the code below incomplete.
>

On the basis that we can get some foreign people who maybe don't have
English as a commonly used language, muddled grammar isn't that big deal.
However, when asking for help it is worth checking that you've asked in a
clear way.

> m = [[1,2,3],[4,5,6],[7,8,9]]
> x = []
> for i in [0,1,2]:
>     y = []
>     for linha in m:
>         y.append(linha[i])
>     x.append(y)
>
> print x
> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
>

Is this the right output? Is this what you *meant* by inverse? As Ian Kelly
(who is undoubtedly more learned in this area) said, this is a transpose,
so you have just swapped the one axis with another.

> def ProdMatrix(x,b):
>     tamL = len(x)
>     tamC = len(x[0])
>     c = nullMatrix(tamL,tamC)
>     for i in range(tamL):
>         for j in range(tamC):
>             val = 0
>             for k in range(len(b)):
>                 val = val + x[i][l]*b[k][j]
>             c[i][j]
>     return c
>

You haven't given the full code. This crashes because we don't have
"nullMatrix" defined. It would be nice if we had something we could try to
run.

Then, the error is: "NameError: global name 'l' is not defined". On the
line "val = val + x[i][l]*b[k][j]" you use a variable "l" which doesn't
exist. What should you be using, or should you have created it?

*Then* you get an output of pure 0s. This is because you forgot to put your
result into c, your new matrix.
You probably just forgot to finish the line "c[i][j]", which does nothing
now.

You're actually really close on the second part. I have no idea if you're
doing what you want for the first part, but it's not what's traditionally
called an inverse.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121113/039498c9/attachment.html>
```