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 at 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.
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.
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.
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 . 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.
Example 5. Here is the graph of the table s1.
ListPlot[s1]
ListPlot[s1,PlotJoined->True]
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[]]
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[%]
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}]
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[]
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.
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]
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]
Created by Mathematica (January 13, 2008)