Unformatted text preview: applies.
> combine(exp(x)^2*exp(y),exp); e(2 x+y) 38 • Chapter 2: Mathematics with Maple: The Basics > combine((x^a)^2, power); x(2 a) The map Command
This command is useful when working with lists, sets, or arrays. It provides a means for working with multiple solutions or for applying an operation to each element of an array. The map command applies a command to each element of a data structure or expression. While it is possible to write program structures such as loops to accomplish these tasks, you should not underestimate the convenience and power of the map command. The map command is one of the most useful commands in Maple.
> map( f, [a,b,c] ); [f(a), f(b), f(c)]
> data_list := [0, Pi/2, 3*Pi/2, 2*Pi]; data _list := [0,
> map(sin, data_list); 1 3 π, π, 2 π ] 2 2 [0, 1, −1, 0] If you give the map command more than two arguments, Maple passes the last argument(s) to the initial command.
> map( f, [a,b,c], x, y ); [f(a, x, y ), f(b, x, y ), f(c, x, y )] For example, to diﬀerentiate each item in a list with respect to x, you can use the following commands.
> fcn_list := [sin(x),ln(x),x^2]; fcn _list := [sin(x), ln(x), x2 ] 2.6 Expression Manipulation > map(Diff, fcn_list, x); • 39 [
> map(value, %); d d d sin(x), ln(x), (x2 )] dx dx dx [cos(x), 1 , 2 x] x You can also create an operation to map onto a list. For example, suppose that you want to square each element of a list. Replace each element (represented by x) with its square (x2 ).
> map(x>x^2, [1,0,1,2,3]); [1, 0, 1, 4, 9] The lhs and rhs Commands
These two commands take the lefthand side and righthand side of an expression, respectively.
> eqn1 := x+y=z+3; eqn1 := y + x = z + 3
> lhs(eqn1); y+x
> rhs(eqn1); z+3 The numer and denom Commands
These two commands take the numerator and denominator of a rational expression, respectively.
> numer(3/4); 40 • Chapter 2: Mathematics with Maple: The Basics 3
> denom(1/(1 + x)); x+1 The nops and op Commands
These two commands are useful for breaking expressions into parts and extracting subexpressions. The nops command returns the number of parts in an expression.
> nops(x^2); 2
> nops(x + y + z); 3 The op command allows you to access the parts of an expression. It returns the parts as a sequence.
> op(x^2); x, 2 You can also specify items by number or range.
> op(1, x^2); x
> op(2, x^2); 2
> op(2..2, x+y+z+w); y, z 2.6 Expression Manipulation • 41 Common Questions about Expression Manipulation
1. How do I substitute for a product of two unknowns? Use side relations to specify an identity. Substituting directly does not usually work because Maple searches for an exact match before substituting.
> expr := a^3*b^2; expr := a3 b2
> subs(a*b=5, expr); a3 b2 The subs command was unsuccessful in its attempt to substitute. Use the simplify command.
> simplify(expr, {a*b=5}); 25 a You can also use the algsubs command, which performs an algebraic substitution.
> algsubs(a*b=5, expr); 25 a 2. How do I factor ou...
View
Full
Document
This note was uploaded on 08/27/2012 for the course MATH 1100 taught by Professor Nil during the Spring '12 term at National University of Singapore.
 Spring '12
 NIL
 Math, Division

Click to edit the document details