The
eval
command
Example 1
For our first example let's start with the expression
and assign it the name W.
Suppose now that you want to evaluate the expression
where x has the value 4. The quickest way to do this is to use Maple's
eval
command. Here's what it looks like:
Alternatively, you can apply the
eval
command to W.
Example 2
The
eval
command works equally well with symbolic values:
To replace x by
in the expression
execute the following line. In this case we label the result M.
And now to get Maple to "multiply out" this expression we use the
expand
command.
Example 3
The
eval
command is very versatile. You can use it to evaluate expressions involving more than one variable. Here we replace
by 7 and
y
by 12 in the expression
.
Since U has two
variables, the evaluating point then needs to be in a list, in square
brackets [ ] separated by commas. Note x=7, y=12 are enclosed by
a square bracket [ ].
> |
q := eval(U,[x=7,y=12]);
|
As a floating-point (decimal) number, we have
Example 4
You can also use the
eval
command to substitute a value into an
equation. This is the sort of thing you might want to do to test
whether a particular value "satisfies" the equation. In the next few
lines we substitute different values into the equation
. Are any of these values a solution to the equation?
Note we use "
:=
" to assign the name and just "
=
" for the equation itself.
> |
eqn := x^3-5*x^2+7*x-12=0;
|
To see if 3 is a solution for eqn, execute:
Similarly, to see if 4 is a solution for eqn, execute:
As you can see, since -9 is not equal to 0, 3 is not a solution to
, and 0 = 0 indicates that 4 is in fact a solution. Again, 5 is not a solution as
when
, which the following shows.
Exercise 2.1
Assign the name k to the expression
. Then assign the name M to the expression
.
Finally have Maple calculate
.
Note: to get Maple to multiply the expression out use the
expand
command. That is enter:
expand(3*M+6);
You will learn more about the expand command in the next subsection.
Student Workspace 2.1
Answer 2.1
Exercise 2.2
Expand
using the
expand
command.
Student Workspace 2.2
Answer 2.2
or we can do this all in one step with:
Exercise 2.3
Let
. Find
P if
x = 0.01 , a =
,
,
, and
.
Student Workspace 2.3
Answer 2.3
> |
P := a*x^3+b*x^2+c*x+d;
|
> |
eval(P,[x=0.01,a=-1/5,b=2/5,c=0,d=13/15]);
|
Exercise 2.4
Use the
eval
command to check if any of the numbers: 1,2 or 3 is a solution to the equation:
Student Workspace 2.4
Answer 2.4
> |
eqn := x^3-16*x^2+51*x-36=0;
|
Therefore
and
are solutions of the equation. (In Section 5 you will learn how to solve equations using Maple.)
The
factor
command
Example 1
Factor the expression:
Or you can do it all on one line:
Example 2
First enter in the expression
.
> |
H := 2*(x-2)*(2*x^2+5*x+2)*(x+4);
|
Expand H using the
exapand
command.
Then apply the
factor
command to the result.
Can you explain why the final result looks different than the original expression ?
Example 3
Maple can factor expressions with more than one variable. For example, the expression
, that is,
factors to
Example 4
If Maple can't factor an expression using rational numbers (i.e. integers and fractions) then it returns the input unchanged.
Example 5
The
factor
command is not limited to polynomials. It can be used to factor other forms.
Factor
.
> |
factor((sin(x))^2-(cos(x)^2));
|
Example 6
If the
factor
command is used with a rational expression such as
> |
A := (x^3-7*x^2+15*x-9)/(x^2+4*x+4);
|
the numerator and denominator are each factored, as we see from
The common factors in the expression
> |
B := (x^3-7*x^2+15*x-9)/(x^2-4*x+3);
|
are cancelled to simplify the expression, as we see from
The next example allows you to see the factored form without cancellation.
Example 7
Maple's
numer
and
denom
commands allow you to isolate either the numerator or denominator of a fraction.
For example, consider
.
> |
B := (x^3-7*x^2+15*x-9)/(x^2-4*x+3);
|
Here we use
numer
and
denom
commands to examine the factors of the numerator and denominator separately (i.e. before cancellation of common factors).
> |
factor(numer(B));
factor(denom(B));
|
Exercise 2.6
Factor the expression
.
Student Workspace
2.6
Answer
2.6
> |
factor(3*x^4-2*x^3+22*x^2-18*x-45);
|
Exercise 2.7
Factor the expression
and then use the
expand
command to check the result.
Student Workspace
2.7
Answer
2.7