MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Matrix manipulation



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



  • Prev by Date: Re: Black-Scholes option pricing model
  • Next by Date: Re: Hermite Normal Form
  • Prev by thread: Matrix manipulation
  • Next by thread: Re: Matrix manipulation