Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (25.81 MB, 585 trang )

24

Chapter 2 Basic Operations on Numbers, Expressions, and Functions

EXAMPLE 2.1.1: Calculate (a) 121 542; (b) 3231 9876; (c)

12315

467

; and (f)

.

(d) 22341 832748 387281 ; (e)

31

35

23 76 ;

SOLUTION: These calculations are carried out in the following screen

shot. In (f), Mathematica simpliﬁes the quotient because the numerator

and denominator have a common factor of 5. In each case, the input is

typed and then evaluated by pressing Enter.

n

m n

m

The term an/ m

a

a is entered as aˆ(n/m). For n/ m

1/ 2, the command Sqrt[a] can be used instead. Usually, the result is returned in unevaluated

form but N can be used to obtain numerical approximations to virtually any degree

of accuracy. With N[expr,n], Mathematica yields a numerical approximation of

expr to n digits of precision, if possible. At other times, Simplify can be used to

produce the expected results.

Remark. If the expression b in ab contains more than one symbol, be sure that the

exponent is included in parentheses. Entering aˆn/m computes an / m m1 an while

entering aˆ(n/m) computes an/ m .

EXAMPLE 2.1.2: Compute (a)

27 and (b)

3

82

82/ 3 .

2.1 Numerical Calculations and Built-In Functions

25

SOLUTION: (a) Mathematica automatically simpliﬁes

27

3 3.

In[18]:= Sqrt 27

Out[18]= 3

3

We use N to obtain an approximation of

27.

N[number] and

number//N return

numerical approximations of

number.

In[19]:= N Sqrt 27

Out[19]= 5.19615

(b) Mathematica automatically simpliﬁes 82/ 3 .

In[20]:= 8ˆ 2/3

Out[20]= 4

When computing odd roots of negative numbers, Mathematica’s results are surprising to the novice. Namely, Mathematica returns a complex number. We will

see that this has important consequences when graphing certain functions.

EXAMPLE 2.1.3: Calculate (a)

1

3

27

64

2

and (b)

27

64

2/ 3

.

SOLUTION: (a) Because Mathematica follows the order of operations,

(-27/64)ˆ2/3 ﬁrst computes 27/ 64 2 and then divides the result

by 3.

In[21]:=

27/64 ˆ2/3

243

Out[21]=

4096

(b) On the other hand, (-27/64)ˆ(2/3) raises 27/ 64 to the 2/ 3 power.

2/ 3

Mathematica does not automatically simplify 27

.

64

In[22]:=

27/64 ˆ 2/3

9

1 2/ 3

Out[22]=

16

However, when we use N, Mathematica returns the numerical version

2/ 3

.

of the principal root of 27

64

In[23]:= N

Out[23]=

27/64 ˆ 2/3

0.28125

0.487139 i

26

Chapter 2 Basic Operations on Numbers, Expressions, and Functions

To obtain the result

27

64

2

2/ 3

3

27

64

3

4

2

9

,

16

which would be expected by most algebra and calculus students, we

load the RealOnly package that is contained in the Miscellaneous

directory. Then,

In[24]:= << Miscellaneous‘RealOnly‘

In[25]:=

Out[25]=

27/64 ˆ 2/3

9

16

returns the result 9/ 16.

2.1.2 Built-In Constants

Mathematica has built-in deﬁnitions of many commonly used constants. In par1 is

ticular, e 2.71828 is denoted by E, Π 3.14159 is denoted by Pi, and i

denoted by I. Usually, Mathematica performs complex arithmetic automatically.

Other built-in constants include , denoted by Infinity, Euler’s constant, Γ

0.577216, denoted by EulerGamma, Catalan’s constant, approximately 0.915966,

5

1.61803, denoted by

denoted by Catalan, and the golden ratio, 12 1

GoldenRatio.

EXAMPLE 2.1.4: Entering

In[26]:= N e, 50

Out[26]= 2.718281828459045235360287471352662497757247093699959

7.496696760000000000000000000000000000000000000000 108

returns a 50-digit approximation of e. Entering

In[27]:= N Π, 25

Out[27]= 3.141592653589793238462643

