LearningGuide

# newstr cati cant believe mystr newstr i cant

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: ; they cannot be assigned a value. > "my age" := 32; Error, invalid left hand side of assignment Like elements of lists or arrays, the individual characters of a string can be indexed with square bracket notation. > mystr := "I ate the whole thing."; mystr := “I ate the whole thing.” > mystr[3..5]; “ate” > mystr[11..-2]; “whole thing” A negative index represents a character position counted from the right end of the string. In the example above, −2 represents the second last character. The concatenation operator, “||”, or the cat command is used to join two strings together, and the length command is used to determine the number of characters in a string. > newstr := cat("I can’t believe ", mystr); newstr := “I can’t believe I ate the whole thing.” > length(newstr); 2.6 Expression Manipulation • 33 38 For examples of commands that operate on strings and take strings as input, refer to the ?StringTools help page. 2.6 Expression Manipulation Many Maple commands concentrate on manipulating expressions. This includes manipulating results of Maple commands into a familiar or useful form. This section introduces the most commonly used commands in this area. The simplify Command You can use this command to apply simpliﬁcation rules to an expression. Maple has simpliﬁcation rules for various types of expressions and forms, including trigonometric functions, radicals, logarithmic functions, exponential functions, powers, and various special functions. > expr := cos(x)^5 + sin(x)^4 + 2*cos(x)^2 > - 2*sin(x)^2 - cos(2*x); expr := cos(x)5 + sin(x)4 + 2 cos(x)2 − 2 sin(x)2 − cos(2 x) > simplify(expr); cos(x)4 (cos(x) + 1) To perform only a certain type of simpliﬁcation, specify the type you want. > simplify(sin(x)^2 + ln(2*y) + cos(x)^2); 1 + ln(2) + ln(y ) > simplify(sin(x)^2 + ln(2*y) + cos(x)^2, ’trig’); 1 + ln(2 y ) 34 • Chapter 2: Mathematics with Maple: The Basics > simplify(sin(x)^2 + ln(2*y) + cos(x)^2, ’ln’); sin(x)2 + ln(2) + ln(y ) + cos(x)2 With the side relations feature, you can apply your own simpliﬁcation rules. > siderel := {sin(x)^2 + cos(x)^2 = 1}; siderel := {sin(x)2 + cos(x)2 = 1} > trig_expr := sin(x)^3 - sin(x)*cos(x)^2 + 3*cos(x)^3; trig _expr := sin(x)3 − sin(x) cos(x)2 + 3 cos(x)3 > simplify(trig_expr, siderel); 2 sin(x)3 − 3 cos(x) sin(x)2 + 3 cos(x) − sin(x) The factor Command This command factors polynomial expressions. > big_poly := x^5 - x^4 - 7*x^3 + x^2 + 6*x; big _poly := x5 − x4 − 7 x3 + x2 + 6 x > factor(big_poly); x (x − 1) (x − 3) (x + 2) (x + 1) > rat_expr := (x^3 - y^3)/(x^4 - y^4); rat _expr := x3 − y 3 x4 − y 4 Both the numerator and denominator contain the common factor x−y . Thus, factoring cancels these terms. > factor(rat_expr); 2.6 Expression Manipulation • 35 x2 + x y + y 2 (y + x) (x2 + y 2 ) Maple can factor both univariate and multivariate polynomials over the domain the coeﬃcients specif...
View Full Document

Ask a homework question - tutors are online