# It's always a good idea to include the restart command at the # beginning of a Maple worksheet. This clears the memory. > restart: # Quadratic equations # There are a number of ways to analyze polynomials in Maple. A quick # way to determine the roots of your polynomial is via the solve command: > solve(3*x^2-12*x+7=0,x); # The first argument to this function is the equation you wish to solve, # and the second argument is the variable for which you'd like to solve # it. In the case of a one variable function such as this, the second # argument is not actually necessary. > solve(3*x^2-12*x+7=0); # However, consider the following: > solve(a*x^2+b*x+c=0); # In this case, there is more than one unknown, and Maple does not know # which you'd like to solve for. Therefore it is necessary to include the # second argument, x;. > solve(a*x^2+b*x+c=0,x): # Notice a few things about the Maple code above. First of all, when you # want to multiply two quantities, such as 3;and x;, you must include an # asterisk *. You cannot simply write 3*x;. Moreover, you must end your # commands with either a colon or a semicolon if you want them to execute. # Ending with a colon suppresses the output; if you want to see the # output, end your command with a semicolon. You can see this for yourself # by changing any of the above semicolons to colons. # # If you want to execute multiple commands at once, press shift + return # instead of simply return at the end of a line. Once you are ready to # execute a block of code, press return by itself. The following code # factors a quadratic polynomial and then reconstructs the original # polynomial from its factors. The colon followed by an equals sign # (:=) # assigns what is on the right of the symbol to the variable name on the # left. More details about the syntax used below can be found in Maple Lab # 1. # > eq:=3*x^2-12*x+7; > ans:=[solve(eq=0,x)]; > eq1:=3*(x-ans[1])*(x-ans[2])=0; > expand(eq1); # # Functions and plotting # # Let's start with a very simple example. We'll plot the function f(x) = # sin(x). > plot(sin(x)); # If you would like to specify the domain of your plot, you can add this # as the second argument to the plot command. Let's say that you'd like to # plot f(x) = sin(x) on the interval [-Pi, Pi];. # Then you write > plot(sin(x),x=-Pi..Pi); # Now let's define and plot the function g(y) = 1/(2-y); on the interval # -10, 2;. To define g; as the function that maps y; to 1/(2-y) > g:=y->1/(2-y): a:=-10: b:=2: # (The combination - + > (minus sign + right pointy bracket) is used to # create an arrow.) # We can plot this just as we did above for sin(x) > plot(g(y),y=a..b); # Defining a function in this way allows us to evaluate it at specific # points: > g(-3); > g(x); # If you ever have a question about a Maple command, simply type a # question mark followed by the command name, and a help page for the # command will pop up. For example, > ?plot # # Derivatives # # Define > f:=x->sin(x); # To differentiate this function with respect to x;, type > diff(f(x),x); # As with the solve command above, it is not necessary to include the # second argument x; when you are differentiating a function of a single # variable, but it doesn't hurt to include it either. # # Now let's try something a little more complicated, a function of two # independent variables such as # h(x, y) = x^2*exp(-3*x*y)+sin(x)*cos(2*y)-y/(1-x)^4; # We first define h; as follows: > h:=(x,y)->x^2*exp(-3*x*y) + sin(x)*cos(2*y) - y/(1-x)^4; # To compute the partial derivatives with respect to x; and y; # respectively, we write > dhdx:=(x,y)->diff(h(x,y),x); > dhdx(x,y); # and > dhdy:=(x,y)->diff(h(x,y),y); > dhdy(x,y); # # Vector partials and the Jacobian matrix # # In order to compute vector partials in Maple, it is necessary to first # load the VectorCalculus package. > with(VectorCalculus): # Next, we define a vector as follows: > u:=Vector([t1-t2^2,5-t1*t2,t1^3+7*t2-6]); # If you want to use specific components of the vector, say the second # and third, then type > v:=u[2..3]; # To differentiate with respect to one of the variables in your vector, # proceed as you would to differentiate a function such as we've already # worked with above. For instance, to differentiate u; with respect to # variable t1, enter > diff(u,t1); # Note that this only works because we've loaded the VectorCalculus package. # # Now let's consider the system of equations # z[1] = 2*x-y^2; # z[2] = y+x^3*y-1; # # To compute the Jacobian, we first define two equations, > z1:=2*x-y^2; > z2:=y+x^3*y-1; # and then enter > J:=Jacobian([z1,z2],[x,y]); # Note that the VectorCalculus package is also necessary to use the # Jacobian command. In order to compute the determinant, we'll need the # LinearAlgebra package. We can load it as we did the VectorCalculus # package, by typing) # with(LinearAlgebra): or we can simply write > detJ:=LinearAlgebra[Determinant](J); # In order to evaluate the Jacobian or its determinant at a particular # point c, d;, write > subs(x=c,y=d,J); > subs(x=c,y=d,detJ); # # Additional topics # # The above should be all that you'll need to complete Maple lab 1. # However, there are a few other commands that will be useful to know. # # Integration # # To evaluate an indefinite integral, type > int(x*ln(x),x); # Limits of integration are included by changing the above to > int(x*ln(x),x=2..5); # If you want a number for an answer, just include a decimal point # somewhere in the above code (I did this by multiplying the function by # 1). > int(1.*x*ln(x),x=2..5); # Solving differential equations # Let's say we want to solve the differential equation dy/dx = y(1-y);. # We first input the ODE as follows: > ode1:=diff(y(x),x)=y(x)*(1-y(x)); # and then use the # dsolve command to solve it: > dsolve(ode1); # Now suppose we want to solve the initial value problem diff(xy(x), # x)+2*y = 6*x^2*sqrt(y), y(1) = 2.; Then we write > ode2:=x*diff(y(x),x)+2*y(x)=6*x^2*sqrt(y(x)); > dsolve({ode2,y(1)=2}); # Don't forget the curly braces inside of the parenthesis when including # an initial condition. # === end of file ====