Solutions

The Plot function might appear a bit problematic sometimes. It is due to the fact that it evaluates its arguments in a non-standard way. If everything should be OK, but Plot still complains, try using the function Evaluate. This might happen when you try to plot a table of some sort.

In[1]:=

(*1*)A = Table[Series[Cos[x], {x, 0, i}], {i, 2, 30, 2}]//Normal ; Plot[Evaluate[Prepend[A, Cos[x]]], {x, -5Pi, 5Pi}, PlotStyleTable[Hue[i/30], {i, 2, 30, 2}]]

[Graphics:../HTMLFiles/ex05_solutions_6.gif]

Out[2]=

⁃Graphics⁃

The criterion for the Select function is conveniently presented in the form of a pure function. The #-symbol stands for the argument of the pure function, and the &-sign barely tells Mathematica that we're dealing with a pure function. The selection of all sixes from a random table is of course something bloody stupid.

In[3]:=

(*2*)Table[Random[Integer, {1, 6}], {i, 10}] Select[%, #6&] Length[%]

Out[3]=

{1, 4, 3, 4, 5, 1, 1, 2, 6, 3}

Out[4]=

{6}

Out[5]=

1

See the help file for Cases for more information.

In[6]:=

(*3*)thelist = {x, x^2, Exp[y], x + y, 5x, x^(x^x), Sin[x], Log[x] + Cos[x]} Cases[thelist, a_^b_] Cases[thelist, a_^b_, {1, 2}]

Out[6]=

{x, x^2, ^y, x + y, 5 x, x^x^x, Sin[x], Cos[x] + Log[x]}

Out[7]=

{x^2, ^y, x^x^x}

Out[8]=

{x^2, ^y, x^x, x^x^x}


Created by Mathematica  (April 10, 2007) Valid XHTML 1.1!