Tables and graphs, identity verification
Functions: Table, TableForm, ListPlot, Show, Part, Random, PrimeQ and more.

Example 1. Creating tables is done with the function Table. Here is a table containing 20 values of the function ^x/5at x=1, 2, ... ,20. Usually, the result is shown and saved as a list. In order to represent it vertically we use the function TableForm. Here //N means numerical answers and '%' is the result of the previous operation.

data = Table[^x/5, {x, 20}] data//N TableForm[%]

{^(1/5), ^(2/5), ^(3/5), ^(4/5), , ^(6/5),  ... 14/5), ^3, ^(16/5), ^(17/5), ^(18/5), ^(19/5), ^4}

RowBox[{{, RowBox[{1.2214, ,, 1.49182, ,, 1.82212, ,, 2.22554, ,, 2.71828, ,, 3.32012, ,, 4.05 ... 13.4637, ,, 16.4446, ,, 20.0855, ,, 24.5325, ,, 29.9641, ,, 36.5982, ,, 44.7012, ,, 54.5982}], }}]

1.2214
1.49182
1.82212
2.22554
2.71828
3.32012
4.0552
4.95303
6.04965
7.38906
9.02501
11.0232
13.4637
16.4446
20.0855
24.5325
29.9641
36.5982
44.7012
54.5982

Example 2. Drawing point data is done with the function ListPlot. We can combine the points, in other words create a linear spline, by turning on the option  PlotJoined->True.

ListPlot[data] g2 = ListPlot[data, PlotJoinedTrue]

[Graphics:HTMLFiles/index_6.gif]

⁃Graphics⁃

[Graphics:HTMLFiles/index_8.gif]

⁃Graphics⁃

Example 3. Here is creation of another single value table with a different range of the variable. The simultaneous display of graphs is done with the function Show. Notice that the numbering of the elements always starts at 1 no matter what the variable 'i' is.

d2 = Table[(1 + i^3)/(1 + i^2), {i, 5, 20}] g3 = ListPlot[d2, PlotJoinedTrue] Show[g2, g3]

{63/13, 217/37, 172/25, 513/65, 365/41, 1001/101, 666/61, 1729/145, 1099/85, 2745/197, 1688/113, 4097/257, 2457/145, 5833/325, 3430/181, 8001/401}

[Graphics:HTMLFiles/index_12.gif]

⁃Graphics⁃

[Graphics:HTMLFiles/index_14.gif]

⁃Graphics⁃

Example 4. Tables can also be created by increasing the variable with an arbitrary constant value or step. For example, for the function Cos[2x] the variable 'x' changes from -π  to π  through  π/10. This way we get 21 values. Extracting a defined element is done by using its index with [[ ]] or Part. In the example below we have chosen the third element of the table, saved to the variable s1.

step = π/10 s1 = Table[ Cos[2x], {x, -π, π, step}]//N s1[[3]] Part[s1, 3]

π/10

RowBox[{{, RowBox[{1., ,, 0.809017, ,, 0.309017, ,, RowBox[{-, 0.309017}], ,, RowBox[{-, 0.809 ... , 1.}], ,, RowBox[{-, 0.809017}], ,, RowBox[{-, 0.309017}], ,, 0.309017, ,, 0.809017, ,, 1.}], }}]

0.309017

0.309017

Example 5. Here is the graph of the table s1.

ListPlot[s1]
ListPlot[s1,PlotJoined->True]

[Graphics:HTMLFiles/index_22.gif]

⁃Graphics⁃

[Graphics:HTMLFiles/index_24.gif]

⁃Graphics⁃

Example 6. The common way to check for the authenticity of equations is to use numbers, randomly generated in a defined interval. This is done with the function Random without an argument or with a whole number for an argument. It generates a random number in the interval [0, 1]. Deriving whole numbers within a given interval is done by assigning an Integer argument and an interval or with the function Round. In the example we have an interval for random numbers [0, 10]. Repeat the cell many times over.

Random[]
Random[]
Random[]
Random[Integer,{1,1    0}]
Round[10*Random[]]

0.788172

0.654077

0.22338

1

7

Example 7. Generating a table of six random numbers with possible repetition in the interval [1, 49]. In the last line is the sorted table (list) t3.

n=6;
dolu=1;
gore=49;
t1= Table[Random[Integer,{dolu,gore}], {n}]
t2= Table[Random[Integer,{dolu,gore}], {n}]
t3= Table[Random[Integer,{dolu,gore}], {n}]
Sort[%]

{19, 4, 31, 17, 44, 5}

{7, 1, 32, 9, 49, 22}

{3, 41, 31, 39, 19, 13}

{3, 13, 19, 31, 39, 41}

Example 8. Generating a tables of eight integer, real and complex random numbers in different intervals.

Table[Random[Integer , 20],{8}]
Table[Random[Real,{10 ,11}],{8}]
Table[Random[Complex,{1+i,10+10i}],{8}]

{10, 2, 12, 15, 7, 15, 12, 15}

RowBox[{{, RowBox[{10.9123, ,, 10.7255, ,, 10.6186, ,, 10.2927, ,, 10.7759, ,, 10.018, ,, 10.5592, ,, 10.6148}], }}]

RowBox[{{, RowBox[{RowBox[{RowBox[{1.87442, }], +, RowBox[{3.60355,  , }]}], , ... , }]}], ,, RowBox[{RowBox[{4.97183, }], +, RowBox[{7.85801,  , }]}]}], }}]

Example 9. Authenticating equations and identities can be done by temporarily substituting arguments - random numbers. If the equation is correct we recieve 'True' as an answer and if it is not - 'False'. In the table we have the Authentications: is 1 equal to 2, is 3 equal to 3 etc.

1 == 2
3 == 3
Sin[Cos[x]] == Cos[ Sin[x]] /. x->Random[]
Sin[Cos[x]] == Cos[ Sin[x]] /. x->Random[]

False

True

False

False

Example 10. Here we have two identities with two variables. It is easily authenticated by executing the cell that the first is always true, but the second is always false.

a^2 - b^2 (a + b) (a - b)/.{aRandom[], b Random[]} a^2 + b^2 (a + b) (a - b)/.{aRandom[], b Random[]}

True

False

Example 11. Now we will create a table of the first 100 prime numbers. The funcrion Primer[n] prints the 'n'-th prime number. A graph of the first 100 prime numbers is also given.

Prime[5]
Prime[1000]
p=Table[Prime[n],{n,100}]
ListPlot[p,PlotJoined->True]

11

7919

{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 9 ... 19, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541}

[Graphics:HTMLFiles/index_48.gif]

⁃Graphics⁃

Example 12. Authenticating prime numbers is a big problem from the theory of numbers. Mathematica handles this numerically very well. We simply need to use the function PrimeQ with the number in question as an argument.

PrimeQ[13]
PrimeQ[15]
PrimeQ[1337]
PrimeQ[16300109754300123107]
opit=Random[Integer,{100,1000}]
PrimeQ[opit]

True

False

False

True

947

True


Created by Mathematica  (January 13, 2008)