Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to define simple matrix algebra (inspired by the following posts: Block Matrix Algebra with Mathematica ; How to define custom operators ).

I assume the funtion MatrixMult[A_,B_] to be the matrix product. I surely can define some properties of this function, like linearity, associativity etc. (see referenced posts). Now I want to solve simple matrix equation

Solve[MatrixMult[A, X]==B,X]

Obviously, the answer is

{{X -> InverseFunction[MatrixMult, 2, 2][A, B]}}

Now the question is how can I explicitly define that the inverse of my function is the following:

InverseFunction[MatrixMult, 2, 2][A_, B_] := MatrixMult[Inverse[A], B]

(the last line results in "Tag InverseFunction is Protected" error)

share|improve this question
    
Either unprotect the symbol or change the name of your predicate. Also look up What are the most common pitfalls ... thread and see the difference between = and := when defining predicates. –  Sektor Mar 3 at 10:22
    
I get the idea about Unprotect, but still couldn't get it work. After I define the inverse function (with SetDelayed) the Solve function returns {}. What do you mean by "change the name of your predicate"? –  bcp Mar 3 at 10:59
    
Well, InverseFunction is a built-in predicate, so you can't just use it overwrite it. –  Sektor Mar 3 at 11:05
    
Both Solve and InverseFunction are meant to be used with scalars only. What you are asking for would not be useful in this specific situation. For symbolic matrix algebra, google for the NCAlgebra package. –  Szabolcs Mar 3 at 14:30
1  
Redefining built-ins is usually not a good idea, as it might break random and unexpected things. (This is a good example: Solve won't even return the InverseFunction any more.) What you could do instead is use a replacement rule that is not tied to InverseFunction and apply it manually, i.e. result /. InverseFunction[MatrixMult, 2, 2][A_, B_] :> MatrixMult[Inverse[A], B]. –  Szabolcs Mar 3 at 21:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.