Lists and transformations of lists
Example 1. Vectors and other similar mathematical objects are presented in Mathematica through a list of arranged elements, unified in curly brackets { }. The list can be stored in an ordinary variable. Extraction of a specific element is done with the operation [[ ]] - double square brackets. Here are two five dimensional vectors.
{1,2,3,4,5}
a={-2.2,3.2,0,2,0}
a[[1]]
a[[3]]
Example 2. Squaring, increasing power or any other action is done for each separate element.
b={0,1,2,3,4,5}
Example 3. Specific replacements with variable values and extraction of 2nd and 3rd element from the obtained results.
c1 /.x->2
c2 /. {x->1, y->2z}
%[[2]] (* Extraction of the second element from the prevoius result *)
%%[[3]] (* Third element from the before last result *)
Example 4. Differentiation - first and second derivative with respect to x. Mathematical symbols from the palettes may also be used, such as , etc.
Example 5. The table is also a list, but its elements are calculated with formulas.
1 |
8 |
27 |
64 |
125 |
216 |
343 |
512 |
729 |
1000 |
Example 6. For example the table of the function with x changing in the interval [0, 1] with a 0.2 step is done like this:
Example 7. Here are generating of 5 random numbers in the interval [0,1]. Then - 6 random numbers in the interval [1, 49] which are sorted in ascending way with the fucntion Sort.
Table[Random[],{5}]
Table[Random[Integer,{1,49}],{6}]
s1=Sort[%]
Example 8. Showing the list vertically.
TableForm[s1]
17 |
23 |
24 |
33 |
43 |
44 |
Example 9. The same with the function ColumnForm.
ColumnForm[s1]
17 |
23 |
24 |
33 |
43 |
44 |
Example 10. Forming a two dimensional list, which is a list of lists and it its presentation in different ways.
a=.
a=Table[i+j,{i,1,3},{j,1,3}]
TableForm[a]
ColumnForm[a]
2 | 3 | 4 |
3 | 4 | 5 |
4 | 5 | 6 |
{2, 3, 4} |
{3, 4, 5} |
{4, 5, 6} |
Example 11. Table of two rows and four columns.
b=Table[i+j,{i,1,2},{j,1,4}]
TableForm[b]
MatrixForm[b]
2 | 3 | 4 | 5 |
3 | 4 | 5 | 6 |
Example 12. Extraction of matrix elements.
b[[1]]
b[[2,3]]
Part[b,1]
Example 13. Product of vectors and matrices.
Clear[a,b,c,p,q,r,u,v]
u={a,b,c}
v={p,q,r}
u.v
Created by Mathematica (December 21, 2007)