Unformatted text preview: dentiﬁes them.
> expr := a * b * c * a^b; expr := a b c ab
> subs( a*b=3, expr ); a b c ab 198 • Chapter 6: Evaluation and Simpliﬁcation The expr expression is a product of four factors.
> op( expr ); a, b, c, ab The product a*b is not a factor in expr. You can make the substitution a*b=3 in three ways: solve the subexpression for one of the variables,
> subs( a=3/b, expr ); 3 3 c ( )b b use a side relation to simplify,
> simplify( expr, { a*b=3 } ); 3 c ab or use the algsubs command, which performs algebraic substitutions.
> algsubs( a*b=3, expr); 3 c ab Note that in the ﬁrst case all occurrences of a have been replaced by 3/b. Whereas, in the second and third cases both variables a and b remain in the result. You can make several substitutions with one call to subs.
> expr := z * sin( x^2 ) + w; expr := z sin(x2 ) + w
> subs( x=sqrt(z), w=Pi, expr ); z sin(z ) + π The subs command makes the substitutions from left to right.
> subs( z=x, x=sqrt(z), expr ); 6.3 Structural Manipulations • 199 √ z sin(z ) + w If you give a set or list of substitutions, subs makes those substitutions simultaneously.
> subs( { x=sqrt(Pi), z=3 }, expr ); 3 sin(π ) + w Note that in general you must explicitly evaluate the result of a call to subs.
> eval( % ); w Use the subsop command to substitute for a speciﬁc operand of an expression.
> expr := 5^x; expr := 5x
> op( expr ); 5, x
> subsop( 1=t, expr ); tx The zeroth operand of a function is typically the name of the function.
> expr := cos(x); expr := cos(x)
> subsop( 0=sin, expr ); sin(x) 200 • Chapter 6: Evaluation and Simpliﬁcation For information about the operands of an expression, see this section, pages 188–193. Changing the Type of an Expression
To convert an expression to another type, use the convert command. Consider the Taylor series for sin(x).
> f := sin(x); f := sin(x)
> t := taylor( f, x=0 ); t := x − 15 13 x+ x + O(x6 ) 6 120 For example, you cannot plot a series, you must use convert(..., polynom) to convert it into a polynomial approximation ﬁrst.
> p := convert( t, polynom ); p := x − 15 13 x+ x 6 120 Similarly, the title of a plot must be a string, not a general expression. You can use convert(..., string) to convert an expression to a string.
> p_txt := convert( p, string ); p _txt := “x1/6*x^3+1/120*x^ 5” > plot( p, x=4..4, title=p_txt );
x–1/6*x^3+1/120*x^5 1.5 1 0.5 –4 –3 –2 –1 0 –0.5 –1 –1.5 1 2 x 3 4 6.3 Structural Manipulations • 201 The cat command concatenates all its arguments to create a new string.
> ttl := cat( convert( f, string ), > " and its Taylor approximation ", > p_txt ); ttl := “sin(x) and its Taylor approximation x1/6*x^\ 3+1/120*x^5”
> plot( [f, p], x=4..4, title=ttl );
sin(x)anditsTaylorapproximationx–1/6*x^3+1/120*x^5 1.5 1 0.5 –4 –3 –2 –1 0 –0.5 –1 –1.5 1 2 x 3 4 You can also convert a list to a set or a set to a list.
> L := [1,2,5,2,1]; L := [1, 2, 5, 2, 1]
> S := convert( L, set ); S := {1, 2, 5}
>...
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