returns a 25-digit approximation of Π. Entering

In[28]:=

3 i / 4

11 7 i

Out[28]=

17

17

performs the division 3

form.

i

i/ 4

i and writes the result in standard

2.1 Numerical Calculations and Built-In Functions

27

2.1.3 Built-In Functions

Mathematica contains numerous mathematical functions.

Functions frequently encountered by beginning users include the exponential

function, Exp[x]; the natural logarithm, Log[x]; the absolute value function,

Abs[x]; the trigonometric functions Sin[x], Cos[x], Tan[x], Sec[x], Csc[x],

and Cot[x]; the inverse trigonometric functions ArcSin[x], ArcCos[x],

ArcTan[x], ArcSec[x], ArcCsc[x], and ArcCot[x]; the hyperbolic trigonometric functions Sinh[x], Cosh[x], and Tanh[x]; and their inverses

ArcSinh[x], ArcCosh[x], and ArcTanh[x]. Generally, Mathematica tries to

return an exact value unless otherwise speciﬁed with N.

Several examples of the natural logarithm and the exponential functions are

given next. Mathematica often recognizes the properties associated with these

functions and simpliﬁes expressions accordingly.

EXAMPLE 2.1.5: Entering

In[29]:= N Exp

5

Out[29]= 0.00673795

returns an approximation of e

5

1/ e5 . Entering

In[30]:= Log Exp 3

Exp[x] computes ex . Enter

E to compute e 2.718.

Out[30]= 3

computes ln e3

3. Entering

Log[x] computes ln x. ln x

and ex are inverse functions

(ln ex x and eln x x) and

Mathematica uses these

properties when simplifying

expressions involving these

functions.

In[31]:= Exp Log 4

Out[31]= 4

computes eln 4

N[number] or

number//N return

approximations of number.

4. Entering

In[32]:= Abs

Π

Out[32]= Π

computes

Π

Π. Entering

In[33]:= Abs

Out[33]=

computes 3

3

2i / 2

Abs[x] returns the

absolute value of x, x .

9i

13

85

2i / 2

9i . Entering

In[34]:= Sin Π/12

1

3

Out[34]=

2 2

28

N[number] and

number//N return

approximations of number.

Chapter 2 Basic Operations on Numbers, Expressions, and Functions

computes the exact value of sin Π/ 12 . Although Mathematica cannot

compute the exact value of tan 1000, entering

In[35]:= N Tan 1000

Out[35]= 1.47032

returns an approximation of tan 1000. Similarly, entering

In[36]:= N ArcSin 1/3

Out[36]= 0.339837

returns an approximation of sin

1

1/ 3 and entering

In[37]:= ArcCos 2/3 //N

Out[37]= 0.841069

returns an approximation of cos

1

2/ 3 .

Mathematica is able to apply many identities that relate the trigonometric and exponential functions using the functions TrigExpand, TrigFactor, TrigReduce,

TrigToExp, and ExpToTrig.

In[38]:= ?TrigExpand

"TrigExpand expr expandsouttrigonometric

functionsinexpr."

In[39]:= ?TrigFactor

"TrigFactor expr factorstrigonometricfunctions

inexpr."

In[40]:= ?TrigReduce

"TrigReduce expr rewritesproductsandpowers

oftrigonometricfunctionsinexprinterms

oftrigonometricfunctionswithcombinedarguments."

In[41]:= ?TrigToExp

"TrigToExp expr convertstrigonometricfunctions

inexprtoexponentials."

In[42]:= ?ExpToTrig

"ExpToTrig expr convertsexponentialsinexpr

totrigonometricfunctions."

2.1 Numerical Calculations and Built-In Functions

EXAMPLE 2.1.6: Mathematica does not automatically apply the identity sin2 x cos2 x 1.

In[43]:= Cos x ˆ2

Out[43]= Cos x

2

Sin x ˆ2

Sin x

2

To apply the identity, we use Simplify. Generally,

Simplify[expression] attempts to simplify expression.

In[44]:= Simplify Cos x ˆ2

Sin x ˆ2

Out[44]= 1

Use TrigExpand to multiply expressions or to rewrite trigonometric functions.

