Calculus B - Lab 6 

TA: Patrick C. Rowe 

 

In this lab we will learn some commands to manipulate algebraic expressions. 

'factor' and 'expand' 

These commands are opposites in a sense, so we'll learn about them at the same time. 

 

First we'll look at factor. 

 

The syntax of the factor command is factor(expr,K). K is optional and is used to give an option to factor with respect to, which can be either a number or a field. If K is not typed in, then Maple tries to infer a correct value from the coeffiecents in the expressionl. This works well for most purposes. 

 

Examples
 

> f:=3*x^2-x*exp(1)+3*Pi*x-Pi*exp(1);
 

Typesetting:-mprintslash([`:=`(f, `+`(`*`(3, `*`(`^`(x, 2))), `-`(`*`(x, `*`(exp(1)))), `*`(3, `*`(Pi, `*`(x))), `-`(`*`(Pi, `*`(exp(1))))))], [`+`(`*`(3, `*`(`^`(x, 2))), `-`(`*`(x, `*`(exp(1)))), `*... (1.1)
 

> factor(f);
 

`*`(`+`(`*`(3, `*`(x)), `-`(exp(1))), `*`(`+`(x, Pi))) (1.2)
 

> f:=x^3+5;
 

Typesetting:-mprintslash([`:=`(f, `+`(`*`(`^`(x, 3)), 5))], [`+`(`*`(`^`(x, 3)), 5)]) (1.3)
 

> factor(f,5^(1/3));
 

`*`(`+`(`*`(`^`(x, 2)), `-`(`*`(x, `*`(`^`(5, `/`(1, 3))))), `*`(`^`(5, `/`(2, 3)))), `*`(`+`(x, `*`(`^`(5, `/`(1, 3)))))) (1.4)
 

Note how in the last example, a value for K was specified. The result reflects this specified value. Although this example is somewhat contrived, it is easy to imagine that there are situations where this functionality could be useful. 

 

In the next example, we see that both the numerator and denominator of rational expressions are factored. 

> f:=(x^2+2*x+1)/(x^2-1);
 

Typesetting:-mprintslash([`:=`(f, `/`(`*`(`+`(`*`(`^`(x, 2)), `*`(2, `*`(x)), 1)), `*`(`+`(`*`(`^`(x, 2)), `-`(1)))))], [`/`(`*`(`+`(`*`(`^`(x, 2)), `*`(2, `*`(x)), 1)), `*`(`+`(`*`(`^`(x, 2)), `-`(1)... (1.5)
 

> factor(f);
 

`/`(`*`(`+`(x, 1)), `*`(`+`(x, `-`(1)))) (1.6)
 

Now we'll look at expand. 

 

This function expands factors, trig functions, logarithms, etc. It is very powerful and easy to use. The syntax is expand(expr). (See Maple help for additional functionality.) 

 

Examples 

> expand((x+1)*(x-4));
 

`+`(`*`(`^`(x, 2)), `-`(`*`(3, `*`(x))), `-`(4)) (1.7)
 

> expand(sin(2*x+3*y));
 

`+`(`*`(8, `*`(sin(x), `*`(cos(x), `*`(`^`(cos(y), 3))))), `-`(`*`(6, `*`(sin(x), `*`(cos(x), `*`(cos(y)))))), `*`(8, `*`(`^`(cos(x), 2), `*`(sin(y), `*`(`^`(cos(y), 2))))), `-`(`*`(2, `*`(`^`(cos(x),...
`+`(`*`(8, `*`(sin(x), `*`(cos(x), `*`(`^`(cos(y), 3))))), `-`(`*`(6, `*`(sin(x), `*`(cos(x), `*`(cos(y)))))), `*`(8, `*`(`^`(cos(x), 2), `*`(sin(y), `*`(`^`(cos(y), 2))))), `-`(`*`(2, `*`(`^`(cos(x),...
(1.8)
 

> expand(ln(2*x));
 

`+`(ln(2), ln(x)) (1.9)
 

'simplify' and 'collect' 

The simplify command applies the basic rules of mathematics to produce a simpler expression. The syntax is simplify(expr). 

 

Examples 

> simplify(sin(x)^2+x+cos(x)^2+3*x);
 

`+`(`*`(4, `*`(x)), 1) (2.1)
 

> simplify(ln(2*x));
 

`+`(ln(2), ln(x)) (2.2)
 

The collect command collects together like powers of the specified 'variable'. The variable can be another expression. The syntax is collect(expr,x), where x is the expression to collect on. 

 

Examples 

> f:=2*ln(x)+x*ln(x)-x;
 

Typesetting:-mprintslash([`:=`(f, `+`(`*`(2, `*`(ln(x))), `*`(x, `*`(ln(x))), `-`(x)))], [`+`(`*`(2, `*`(ln(x))), `*`(x, `*`(ln(x))), `-`(x))]) (2.3)
 

> collect(f,x);
 

`+`(`*`(`+`(ln(x), `-`(1)), `*`(x)), `*`(2, `*`(ln(x)))) (2.4)
 

> collect(f,ln(x));
 

`+`(`*`(`+`(2, x), `*`(ln(x))), `-`(x)) (2.5)
 

 

>