Calculus B - Lab 2
TA: Patrick C. Rowe
| > | restart; |
| > |
limit
Maple has a very simple command to take limits: limit. The syntax is limit(expr,x=a,dir) where expr is the expression to be evaluated, a is the value to be approached and dir is the direction approached from. dir is optional and when it's left out, the command returns the usual limit evaluated from both directions.
Examples:
| > | limit(sin(x),x=0); |
| > | limit(1/x,x=0,right); |
| > | limit(1/x,x=0,left); |
| > | limit(sin(x)/x,x=0); |
Notice the last limit found. This requires L'Hopital's rule to be evaluated. In the method which Maple uses to calculate limits, the rule is effectively invoked automatically when needed.
| > |
diff
Taking derivatives in Maple is also simple. The diff command is used. The syntax is diff(expr,var) where expr is the expression for which we wish to know the derivative and var is the variable to take the derivative with respect to.
Example:
| > | g:=x^2+sin(x); |
| > | diff(g,x); |
We can store the result in another variable so that we can perform further calculations with it.
| > | g1:=diff(g,x); |
Note that the diff command is designed to work on expressions. If we want to take the derivative of a function, we must plug in the variable first. Look at the following example.
| > | f:=x->ln(x)+x^3; |
| > | diff(f,x); |
In the command above, we get a result that is not very useful and may seem strange to us. But remember that the function f is not actually associated with the variable x. Rather, f is simply a rule apply to a number, or a variable. By entering f(x), we make an expression from the function. Then the diff command can operate on it.
| > | diff(f(x),x); |
solve, fsolve
The solve and fsolve commands are used to find the solutions to equations, systems of equations, and inequalities. solve finds symbolic solutions and can be used to find one variable in terms of another. fsolve finds numeric solutions in decimal format.
The syntax for the solve command is solve(equations,variables). The variables option can be left blank, in which case a system of solutions is returned. It is usually better to specify which variable you want solved for so that there is no confusion in the interpretation of an answer.
Examples
| > | f:=x^3-6*x+9; |
| > | solve(f=0,x); |
Notice that the solution includes complex roots.
The above could have been entered differently. The zero does not need to be specified. If an expression is not set equal to something, solve assumes it is equal to zero.
| > | solve(f,x); |
Also, the entire equation could be stored in f. Suppose we want to do this and, instead of zero, set the equation equal to 4. We could enter:
| > | f:=x^3-6*x+9=4; |
| > | solve(f,x); |
Now suppose we have multiple variables.
| > | f:=x^3*y^2+6*x*y+9=4; |
| > | solve(f,y); |
If we don't specify that we want y in terms of x, the results may be more than what we expected.
| > | solve(f); |
This may not seem to bad, but it can make the solutions difficult to reference later on which we may want to do when writing code in Maple.
When asked to solve polynomials higher than degree 4, Maple will return the answer using RootOf. This simply reflects the fact that there is no formula to find these solutions. In these cases, it may be preferable to use fsolve and work with the numeric solution.
| > | f:=x^7+8*x^6-9*x^5-4*x^2+x-2; |
| > | solve(f=0,x); |
| > | fsolve(f=0,x); |
The solution returned by fsolve only has three roots. But the polynomial is 7th degree, therefore we know that 7 solutions exist. What happened to the 4 others?
They are complex. By default, fsolve only returns real roots to a polynomial equation. If complex roots are desired, we must add the option complex to the command. Before looking at this let's look at the syntax for fsolve.
The syntax is fsolve(equations, variables, complex, fulldigits, interval, starting_values, options). Everything except the equations are optional, so we won't examine all of them.
equations works as it does in solve. The variables parameter is less important here as it is usually implied by the equations, however, for later reference it may be better to specify. complex simply states whether complex solutions are to be included. By default they aren't. fulldigits is for higher computations and we won't be using it.
interval is important. This is used to specify the interval of the solution for which you are searching. Usually this is found by graphing the expression first.
starting_values can be used to enter an initial guess. We won't use it much. options is used for yet finer tuning of the command.
| > | fsolve(f=0,x,complex); |
| > | plot(f,x=-10..2,y=-10..10); |
From the graph, we see that there is a solution between -10 and -8. (We already knew this, but this is just for demonstration.) To select only this solution to be found by fsolve, we specify the interval to be searched.
| > | fsolve(f,x=-10..-8); |
This is especially helpful when solving equations which are not polynomials. For these equations, fsolve does not return all the real solutions by default. It usually returns the first solution found, which may not be the one desired. Suppose, for instance, we want the first positive root of the following.
| > | f:=sin(x)-cos(x); |
| > | fsolve(f); |
Obviously, this is not the answer. However, by graphing, we can locate the interval of the solution and use it to find the result.
| > | plot(f); |
| > | fsolve(f,x=0..1); |
int
int is Maples command for integration. It's use and syntax is very simple. It can be used to perform indefinite or definite integration.
The syntax is int(expression, variable) for indefinite integration or int(expression, interval) for definite integration.
Examples
| > | int(sin(x),x); |
| > | int(sin(x),x=0..Pi); |
Notice that the indefinite form of the command does not add on the constant of integration.
Inert Commands, % and evalf
Usually we resort to using a computer to perform calculations for two reasons. Either the calculation is tediously repetitive, or lengthy and complicated (or both). When the second is the case, it can be helpful to verify that you have entered the command correctly before evaluating it for an answer. To accomodate this, many Maple commands have an 'inert' form which can be entered first and then evaluated using the evalf commands.
Normally, the inert form is accessed by typing the command with an initial capital letter. The commands limit, diff, and int each have an inert form.
Once the entered command is verified to be correct, to evaluate the command we type evalf(%). The % is a Maple shorthand which refers to the most recent output. evalf stands for evaluate using floating point arithmetic.
Examples
| > | Limit(sqrt(x^2+2)/sqrt(2*x^2+1),x=infinity); |
| > | evalf(%); |
The other commands work in a similar fashion.
Exercises
Section 4.4 # 66 and # 68
Section 4.8 Use solve or fsolve on 13,14,23-28
Section 6.1 35-58 (Use fsolve to find the exact limits of integration)
| > |