Referring to elements of a table in Mathematica

In summary, the conversation discusses different methods for creating a new table that represents the change in values of an existing table. The first method involves defining a new variable, c_i, and setting it equal to the difference between consecutive values of the original table B. The second method involves assigning an indexed variable to each value of the table, using either the suggested method or a loop.
  • #1
MostlyHarmless
345
15
See title.

I have a table that I've named B. And I want to create table that is essentially the change in values of B. If I was writing this on paper I would say: Let ##b_i \in B##, for ##0\leq i\leq100##. Then let ##c_i \in C## such that ##c_i= b_{i+1}-b_{i}##. I don't know how to say that in Mathematica's language though.

Another option I guess would be to find a way to assign an indexed variable to each value of the table. With the indexing variable being the same.
 
Last edited:
Physics news on Phys.org
  • #2
The help page suggests something along the line of C=B[[2;;100]]-B[[1;;99]], but I cannot test it here.
Something that certainly works is a loop.
 

Related to Referring to elements of a table in Mathematica

What is a table in Mathematica?

A table in Mathematica is a data structure that stores information in rows and columns. It is similar to a spreadsheet and is commonly used to organize and manipulate data in Mathematica.

How do I refer to elements in a table in Mathematica?

To refer to an element in a table in Mathematica, you can use the Part function, denoted by double brackets "[[ ]]". For example, if you have a table called "myTable" and want to access the element in the second row and third column, you would use myTable[[2,3]].

Can I refer to multiple elements in a table at once in Mathematica?

Yes, you can use the Span operator (a colon) to refer to a range of elements in a table. For example, myTable[[2;;4,1]] would refer to the elements in rows 2, 3, and 4 in the first column of myTable.

What is the difference between referring to elements using double brackets and single brackets in Mathematica?

Double brackets "[[ ]]" are used to refer to specific elements in a table, while single brackets "[ ]" are used to refer to entire rows or columns. For example, myTable[[2,3]] would refer to a single element, while myTable[[2]] would refer to the entire second row of the table.

Can I refer to elements in a table using their names instead of indices in Mathematica?

Yes, you can assign names to elements in a table using the Association function and then refer to them using their names. For example, myTable = Association["A" -> 1, "B" -> 2] would create a table with the elements "A" and "B" and their corresponding values. You can then refer to them using myTable["A"] or myTable["B"].

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
729
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
11
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Electrical Engineering
Replies
3
Views
866
Replies
80
Views
4K
Back
Top