Message Boards Message Boards

0
|
283 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Accessing matrix elements and evaluating terms multiplied by zero

Posted 12 days ago

I'm totally new to Mathematica. I defined a simple matrix and I tried to query the elements of the matrix but I keep getting an error as shown in the figure attached. I don't know if I'm doing a mistake in the syntax or this is a bug. Error

As a follow up to this question, another simple issue I'm facing is when I tried to evaluate some quantities I get a huge output with most of the terms multiplied by zero. Why is mathematica not making them zero, even when used with the commands Simplify or FullSimplify.

Please let me know where I'm making the mistake. Thanks.

POSTED BY: Arun KG
6 Replies

You are probably using the dot . as multiplication, but in WL it means scalar product of vectors. For example {1, 1} . (0) does not give zero. Plain multiplication is made with *

POSTED BY: Gianluca Gorni
Posted 11 days ago

Yes that was the mistake I was making. Thanks for the help! It works now :)

POSTED BY: Arun KG
Posted 12 days ago

This is a very common stumbling block for new users. Any function that ends in Form is for presentation purposes. What they do is wrap your expression in a way that tells the front end how to display the expression. It's best to avoid doing computations directly on the presentation form. So, when you did this

minkMetric =
 {{1, 0, 0, 0},
   {0, -1, 0, 0},
   {0, 0, -1, 0},
   {0, 0, 0, 1}} // MatrixForm

you didn't actually set minkMetric to a 2-dimensional list, but to an expression with head MatrixForm that itself contains a 2-dimensional list. That MatrixForm head tells the front end to "paint a pretty form" of the matrix. You can see this explicitly using FullForm:

minkMetric // FullForm
(* MatrixForm[List[List[1, 0, 0, 0], List[0, -1, 0, 0], List[0, 0, -1, 0], List[0, 0, 0, 1]]] *)

The idiom I use looks like this:

minkMetric =
  {{1, 0, 0, 0},
   {0, -1, 0, 0},
   {0, 0, -1, 0},
   {0, 0, 0, 1}};
minkMetric // MatrixForm

Now we've assigned the 2-dimensional structure to the symbol minkMetric and then just displayed it in a pretty form. You can see that minkMetric now is just a plain matrix.

minkMetric // FullForm
(* List[List[1, 0, 0, 0], List[0, -1, 0, 0], List[0, 0, -1, 0], List[0, 0, 0, 1]] *)

Now you can access the items:

minkMetric[[2, 3]]
(* 0 *)

As for your follow up question, I would need more information.

POSTED BY: Eric Rimbey
Posted 12 days ago

Ah that makes sense, it is such a silly mistake on my part XD. Thanks for clearing that up. As to the follow-up I mean the results I show in the image attachedZeroNotEvaluated

There are terms here that are clearly zero since they are multiplied by zero, but Mathematica is not evaluating them. How do I fix this minor issue? Please help. Thanks.

POSTED BY: Arun KG
Posted 11 days ago

You'll get better answers if you post code rather than pictures, because that allows people to copy-paste your code into their own notebooks to play around with. All I can do is make a guess based on your picture. My guess is that those are Dot products, and Dot doesn't evaluate when the arguments are not of compatible dimensions.

POSTED BY: Eric Rimbey
Posted 11 days ago

Yes it works correctly now. Thanks a lot of the help! And yes I will start sharing the notebook from the next time. I'm totally new to this so I'm just learning how things are done here, thanks a lot for the patience.

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

Group Abstract Group Abstract