Go to CCP Homepage

Go to Materials Page

Go to Linear Algebra Materials

Go to Table of Contents

Go Back One Page

Go Forward One Page

Mathematica Tutor

Part 7: Functions

  1. Next we define a function to assign the value 10 sin x to each x. Enter
    x=.
    f[x_]:=10*Sin[x]

    and then
    f[1]
    (Note the "_" (underscore) character which appears only on the left of the second command, and the extra colon.) You may be surprised to see

    10 Sin[1]

    rather than a decimal approximation. To obtain a decimal approximation, enter
    N[10*Sin[1]]
    The command "N" stands for "numerical value."

You should notice two important things here:

  1. To be sure that the action of N is clear, enter
    103751/2053
    and then
    N[103751/2053]

  2. An alternate way of forcing Mathematica to return a decimal approximation to f[1] is to enter
    f[1.0]

  3. Note that Mathematica distinguishes between a function and an expression. Enter
    g[x]=10*Sin[x]
    Then enter
    g[1]
    followed by
    g[x]
    The symbols g[x] stand for the expression, not the function. Try the same thing with g[x]:=10*Sin[x]
    (Colon, but no underscore.) You should get almost the same results. Leaving out the underscore when you define a function is a common source of problems when using Mathematica.

  4. Let's evaluate f at pi/6. First, we need the value of pi. Enter
    Pi
    Alter this line to read
    N[Pi]

    Now find a decimal approximation to f(pi/6).

  5. Find a decimal approximation to each of the following: f(2) and f(pi/3).

Go to CCP Homepage

Go to Materials Page

Go to Linear Algebra Materials

Go to Table of Contents

Go Back One Page

Go Forward One Page


modules at math.duke.edu

Copyright CCP and the author(s), 1998, 1999, 2000