Group Abstract Group Abstract

Message Boards Message Boards

0
|
288 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Rules to convert parentheses for vectors and matrices to lists?

Posted 10 days ago

I just find it much easier to use the traditional notation involving parentheses for vectors and matrices.
I think the following works for two dimensional vectors and matrices, but should I worry about the error messages? It seems to do what I want.

enter image description here

4 Replies

The error messages are there because you are evaluating RegionPlot and other commands with invalid arguments. To avoid the error messages, I suggest immediate evaluation with Quiet:

crcChord5[{h_, k_}, r_, line_] = 
 Quiet@ReplaceAll[
  RegionPlot[ImplicitRegion[line, {x, y}], etc

Your use of Evaluate defeats the purpose of the delayed definition :=

POSTED BY: Gianluca Gorni

You can use $PreRead to rewrite your input into the standard Mathematica input. In the form below, this means any 2x1 grid surrounded by parentheses in your code will be converted from a 2x1 matrix to a 2-vector when it is sent to the kernel for evaluation. You cannot enter a 2x1 matrix this way and have it be a 2x1 matrix. If you enter {{a}, {b}}, then that will stay a 2x1 matrix; since the input is not a grid, it will not be converted to a vector.

The unset, $PreRead =., stops the conversions and returns Mathematica to its default behavior of interpreting grid inputs as matrices.

Another way is to use MakeExpression[] to do the same thing:

I don't usually do this. I just get used to the Mathematica way. $PreRead is fiddly. Once you set it, it can affect every input. If you make a mistake in its code, then you might not be able to unset it. You usually can quit the kernel from the Evaluation menu, which resets everything. In the worst case, you might have to kill the Mathematica process externally (for instance, if you print something in an infinite loop) or it might crash for you (for instance, if you use up all your memory, which potentially could freeze up the whole computer). I can't always avoid doing something stupid, but I try to avoid practices that make stupid costly.

There is also the Notations package, which you could use to create your own input form.

POSTED BY: Michael Rogers

Thanks very much, this looks helpful. I'm still trying to figure out exactly how the Wolfram language represents different kinds of vectors. In spite of comments in the Help about how vectors are just lists, sometimes column vectors seems to have one higher level of nesting.

Have to admit that I find trying to figure out the definition of tensor product in Wolfram very tough to understand. I wish I could get away with thinking of multi-dimensional arrays of numbers. And then somehow spreading all these out the way one would the contents of file cabinets and rooms and floors of file cabinets!

I made a couple of mistakes in my previous post: I meant to use ReplaceRepeated, not ReplaceAll, and I used the rule with parentheses just in case this might match better.

As I was saying, I just find it much easier to use the traditional notation involving parentheses for vectors and matrices. I think the following works for two dimensional vectors and matrices, but should I worry about the error messages? It seems to do what I want.

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