Supplement for Lab 1: Maple Basics The first thing you need to grasp is the notion of a Maple session and the user interface called a Maple worksheet (saved as a .mw or .mws file e.g. supplement1.mw). Make sure that you understand what Maple is doing in each line of the following worksheet. The syntax is particularly important to notice, especially as you begin to write your own code. It is good programming practice to begin a Maple worksheet with a restart command serving both as a pointer and as a mechanism to clear all the variables: restart; It just clears the program's memory so that you start with a clean slate. Let us start by illustrating some simple things that Maple can do. It can solve equations: solve (a*x^2 + b*x + c = 0, x); Of course, you could solve a quadratic equation yourself! But how about a cubic equation? solve (3*x^3 - 7*x^2 + 15*x - 10 = 0, x); Notice that Maple solves equations exactly whenever possible. That means expressions end to get fairly lengthy and not particularly transparent. Fortunately, it has a convenient numerical feature which gives simple floating-point (decimal) numbers: evalf(%); (The % sign stands for the most recent expression that Maple evaluated.) The solve function can also handle systems of equations: solve( {x - y = a, 2*x + 3*y = b}, [x,y] ); Beware that variables in Maple can be more than one letter long, so for example, if you try to define kinetic energy as: K := mv^2/2; It looks ok, but if you try to substitute m = 1 and v = 2 you get: subs({m=1,v=1},K); You just get the original (symbolic) equation back. This is because Maple thinks you have a variable called "mv" that is squared. Instead, you should define kinetic energy as: K := m*v^2/2; Notice that in this case, it is clear that we have "m" TIMES "v". If you have a keen eye, you will notice the small space between the "m" and "v" indicating that they are seperate variables, now the substitution should work: subs({m=1,v=1},K); Maple can also do calculus: if we define f to be f := log(1/x); then its derivative is g := diff(f,x); and its integral is h := int(f,x); This example was chosen so that you could have Maple do an elementary integral (albeit a slightly tricky one). Note that "f" here is a function, but it is not defined in a way where you can call it with varying values of "x". To create a function callable as f(x) such that f(3) evaluates f(x) when x=3, you have to define the function in the following form: QyQ+SSJmRzYiZio2I0kieEdGJUYlNiRJKW9wZXJhdG9yR0YlSSZhcnJvd0dGJUYlLCgqJDkkIiIkIiIiRi5GLyEiI0YwRiVGJUYlRjA= Then you you can plug in any value you like for x: f(3); f(y); f(r+2*s); Other useful operations or functions include simplify and expand: expand(%); simplify(sin(theta)^2 + cos(theta)^2); simplify((x^2-x-6)/(x^3+19*x^2+19*x-255)); Finally, Maple can also plot things: plot(h,x=0.01..10); plot(sin(x)/x,x=-10..10); plot({cos(x),1-x^2/2+x^4/24},x=-3..3); Here are a couple of other things it is useful to know. Let us review with a couple of miscellaneous notes: It is a good idea to make ``restart'' the very first command in every Maple session. This command clears out the memory and gives you a clean slate. A command usually ends with a semicolon. If you prefer, you can end a command with a colon. If you do, Maple will evaluate the command, but it will not print the result on the screen. That is useful if the result of a command is very long and/or uninteresting. The % sign stands for the result of the most recent calculation. Remember that you must type :=, not just =, to assign a value to a variable. If you say ``x:=3'', then you're telling Maple that the value of the variable x is 3. Just saying ``x=3'' will not do that. Perhaps the most useful thing of all: you can get help on any command by typing a question mark, followed by the name of the command. Try typing ?expand , for instance. Finally, to end a Maple session, you type ``quit;'' and the window closes (or you can also just select "quit" from the File menu). If you want to save the worksheet before leaving, use the drop-down menu clicking the mouse pointer on file and dragging down to ``save'' or ``save as'' to accomplish this.