LearningGuide

# You can make several substitutions with one call to

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: in an expression. &gt; nops( expr ); 3 You can select, for example, the third term as follows. &gt; 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. &gt; whattype( term3 ); ∗ &gt; nops( term3 ); 3 &gt; op( term3 ); 2, cos(x)2 , sin(x) Retrieve the second factor in term3 in the following manner. &gt; factor2 := op(2, term3); factor2 := cos(x)2 It is an exponentiation. &gt; whattype( factor2 ); ^ The expression factor2 has two operands. &gt; op( factor2 ); cos(x), 2 The ﬁrst operand is a function and has only one operand. &gt; op1 := op(1, factor2); op1 := cos(x) &gt; whattype( op1 ); 192 • Chapter 6: Evaluation and Simpliﬁcation function &gt; op( op1 ); x The name x is a symbol. &gt; whattype( op(op1) ); symbol Since you did not assign a value to x, it has only one operand, namely itself. &gt; nops( x ); 1 &gt; op( x ); x You can represent the result of ﬁnding 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 &gt; op( [a,b,c] ); a, b, c &gt; 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. &gt; 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. &gt; large := z -&gt; evalb( is(z&gt;3) = true ); large := z → evalb(is(3 &lt; z ) = true ) &gt; 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. &gt; has( x*exp(cos(t^2)), t^2 ); true &gt; 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 Simpliﬁcation &gt; sol := { solve( { x^2*y^2 = b*y, x^2-y^2 = a*x }, &gt; {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. &gt; 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. &gt; type( 3+x, ‘+‘ ); true In this example, the select command passes its third argument, ‘+‘, to type. &gt; expr := ( 3+x ) * x^2 * sin( 1+sqrt(Pi) ); expr := (3 + x) x2 sin(1 + &gt; select( type, expr, ‘+‘ ); √ π) 3+x The hastype command determines if an expression contains a subexpression of a certain type. &gt; 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