In this case, entering

In[45]:= TrigExpand Cos 3x

Out[45]= Cos x

3

3 Cos x

Sin x

2

writes cos 3x in terms of trigonometric functions with argument x. We use the

TrigReduce function to convert products to sums.

In[46]:= TrigReduce Sin 3x Cos 4x

1

Sin x

Sin 7 x

Out[46]=

2

We use TrigExpand to write

In[47]:= TrigExpand Cos 2x

Out[47]= Cos x

2

Sin x

2

in terms of trigonometric functions with argument x. We use ExpToTrig to convert exponential expressions to trigonometric expressions.

In[48]:= ExpToTrig 1/2 Exp x

Exp

x

Out[48]= Cosh x

Similarly, we use TrigToExp to convert trigonometric expressions to exponential expressions.

In[49]:= TrigToExp Sin x

1

i e i x ei x

Out[49]=

2

Usually, you can use Simplify to apply elementary identities.

In[50]:= Simplify Tan x ˆ2

Out[50]= Sec x

2

1

29

30

Chapter 2 Basic Operations on Numbers, Expressions, and Functions

A Word of Caution

Remember that there are certain ambiguities in traditional mathematical notation.

For example, the expression sin2 Π/ 6 is usually interpreted to mean “compute

sin Π/ 6 2 . The symbol sin is

sin Π/ 6 and square the result.” That is, sin2 Π/ 6

not being squared; the number sin Π/ 6 is squared. With Mathematica, we must be

especially careful and follow the standard order of operations exactly, especially

when using InputForm. We see that entering

In[51]:= Sin Π/6 ˆ2

1

Out[51]=

4

computes sin2 Π/ 6

sin Π/ 6

2

while

In[52]:= Sin ˆ2 Π/6

2

Out[52]= Sin

Π

6

raises the symbol Sin to the power 2

Π

6

. Mathematica interprets

In[53]:= sinˆ2 Π/6

Π sin2

Out[53]=

6

to be the product of the symbols sin2 and Π6 . However, using TraditionalForm we

sin Π/ 6 2 with Mathematica using conventional

are able to evaluate sin2 Π/ 6

mathematical notation.

In[54]:= Sin2

Out[54]=

Π

6

1

4

Be aware, however, that traditional mathematical notation does contain certain

ambiguities and Mathematica may not return the result you expect if you enter input using TraditionalForm unless you are especially careful to follow the standard

order of operations, as the following warning message indicates.

2.2 Expressions and Functions: Elementary Algebra

2.2 Expressions and Functions:

Elementary Algebra

2.2.1 Basic Algebraic Operations on Expressions

Expressions involving unknowns are entered in the same way as numbers.

Mathematica performs standard algebraic operations on mathematical expressions.

For example, the commands

1.

2.

3.

4.

Factor[expression] factors expression;

Expand[expression] multiplies expression;

Together[expression] writes expression as a single fraction; and

Simplify[expression] performs basic algebraic manipulations on

expression and returns the simplest form it ﬁnds.

For basic information about any of these commands (or any other) enter ?command

as we do here for Factor.

or access the Help Browser as we do here for Simplify.

31

32

Chapter 2 Basic Operations on Numbers, Expressions, and Functions

When entering expressions, be sure to include a space or * between variables to

denote multiplication.

EXAMPLE 2.2.1: (a) Factor the polynomial 12x2 27xy 84y2 . (b) Expand

2

x2

as a single

the expression x y 2 3x y 3 . (c) Write the sum 2

x

2

fraction.

SOLUTION: The result obtained with Factor indicates that 12x2

27xy 84y2 3 4x 7y x 4y . When typing the command, be sure to include a space, or *, between the x and y terms to denote multiplication.

xy represents an expression while x y or x*y denotes x multiplied

by y.

In[55]:= Factor 12x2

Out[55]= 3 4 x

27xy

7y

x

84y2

4y

We use Expand to compute the product x

x2

2

as a single fraction.

to express 2

x

2

In[56]:= Expand

Out[56]= 27 x5

x

27 x4 y

In[57]:= Together

Out[57]=

