My IIT Login
IIT.EDU HOME
    Undergraduate Admission
    Graduate Admission

    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.


    Xiaoyan

    Xiaoyan Zeng
    Applied Mathematics

    The geographic distance between Hong Kong and Chicago was considerably shortened for Xiaoyan Zeng when her college adviser showed her a brochure about IIT. more...

    Spring 2012 Special Events

    2012 Karl Menger Lecture and Awards
    April 23, 2012
    IIT Main Campus

    2012 Commencement Ceremony
    May 12, 2012
    IIT Main Campus

    © 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 | Site Index