# Creating Matrix,Inverted and Upper Triangulate inside Module

I was trying to fit this into a module but I didn't have any luck. And for some reason it won't Inverse the Matrix. Here's the code:

Input:

f[x_, y_] = 2^x - y
n = 3
m = Array[f, {n, n}]
k = MatrixForm[m]
Inverse[k]
MatrixForm[UpperTriangularize[m]]


Output:

And here is how the output should look like :

Is it possible to put this into a Module function? Please help!

• Look up Transpose[]. May 23, 2015 at 16:48
• You shouldn't use the output of MatrixForm to carry out further calculations (see: Why does MatrixForm affect calculations?). This is the reason why your Inverse was returned unevaluated. If you had tried Inverse[m] instead, you would have seen Matrix {{1,0,-1},{3,2,1},{7,6,5}} is singular. which would have been a lot more informative to you. May 23, 2015 at 17:09
• @MarcoB I updated my answer with your comment (if you don't mind), this is the correct answer indeed. May 23, 2015 at 17:38
• @Bichoy Of course, thanks for including it. May 23, 2015 at 18:59
• Ok thanks guys, I actually meant to use Transpose[](@Guesswhoitis.) and not Inverse[]. Anyway is there a way to implement this into a module, all of it? f[x_, y_] = 2^x - y | n = 3 m = Array[f, {n, n}] | MatrixForm[m] | Transpose[m] // MatrixForm | MatrixForm[UpperTriangularize[m]] | May 24, 2015 at 16:49

As pointed out by MarcoB in the comments, one shouldn't use MatrixForm for calculations (check the question he referred to). As he suggested, this is the real reason Inverse doesn't evaluate.
Also, in this case the matrix m is singular. You can easily check that by MatrixRank[m] which yields 2, and also by checking Det[m]==0.
How to proceed with m being singular highly depends on what you are trying to do next with Inverse[m].
• Ok thanks very much I did it! Only now to implement it into a module. f[x_, y_] = 2^x - y | n = 3 m = Array[f, {n, n}] | MatrixForm[m] | Transpose[m] // MatrixForm | MatrixForm[UpperTriangularize[m]] | May 24, 2015 at 16:51
• Then, just put the whole thing into a module, something like: Module[{f,n=3,m}, f[x_,y_] = 2^x -y; m=Array[f,{n,n}]; .... ]. This module will return the value of the last statement being evaluated (but don't terminate the last statement inside with ; ) May 24, 2015 at 17:00