You can make several substitutions with one call to

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: in an expression. > nops( expr ); 3 You can select, for example, the third term as follows. > term3 := op(3, expr); 6.3 Structural Manipulations • 191 term3 := 2 cos(x)2 sin(x) The expression term3 is a product of three factors. > whattype( term3 ); ∗ > nops( term3 ); 3 > op( term3 ); 2, cos(x)2 , sin(x) Retrieve the second factor in term3 in the following manner. > factor2 := op(2, term3); factor2 := cos(x)2 It is an exponentiation. > whattype( factor2 ); ^ The expression factor2 has two operands. > op( factor2 ); cos(x), 2 The first operand is a function and has only one operand. > op1 := op(1, factor2); op1 := cos(x) > whattype( op1 ); 192 • Chapter 6: Evaluation and Simplification function > op( op1 ); x The name x is a symbol. > whattype( op(op1) ); symbol Since you did not assign a value to x, it has only one operand, namely itself. > nops( x ); 1 > op( x ); x You can represent the result of finding the operands of the operands of an expression as a picture called an expression tree . The following is an expression tree for expr. + 3 * sin x sin x cos x ^ 2 2 The operands of a list or set are the elements. 6.3 Structural Manipulations • 193 > op( [a,b,c] ); a, b, c > op( {d,e,f} ); e, d, f This section (page 180) describes how the map command applies a function to all the elements of a list or set. The functionality of map extends to general expressions. > map( f, x^2 ); f(x)f(2) The select and remove commands, described in this section (pages 182– 184) also work on general expressions. > large := z -> evalb( is(z>3) = true ); large := z → evalb(is(3 < z ) = true ) > remove( large, 5+8*sin(x) - exp(9) ); 8 sin(x) − e9 Maple has many commands that can be used as the boolean function in a call to select or remove. The has command determines whether an expression contains a certain subexpression. > has( x*exp(cos(t^2)), t^2 ); true > has( x*exp(cos(t^2)), cos ); true Some of the solutions to the following set of equations contain RootOfs. 194 • Chapter 6: Evaluation and Simplification > sol := { solve( { x^2*y^2 = b*y, x^2-y^2 = a*x }, > {x,y} ) }; sol := {{y = 0, x = 0}, {y = 0, x = a}, { x = RootOf(_Z 6 − b2 − a _Z 5 ), b }} y= 6 RootOf(_Z − b2 − a _Z 5 )2 To select solutions, use select and has. > select( has, sol, RootOf ); {{x = RootOf(_Z 6 − b2 − a _Z 5 ), b y= }} 6 RootOf(_Z − b2 − a _Z 5 )2 You can also select or remove subexpressions by type. The type command determines if an expression is of a certain type. > type( 3+x, ‘+‘ ); true In this example, the select command passes its third argument, ‘+‘, to type. > expr := ( 3+x ) * x^2 * sin( 1+sqrt(Pi) ); expr := (3 + x) x2 sin(1 + > select( type, expr, ‘+‘ ); √ π) 3+x The hastype command determines if an expression contains a subexpression of a certain type. > hastype( sin( 1+sqrt(Pi) ), ‘+‘ ); true 6.3 Structural Manipulations • 195 Use the combination select(h...
View Full Document

Ask a homework question - tutors are online