next up previous
Next: Plotting Functions and Lists Up: Mathematica Commands Previous: Mathematica Commands

Creating Lists and Defining Functions

We will be interested in constructing arrays of values that represent ``abstract'' images, abstract in the sense that they will be made within Mathematica and do not come from real digitilized images. We will use the Table command to construct arrays of values. It can be used to construct arrays of any dimension or size. To construct a list called mylist using the function f, we would use the following command:

	mylist = Table[N[f[i]],{i,imin,imax}];
The variable i is the index for the list and it runs from the values imin to imax, so the array has imax - imin + 1 entries. Note that the ; after the input statement suppresses the output. Note also that we have entered decimal values in the table by using the Mathematica function N[ ] to evaluate f.

We can use this command to produce a doubly indexed list, which we should interpret as being a two-dimensional data set obtained by sampling an image. To obtain a two-dimensional data set, we must use a function f of two variables,

	mylist = Table[N[f[i,j]],{i,imin,imax},{j,jmin,jmax}];

Let us illustrate how to use the two-dimensional version of the Table command to construct a tex2html_wrap_inline80 table representing a function on the domain tex2html_wrap_inline82 .

	mylist = Table[N[f[ 4*(i/32), 4*(j/32)]],{i,1,32},{j,1,32}];

We can use functions built up out of standard functions for the function f, for example,

	Sin[i-j] Cos[i+j]
However, it will be more interesting for us to use continuous functions, like trigonometric functions, to build up piecewise continous functions. In particular, it will be interesting to look at characteristic functions tex2html_wrap_inline86 and step functions, which are linear combinations of characteristic functions. If E is a subset of the domain, which will most often be two dimensional when we think about imaging, then tex2html_wrap_inline86 is defined by

eqnarray21

To do this in Mathematica, we need the following:

Let use the first of these to define the characteristic function of a disk of radius 2 centered at the origin.
	f[x_,y_]:= 1/; x^2 + y^2 <= 4;
	f[x_,y_]:= 0 /; x^2 + y^2 > 4;
This is relatively simple because it is defined by a single condition, the equation of the circle. If a region is defined by more than one condition, it is necessary to use && to represent a logical ``and'' and || to represent a logical ``or''. For example, to define a function that is .5 on a unit square and 0 outside the square, we could use the following.
	f[x_,y_]:=.5/; (x >= 0) && (x<=1) && (y >= 0) && (y<=1);
	f[x_,y_]:=0/; (x < 0) || (x > 1) || (y < 0) || (y > 1);
The first line would be read as f(x,y) = .5 if tex2html_wrap_inline94 and tex2html_wrap_inline96 and tex2html_wrap_inline98 and tex2html_wrap_inline100 . The second would be read as f(x,y) = 0 if x ;SPMlt; 0 or x ;SPMgt; 1 or y ;SPMlt; 0 or y ;SPMgt; 1. Notice for a point to be in the square four conditions must simultaneously be satisfied, thus the sequence of four conditions connected by ``and''. But, for a point to lie outside the square, only one of the four conditions needs to fail, thus the sequence of four conditions connected by ``or''.


next up previous
Next: Plotting Functions and Lists Up: Mathematica Commands Previous: Mathematica Commands


Fri Sep 3 15:13:30 EDT 1999