Access Matrix Element in Mathematica

Click For Summary

Discussion Overview

The discussion revolves around accessing elements of a matrix in Mathematica, comparing it with other programming languages like Matlab. Participants share methods for element extraction and express their opinions on the usability of Mathematica versus other languages.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • One participant suggests using the Extract function to access matrix elements, providing an example.
  • Another participant mentions that L[[x]] can be used to extract the x-th element of a list and proposes defining a function for easier access to matrix elements.
  • A different participant expresses a preference for Matlab over Mathematica, citing its design for matrix manipulation.
  • One participant acknowledges the learning curve associated with functional programming in Mathematica.
  • Another participant asserts that accessing matrix elements is not difficult and suggests using the Part function.
  • Some participants express strong negative opinions about Mathematica compared to other programming languages.

Areas of Agreement / Disagreement

Participants express differing opinions on the usability of Mathematica versus other programming languages, with no consensus on which is superior for matrix manipulation.

Contextual Notes

Participants reference various programming languages and their respective strengths and weaknesses without resolving the debate over which is better for matrix operations.

Who May Find This Useful

Individuals interested in programming languages for mathematical computations, particularly those comparing Mathematica with alternatives like Matlab and Python.

Mindscrape
Messages
1,854
Reaction score
1
[SOLVED] Access Matrix Element in Mathematica

Alright, so in Mathematica you define a matrix by saying A = {{a11,12,...},{21,a22,...}} for whatever matrix you are making. How do you access a particular element of that matrix?

Argh, Matlab is so much better.
 
Physics news on Phys.org
Yep, Mathematica is the crappiest language I've ever come across, and I've worked with more than a few. :)

Use Extract, e.g.:

Extract[Extract[A,1],2] = a12

If possible, use IDL, Matlab, R, Octave, SciLab, Python with NumPy and SciPy or anything else. I'd rather use an abacus than use Mathematica :). Good luck with your work.

--------
Assaf
http://www.physicallyincorrect.com/"
 
Last edited by a moderator:
If I recall correctly, L[[x]] extracts the x-th element of a list.

If you really don't want to type A[[x]][[y]], you can always define a function:

A[x_, y_] := A[[x]][[y]]

and then you should be able to use A[x, y] to index your matrix. (I think you can use the same letter A for both these purposes. If it fails or you find it confusing, then just rename the function to something else.

You could even do a generic

Get[A_, x_, y_] := A[[x]][[y]]

that takes the matrix as an argument. Then you'd call

Get[A, x, y]



Matlab was designed for the sole purpose of manipulating matrices -- therefore it should be no surprise that it's more convenient to use Matlab instead of Mathematica for manipulating matrices. :wink:

Mathematica isn't a bad language: the catch is that it's a functional language, which takes a bit of adjustment if you've never programmed in a functional language before.
 
Last edited:
I guess it's a matter of taste. But I have worked with LISP & Haskell. Can't say they've changed my opinion about Mathematica :smile:

--------
Assaf
http://www.physicallyincorrect.com/"
 
Last edited by a moderator:
Got it. Thanks guys, I would have never sorted through mathematica help well enough to figure this out.
 


It really isn't that difficult - you can use Part[A, i, j]=aij
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 12 ·
Replies
12
Views
6K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K