Group Abstract Group Abstract

Message Boards Message Boards

0
|
548 Views
|
8 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Mathematica 14.2 is not performing matrix multiplication on 3 times 3 matrices.

enter image description here

POSTED BY: P. Marrone
8 Replies
Posted 7 days ago

Multiplying matrices when they are wrapped in MatrixForm or Grid can be done, as shown below:

The cosmetic wrapper is part 0. The actual matrix is part 1. The function First returns part 1.

POSTED BY: Hans Milton
Posted 8 days ago

Mathematica has nice features for display of various data structures, but it does its computations on very simple, often List-based structures. Many of the display features will interfere with computation. As a general rule (not 100%), any Mathematica function that ends in Form (e.g. MatrixForm, TableForm) is for display purposes only. When the front end "sees" MatrixForm, it creates a special "object" that makes the pretty display. If you try to do subsequent computations on that object, you will get unexpected results. Two of these *Form "functions" are useful for debugging: InputForm and FullForm. Also useful for debugging are various "functions" that prevent evaluation.

So, to debug your notebook, here's what I did...

For your first input, I copied the cell contents to my clipboard by hovering over it and choosing "copy" (which is just a feature of this website). I pasted directly into a new notebook and then surrounded it with Hold and FullForm like this:

enter image description here

Then I evaluated that, which produced the following:

Hold[Eigensystem[List[List[6, 2, 1], List[0, 4, 2], List[0, 0, 3]]]]

That looks fine. I did the same thing with your next cell:

enter image description here

and I got this:

Hold[MatrixForm[
  Inverse[Grid[List[List[1, -1, 1], List[0, 1, -2], List[0, 0, 1]], 
    Rule[ItemSize, List[Inherited, Inherited]]]]]]

And now we can see a problem. Instead of taking Inverse of a matrix, you're taking Inverse of a Grid expression, which doesn't make any sense. I don't know how you got a Grid expression in there -- you'll need to think back on your process to figure that out. But if we get rid of that Grid, it should work fine:

Inverse[List[List[1, -1, 1], List[0, 1, -2], List[0, 0, 1]]]
(* output is {{1, 1, 1}, {0, 1, 2}, {0, 0, 1}} *)

Of course, List[List[1, -1, 1], List[0, 1, -2], List[0, 0, 1]] is the fully expanded expression (what FullForm shows you). You could just as easily have used the "normal" input form (what InputForm shows you):

Inverse[{{1, -1, 1}, {0, 1, -2}, {0, 0, 1}}]

Continue this process for the rest of you notebook. You'll see that you have Grid littered throughout your code, and that is interfering with the matrix calculations.

Side note... ClearAll isn't used as a standalone command. You need to tell it which symbols you want to clear. One common usage is ClearAll["Global`*"]. In your case, I don't see that your code defines any symbols, so there is no need to use ClearAll.

POSTED BY: Eric Rimbey

POSTED BY: P. Marrone

You are using Grid to compose matices. Don't do that.

POSTED BY: Gianluca Gorni

MatrixForm is a pitfall as old as Mathematica. We must be careful to use it only for final display, but not for calculation. For example

IdentityMatrix[2] // MatrixForm

gives a nice-looking output, but it is wrapped into an invisible cloak that shields it from further calculation. What I suspect you did is to copy and paste the result of MatrixForm for more computation: sadly, you also copied the invisible cloak.

POSTED BY: Gianluca Gorni

Thank you pardon me. What do you mean by use InputForm. What is a MatrixFormWrapper?

How do I get code in pastable for?

POSTED BY: P. Marrone
In[26]:= Eigensystem[\!\(\*
TagBox[
RowBox[{"(", GridBox[{
{"6", "2", "1"},
{"0", "4", "2"},
{"0", "0", "3"}
}], ")"}],
"Grid"]\)]


Out[26]= {{6, 4, 3}, {{1, 0, 0}, {-1, 1, 0}, {1, -2, 1}}}

In[27]:= Inverse[\!\(\*
TagBox[
RowBox[{"(", GridBox[{
{"1", 
RowBox[{"-", "1"}], "1"},
{"0", "1", 
RowBox[{"-", "2"}]},
{"0", "0", "1"}
}], ")"}],
"Grid"]\)] // MatrixForm

Out[27]//MatrixForm= \!\(
TagBox[
RowBox[{"(", "", GridBox[{
{"1", "1", "1"},
{"0", "1", "2"},
{"0", "0", "1"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}], "", ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\)

In[2]:= \!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{"1", "1", "1"},
{"0", "1", "2"},
{"0", "0", "1"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}], "", ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\) . ( \!\(\*
TagBox[GridBox[{
{
RowBox[{"e", "^", 
RowBox[{"{", 
RowBox[{"6", "t"}], "}"}]}], "0", "0"},
{"0", 
RowBox[{"e", "^", 
RowBox[{"{", 
RowBox[{"4", "t"}], "}"}]}], "0"},
{"0", "0", 
RowBox[{"e", "^", 
RowBox[{"{", 
RowBox[{"3", "t"}], "}"}]}]}
}],
"Grid"]\) ) . ( {
   {1, -1, 1},
   {0, 1, -2},
   {0, 0, 1}
  } ) . ( \!\(\*
TagBox[GridBox[{
{"x"},
{"y"},
{"z"}
}],
"Grid"]\) )

Out[2]= {{1, 1, 1}, {0, 1, 2}, {0, 0, 1}} . \!\(\*
TagBox[GridBox[{
{
RowBox[{"{", 
SuperscriptBox["e", 
RowBox[{"6", " ", "t"}]], "}"}], "0", "0"},
{"0", 
RowBox[{"{", 
SuperscriptBox["e", 
RowBox[{"4", " ", "t"}]], "}"}], "0"},
{"0", "0", 
RowBox[{"{", 
SuperscriptBox["e", 
RowBox[{"3", " ", "t"}]], "}"}]}
},
AutoDelete->False,
GridBoxItemSize->{}],
"Grid"]\) . {{1, -1, 1}, {0, 1, -2}, {0, 0, 1}} . \!\(\*
TagBox[GridBox[{
{"x"},
{"y"},
{"z"}
},
AutoDelete->False,
GridBoxItemSize->{}],
"Grid"]\)&[Wolfram Notebook][1]
POSTED BY: P. Marrone

(1) Use InputForm to see what it is you are actually evaluating. You will find a MatrixForm wrapper that is getting in the way.

(2) In general to get assistance one should provide actual code in copy-pastable form.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard