Discrete Wavelets

003 - Some Commands

Helmut  Knaust - Department of Mathematical Sciences, University of Texas at El Paso, hknaust@utep.edu
9/13/2010; last edit 9/28/2020

Four Equal Signs

=

a=5

a

b=a

Here the variable b is assigned the value of a, namely 5, immediately. Changing the value of a will NOT affect the prior assignment of b:

b

a=6

b

:=

The next command is a delayed assignment. Every time one asks for the value of c, Mathematica will look up the current value of a.

c:=a

a

c

a=-5

c

b

==

Two equal signs ( == ) are used to compare two mathematical expressions. Mathematica will return 'True' or 'False'.

4==5

Not[4==5]

Oops :

4==4

Pi==4ArcTan[1]

2.==2

===

Pi===4ArcTan[1]

2===2.

Clear

The 'Clear' command will remove assignments for a variable :

Clear[a]

a

c

Functions

Clear[f,g]

f[x_]=x^2-1

f[5]

f[t^2]

a=4

f[a]

Plot[f[t],{t,1,5}]

f[x_,y_,z_]=x+y+z

f[1,2,3]

g[{x_,y_,z_}]=x+y+z

g[1,2,3]

g[{1,2,3}]

g1[x_]:=x[[1]]+x[[2]]+x[[3]]

g1[{1,2,3,4}]

g1[{1,2,3}]

g2[x_]:=Sum[x[[i]],{i,1,Length[x]}]

g2[{1,2,3,4}]

g2[{1}]

Length[2]

g2[1]

g3[x_]=Total[x]

g3[{1,2,3,1}]

g3[2]

The 'Function' command defines a pure (= variable-free) function.

h=Function[t,t^2-1]

h[3]

Plot[h[s],{s,-1,1}]

Below is the short form of the ' Function' command. The variable is always named '#' (or #1, #2, etc., if there is more than one); left delimiter is '(', right delimiter is '&)'.

Clear[g]

g=(2#^2-1&)

g[5]

Plot[g[x],{x,0,2}]

Map

' Map' applies a function to a list. One can fine-tune which levels the function should be applied to.

A=RandomInteger[{0,255},{4,3,3}]

Map[j,A]

Level {1} are the rows:

Map[j,A,{1}]

Level {2} are the matrix entries (here 3 - vectors):

Map[j,A,{2}]

Level {3} applies the function to the 3-vector entries :

Map[j,A,{3}]

Level 3 applies the functions to level 1, 2, and 3 :

Map[j,A,3]

A

Reverse[{1,2,3,4}]

Map[Reverse,A,{1}]

g

A
Map[g,A,{2}]

A
Map[Reverse,A,{2}]

Drop[{1,2,3},1]

k=Function[s,Drop[s,1]]

k[{1,2,3}]

A

Map[k,A,{0}]

A
Map[k,A,{1}]

A
Map[k,A,{2}]

With (...&):

A
Map[(Drop[#,1]&),A,{1}]

Flatten & Partition

Flatten removes layers of nested lists.

A

B=Flatten[A]

StandardForm[A]

Flatten[A,1]
StandardForm[Flatten[A,1]]

Partition is the command to “undo” a Flattening:

B

B1=Partition[B,3]

StandardForm[B1]

B2=Partition[B1,3]

A==B2