0
$\begingroup$

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:

Output

And here is how the output should look like :

enter image description here

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

$\endgroup$
6
  • $\begingroup$ Look up Transpose[]. $\endgroup$ May 23, 2015 at 16:48
  • $\begingroup$ 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. $\endgroup$
    – MarcoB
    May 23, 2015 at 17:09
  • $\begingroup$ @MarcoB I updated my answer with your comment (if you don't mind), this is the correct answer indeed. $\endgroup$
    – Bichoy
    May 23, 2015 at 17:38
  • $\begingroup$ @Bichoy Of course, thanks for including it. $\endgroup$
    – MarcoB
    May 23, 2015 at 18:59
  • $\begingroup$ 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]] | $\endgroup$
    – Andrej
    May 24, 2015 at 16:49

1 Answer 1

2
$\begingroup$

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].

$\endgroup$
5
  • $\begingroup$ (Thanks for the correction Chris) $\endgroup$
    – Bichoy
    May 23, 2015 at 17:04
  • $\begingroup$ 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]] | $\endgroup$
    – Andrej
    May 24, 2015 at 16:51
  • $\begingroup$ 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 ; ) $\endgroup$
    – Bichoy
    May 24, 2015 at 17:00
  • $\begingroup$ Wow thanks a lot! I did it. It finally works like it should. $\endgroup$
    – Andrej
    May 24, 2015 at 17:15
  • $\begingroup$ You are very welcome @Andrej $\endgroup$
    – Bichoy
    May 24, 2015 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.