next up previous
Next: Roles of Different Up: COMMANDS FOR MATH Previous: Long Command Lines

Manipulating Expressions, Extracting Parts of Expressions

Maple has many commands to manipulate algebraic expressions. A few of them are collect, expand, simplify, combine - use the ? to find out more about them. To extract parts of an expression two useful commands are op and nops. Briefly, nops(a) gives the number of operands (i.e. pieces) in expression a, while op(3,a) returns the third operand (i.e. piece) of the expression a. As an example, we show how to extract all the terms containing in an expression. Try

a := (x^2 + y*sin(3*x))*x*y + 5*(y^2+x^2)*sin(3*x) + y*sin(x)^3 ;
b := collect(a, sin(3*x));   collect coeff of powers of sin(3x)
nops(b);   number of operands/pieces in b
c := op(1,b);  get first part of b - contains the terms with sin(3x)   
nops(c);       number of pieces in c - want coefficient of sin(3x)
op(1,c);       gives coeff of sin(3x)



Peter Monk
Tue Aug 29 14:41:29 EDT 1995