SOLVING EQUATIONS WITH MAPLE Maple can be used to solve

advertisement
SOLVING EQUATIONS WITH MAPLE
Maple can be used to solve equations symbolically and numerically. The basic command used is
solve(equation, variable)
Here are two examples:
> # Example 1
In this example we will solve the equation 3x + 7 = 5 for x.
> solve(3*x+7=5,x);
> # you could express the output in the form x= by inputing
> x=solve(3*x+7=5,x);
> # you could even assign the output to the variable x by inputing
> x:=solve(3*x+7=5,x);
However, I will point out that there is a danger in creating an assignment statement like this. You
have now assigned a value to x which Maple will remember for the rest of your session. This means
if you try to use x as a variable in another expression, Maple will replace all occurrences of x with
2
− . Since I just had you assign this value to x, enter the next command to remove that assignment.
3
> unassign('x');
> # Example 2
In this next example we will solve the equation x3 + 1 = 0.
> solve(x^3+1=0,x);
Maple has returned three solutions: the single real root of -1 and the two complex roots. As you may
recall from Pre-Calculus, the polynomial x3 + 1 has the factorization x3 + 1 = ( x + 1 ) ( x2 − x + 1 ) .
The first factor produces the real root of -1. Using the quadratic formula on the other factor produces
the two complex roots.
While knowing the complex roots of a function can be very important, we do not really use them in
Calculus I. If we were looking for the critical numbers of a function, we would want only the real
roots of the derivative. Later in this worksheet I will show you how to limit the solutions to the real
numbers.
By default, Maple operates over the complex number field, which means it looks for both the complex
roots and the real roots and it evaluates functions over the complex domain. This can result in
answers in a form you might not expect.
If you graph the cube root function on you calculator, you'll get a graph that looks something like this:
For example, if you graph the cube root function using Maple, here's what you'll get:
> # Example 3
> plot(x^(1/3),x=-8..8);
Because the first cube root of a negative number is complex, and because Maple evaluates root
functions by looking for the primary root, Maple does not plot any values for the cube root function
where x is negative.
What does all this mean for you? If you know you will be working in an environment where you want
to consider functions over the real domain only, you can issue a special command at the start of your
session which tells Maple to work only with real numbers. The command is
with(RealDomain):
Enter that command and then re-do Examples 2 and 3. Compare the "real" output with the "complex"
output.
> with(RealDomain): # you may safely ignore the dire warning!
> # Example 2 revisited
> solve(x^3+1=0,x);
> # Example 3 revisited
> plot(x^(1/3),x=-8..8);
> # That's more like it!
Should you wish to re-enter the complex domain, entering the command restart will take you back to
the default set-up; using restart will also wipe out any assignments you have made.
AN ALTERNATIVE TO solve
The fsolve command can be used in place of solve when you want a decimal approximation. solve
will return the exact solution in either rational or root form; fsolve will give you the decimal form of
the solution.
> # Example 4
> solve(x^2-5=0,x); # produces the two solutions using square roots
> fsolve(x^2-5=0,x); # produces the decimal approximations of the
two solutions
An alternative to using fsolve is to first use the solve command, followed by evalf
> solve(x^2-5=0,x);
> evalf(%);
The solve command can be "nested" inside the evalf command, so that only one line of input is
entered:
> evalf(solve(x^2-5=0,x));
There is one advantage to using this procedure, rather than fsolve. You can include an optional
argument in the evalf command which specifies the number of digits in the answer. For example, to
give the answer to 20 digits, enter
> evalf(solve(x^2-5=0,x),20);
Note: 20 digits, means 19 decimal places in this particular example. So, if you want three decimal
places,
> evalf(solve(x^2-5=0,x),4);
FINDING CRITICAL NUMBERS
Now that you know how to solve equations using Maple, let's put it to work to find critical numbers.
Remember: the critical numbers of a function are the numbers in the domain of the function for which
either the derivative is zero or for which the derivative does not exist.
Before we look at an example, I want to introduce three new Maple commands: root, denom and
numer
The Maple function root provides an alternative way to define a root function and it works
particularly well when doing calculations over the real domain. The syntax for this command is
root(x, n)
where x is the independent variable and n is the index of the root. Thus, you would enter root(x, 2)
for a square root, root(x, 3) for a cube root, etc. The root command can be used with other operations
and functions.
When working with expressions that have a numerator and denominator, you can use the commands
denom and numer to extract the numerator and denominator as separate expressions.
> # Example 5 Using denom and numer
> f:=(x^2-4)/(x^3-10);
> denom(f);
> numer(f);
Want to find the values of x for which the denominator = 0?
> solve(denom(f)=0,x);
For what values of x for will the numerator = 0?
> solve(numer(f)=0,x);
> # Example 6 Finding Critical Numbers
First, the function.
> f:=x^4*(x-2)^3*(x+1)^2;
Next, find the derivative.
> g:=diff(f,x);
There's no need to simplify - just set the derivative equal to zero and solve.
> solve(g=0,x);
Looks like 5 distinct critical numbers (ignore multiplicities). It's worthwhile taking a look at a
factored form of the derivative
> factor(g);
The critical numbers of 0, -1 and 2 are easy to spot. Working by hand, you would have to use the
quadratic formula to find the roots of the factor 9 x2 − 5 x − 8
> # Example 6 Finding Critical Numbers
The function
> f:=(x^2-1)/(40*x^3+x+1);
> g:=diff(f,x);
> simplify(g);
> solve(numer(g)=0,x); # hold onto your hats!
> evalf(%);
> solve(denom(g)-0,x); # keep holding onto your hats!
> evalf(%);
>
What it all boils down to: three critical numbers, approximately 1.75, -1.73 and -0.26. But think of
how much fun you'd have had trying to find them by hand!
A FINAL COMMENT: If you want to see the derivative simplified or factored, you can combine
the diff command with either the factor command or the simplify command.
> simplify(diff(f,x));
> f:=(x^3-5*x)^4*(x^5-8)^10;
> factor(diff(f,x));
>
Download