Factor[xˆ2-3] returns

x2 3.

y

2

x2

3x

y

18 x3 y2

2

3x

y 3 and Together

3

10 x2 y3

7 x y4

y5

x2

2

4 x4

2 x2

To factor an expression like x2 3

the Extension option.

In[58]:= Factor xˆ2

Out[58]=

2

y

3

x

x2

3

2

3, Extension

3

x

3 x

3 , use Factor with

Sqrt 3

x

Similarly, use Factor with the Extension option to factor expressions like x2

x i x i.

1 x 2 i2

In[59]:= Factor xˆ2

Out[59]= 1

In[60]:= Factor xˆ2

Out[60]=

1

x2

x

1, Extension

x

I

2.2 Expressions and Functions: Elementary Algebra

33

x2 to the expression x

Mathematica does not automatically simplify

In[61]:= Sqrt xˆ2

Out[61]=

x2

because without restrictions on x, x2 x . The command PowerExpand[expression]

simpliﬁes expression assuming that all variables are positive.

In[62]:= PowerExpand Sqrt xˆ2

Out[62]= x

Thus, entering

In[63]:= Simplify Sqrt aˆ2 bˆ4

Out[63]=

returns

a2 b4

a2 b4 but entering

In[64]:= PowerExpand Sqrt aˆ2 bˆ4

Out[64]= a b2

returns ab2 .

In general, a space is not needed between a number and a symbol to denote multiplication when a symbol follows a number. That is, 3dog means 3 times variable

dog; dog3 is a variable with name dog3. Mathematica interprets 3 dog, dog*3,

and dog 3 as 3 times variable dog. However, when multiplying two variables,

either include a space or * between the variables.

1. cat dog means “variable cat times variable dog.”

2. cat*dog means “variable cat times variable dog.”

3. But, catdog is interpreted as a variable catdog.

The command Apart[expression] computes the partial fraction decomposition of expression; Cancel[expression] factors the numerator and denominator of expression then reduces expression to lowest terms.

EXAMPLE 2.2.2: (a) Determine the partial fraction decomposition of

1

x2 1

. (b) Simplify 2

.

x 3 x 1

x 2x 1

Then, Cancel is used to ﬁnd that

x

x2

1

1

SOLUTION: Apart is used to see that

x

2

3 x

1

2x

1

1

x

2x 3

1 x 1

x 12

1

2x 1

x 1

.

x 1

.

34

Chapter 2 Basic Operations on Numbers, Expressions, and Functions

In this calculation, we have assumed that x

by Cancel but not by Simplify.

1

In[65]:= Apart

Out[65]=

2

1, an assumption made

x

1

3 x

In[66]:= Cancel 2

x

1 x

Out[66]=

1 x

3

2

x

x 1

1

1 x

2

1

2x 1

In addition, Mathematica has several built-in functions for manipulating parts of

fractions.

1.

2.

3.

4.

Numerator[fraction] yields the numerator of fraction.

ExpandNumerator[fraction] expands the numerator of fraction.

Denominator[fraction] yields the denominator of fraction.

ExpandDenominator[fraction] expands the denominator of

fraction.

2x2 x 2

, (a) factor both the numerator

x2 4x 4

3

2

x 2x x 2

and denominator; (b) reduce 3

to lowest terms; and (c)

x x2 4x 4

3

x 2x2 x 2

ﬁnd the partial fraction decomposition of 3

.

x x2 4x 4

EXAMPLE 2.2.3: Given

x3

x3

x3 2x2 x 2

is extracted with

x3 x2 4x 4

Numerator. We then use Factor together with %, which is used to

refer to the most recent output, to factor the result of executing the

Numerator command.

SOLUTION: The numerator of

x3 2x2 x

x3 x2 4x

2 x2 x3

In[67]:= Numerator

Out[67]=

2

x

In[68]:= Factor %

Out[68]=

1 x 1

x

2

2

4

x

Similarly, we use Denominator to extract the denominator of the

fraction. Again, Factor together with % is used to factor the previous

result, which corresponds to the denominator of the fraction.

Tải bản đầy đủ (.pdf) (585 trang)