Re: Matrix manipulation
- To: mathgroup@smc.vnet.net
- Subject: [mg12362] Re: [mg12327] Matrix manipulation
- From: Daniel Lichtblau <danl@wolfram.com>
- Date: Sun, 10 May 1998 02:04:44 -0400
- References: <199805072252.SAA01047@smc.vnet.net.>
Michael Chang wrote: > > Hi everyone! > > I'm running Mathematica 3.1.x on Windoze 95. Here's a simple question > that has been bothering me recently. > > Suppose I define: > > a={{1,2},{3,4}}; > > In this case, > > Inverse[a] > > gives back the expected result > > {{-2,1},{3/2,-1/2}} > > However, suppose I now define > > b=a//MatrixForm > > and now type > > Inverse[b] > > I *don't* get back any answer as before, but just my input > > Inverse[(2 3)] > [(4 5)] > > (The above is supposed to be a matrix!). Anyways, why is this?!? Other > operations also fail to work in the same manner, such as Det, > Transpose, Eigenvalues, Eigenvectors, etc. > > Is this a bug with Mathematica's front end? Any help with this would be > greatly appreciated! > > Thanks, > > Mike Your b has a MatrixForm wrapper. To see this use InputForm or FullForm to output it. In[12]:= InputForm[b] Out[12]//InputForm= MatrixForm[{{1, 2}, {3, 4}}] This thing is not a matrix for purposes of later computations, because it does not have head List. You could write a function that looks for such heads, replaces them with List, does what you want, and converts back. formatHead[h_] := h===MatrixForm || h===InputForm || h===TableForm || h===FullForm myMatrixFunction[func_, head_?formatHead[mat_?MatrixQ]] := head[func[mat]] In[18]:= myMatrixFunction[Inverse,b] Out[18]//MatrixForm= -2 1 3 1 - -(-) 2 2 Daniel Lichtblau Wolfram Research
- References:
- Matrix manipulation
- From: bt585@FreeNet.Carleton.CA (Michael Chang)
- Matrix manipulation