My IIT Login
    Inquire

    Examples of assigning variables BADLY in Maple

    Never use a typical variable name (like x, y, z, i, j, k) on the left side of an assignment, and never put a number (3, -1, Pi, etc.) on the right side of an assignment.

    For example, these are all BAD:

    > x := t + 3*sin(t);

    > fibonac := 1;

    > x := 3;

    But why would anyone ever do something like that?

    How it typically happens


    The instructions say something like, "Define f to be the function Sin(x*Pi) - 5, then compute f(3)."

    A correct but VERY BAD way to get the answer:
    > f := x -> sin(x*Pi) - 5;
    > x := 3;
    > f(x);

    The problem is that after you run "x := 3;", Maple will now always* think that an "x" is the constant "3". For example, you won't be able to plot a graph over the interval [0,10] on the x-axis, like this:
    > plot(f(x), x=0..10);
    because Maple thinks you mean this:
    > plot(sin(3*Pi)-5, 3=0..10);
    which is nonsense without the variable "x".

    Why it happens: A brief introduction to the Maple kernel


    You can think of Maple's kernel as being the internal part that keeps track of function names, variable names, their current values, and such. The key facts we should observe here are:

    1. No matter how many worksheets you have open, they all use the same kernel, and
    2. The kernel will remember all names and values until you exit Maple, unless you specifically "unassign" something.

    The second property is what causes the problem in the "How it typically happens" example above.




    * Well, not always, but until you either (1) quit Maple, (2) run "unassign('x');", or (3) run a "restart;" command, which clears all variable names (and all other labels, too). But it's simpler to avoid creating the problem in the first place.


    Fall Semester Welcome Reception
    08.20.08
    12:00-2:00 pm

    First Day of Fall Semester Classes
    08.21.08

    Upcoming Colloquia & Seminars

    Stephen Wiggins
    08.25.08
    4:40 pm
    E1 106

    Ali Cinar
    09.08.08
    4:40 pm
    E1 106

    © Illinois Institute of Technology
    Applied Mathematics Office, Engineering 1 Building 10 West 32nd Street, Chicago, IL 60616, Tel 312.567.8980, Fax 312.567.3135
    Undergraduate Admission: 800.448.2329 || Graduate Admission: 312.567.3020   Emergency Information