Table[ x^2, { x, 1, 10}]
The range { x, 1, 10} specifies that x ranges from 1 through 10, increasing by
1 in
each step. If we wanted the first ten odd squares, then we can use the range {
x, 1, 20, 2}.
Now x is incremented by 2 in each step. An ith element of a list L can be
accessed by
L[[i]]. The first and last elements of L are obtained by First[L] and Last[L].
A list is like a
vector and a list of lists (all identical size) is like a matrix, so matrix
operations
can be applied to these. Transpose exchanges the rows and the columns.
Consider the application of these in the following example.
factors= FactorInteger[ 789672] x= Transpose[factors] primefactors= First[x]
The result of these operations is to extract the prime factors of the number.
FactorInteger
returns a list of lists, ( a matrix) whose rows have two elements each, a
prime and its
exponent in the factorization. Transpose interchanges the rows and columns, so
the first
element of the transposed list is now a list of the prime factors.
More list processing functions are discussed in a separate chapter.
Exercise: Make a list of the first fifty Fibonacci numbers. Divide them
by3.
Which are divisible by 3? Make a conjecture and test it for larger Fibonacci
numbers
by making a list of only those Fibonacci numbers that you think are multiples
of 3.
Repeat the exercise to test divisibility by 3.
Up to Tutorial