1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Kỹ thuật lập trình >

5 Power Series: Series[], Coefficient[], and CoefficientList[]

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 (4.66 MB, 453 trang )


Symbolic Operations



109



which gives

Cos[a] - Sin[a](x - a) +



1

1

Cos[a](x - a)2 + Sin[a](x - a)3

2

6



1

Cos[a](x - a)4 +O[x - a]5

24



The expression O[x-a]5 represents a term on the order of (x − a)5 . When a series is given in

this form, one cannot use it for further numerical evaluation; that is, for example, p/.x->2

results in an error message. To obtain an expression without this term and in a form that

permits further numerical evaluation, the function Normal is used as follows

p=Normal[Series[Cos[x],{x,a,4}]]

Execution of this command results in the previous result, but without the last term O[x-a]5 .

To be able to compare this result to those that follow, we shall expand p as follows

Expand[p]

which results in

1 4

1

1

1

a Cos[a] - a3 x Cos[a] - a3 Sin[a]+ a2 x2 Cos[a]+

24

6

6

4

1

1

1

1 2

a x Sin[a] - a2 Cos[a]+ x4 Cos[a]+ x3 Sin[a]2

2

24

6

1

1 2

1

3

2

a x Cos[a] - a x Sin[a] - x Cos[a] - x Sin[a]+

6

2

2

a x Cos[a]+a Sin[a]+Cos[a]

The coefficients of the series can be accessed two ways. If expans is a polynomial in the

powers of (x − a) up to the nth power, then the first way that the coefficients can be accessed

is by using

Coefficient[expans,(x-a),m]]

which retrieves the coefficient associated with (x − a)m , n ≥ m ≥ 1, or with

CoefficientList[expans,x]

which gives a list of all the coefficients up to and including xn−1 (n ≥ 1).

For example, continuing with the expansion of cosine of x above,

Coefficient[p,(x-a),2]]

gives

-



Cos[a]

2



An Engineer’s Guide to Mathematica®



110



whereas

Coefficient[p,x,2]]

gives

1

Cos[a]

1 2

a Cos[a] - a Sin[a] 4

2

2

On the other hand,

CoefficientList[p,x]

displays

{

1

1

1 4

a Cos[a] - a3 Sin[a] - a2 Cos[a]+a Sin[a]+Cos[a],

24

6

2

1 3

1 2

- a Cos[a]+ a Sin[a] - Sin[a]+a Cos[a],

6

2

}

1

1 2

Cos[a] Sin[a] 1

Cos[a]

a Cos[a] - a Sin[a] ,

- a Cos[a],

4

2

2

6

6

24

This list contains the coefficients of the expansion shown in Eq. (4.1), where the first element

in the list contains the terms multiplying x0 , the second element the terms multiplying x1 , and

so on.



Example 4.7

Perturbation Solution #1

The solution to

dy

d2 y

+ 𝜀 = −1

2

dt

dt

with the initial conditions of y(0) = 0 and dy(0)/dt = 1 is

y=



) t

1+ε(

1 − e−𝜀t −

2

𝜀

𝜀



It is assumed that 𝜀 ≪ 1 and the expansion of this solution up to terms including 𝜀2 is

sought. The statement to do this is

Normal[Series[(1+𝛆) (1-Exp[-𝛆 t])/𝛆ˆ2-t/𝛆,{𝛆,0,2}]]

which displays

t-



)

t2 1 (

+ -3 t2 +t3 ε+

2 6



(



t3 t4

6

24



)

ε2



Symbolic Operations



111



Example 4.8

Perturbation Solution #2

Perturbation theory can be used to obtain the approximate roots of transcendental equations.

For example, consider the expression

x2 − 1 = 𝜇ex



(a)



where 𝜇 is a small quantity. To determine the value of x that satisfies this equation using the

perturbation technique, one assumes a solution of the form



x=



N





Xn 𝜇n



(b)



n=0



where Xn is to be determined.

If we assume that N = 3 and substitute Eq. (b) into Eq. (a), we have

(

)2

2

3

X0 + X1 𝜇 + X2 𝜇2 + X3 𝜇3 − 𝜇eX0 +X1 𝜇+X2 𝜇 +X3 𝜇 − 1 = 0

To obtain the values of Xn , the above expression is expanded by expressing the exponential

function as a series and then by collecting the terms multiplying like powers of 𝜇. These terms

are then set equal to zero and a system of equations is obtained from which Xn can then be

determined.

We shall introduce the solution process in stages. First, we determine the coefficients of the

powers of 𝜇 using

trans=Normal[(X0 +μ X1 +μˆ2 X2 +μˆ3 X3 )ˆ2-1

-μ Series[Exp[X0 +μ X1 +μˆ2 X2 +μˆ3 X3 ],{μ,0,2}]]

which gives

(

)

(

)

-1+X20 +μ 2 X0 X1 - eX0 +μ2 X21 - eX0 X1 +2 X0 X2 +

(

)

(

)

1

μ3 2 X1 X2 - eX0 X21 +2 X2 +2 X0 X3

2

Next, we create a list of equations in the format required by Solve. First, we create a list

of the coefficients of 𝜇 as follows

zz=CoefficientList[trans,μ]

This gives

{

}

(

)

1

X20 - 1, 2 X0 X1 - eX0 , X21 - eX0 X1 +2 X0 X2 , 2 X1 X2 - eX0 X21 +2 X2 +2 X0 X3

2



An Engineer’s Guide to Mathematica®



112



We now convert the elements of this list into equations equaling zero by appending “==0”

to each of these coefficients. Thus,

q=Map[#==0 &,zz]

which produces

{ 2

X0 - 1 = =0, 2 X0 X1 - eX0 ==0, X21 - eX0 X1 +2 X0 X2 ==0,

}

(

)

1

2 X1 X2 - eX0 X21 +2 X2 +2 X0 X3 ==0

2

Lastly, we solve these four equations appearing in q for X0 to X3 using Solve as follows

Solve[q,{X0 ,X1 ,X2 ,X3 }]

which gives

{{

}

1

3

7

X0 → -1, X1 → - , X2 →

,

,

X



3

2e

8e2

16e3

{

}}

e

e2

e3

X0 → 1, X1 → , X2 →

, X3 →

2

8

16

Then using the above result and Eq. (b), the two roots are approximated by

e

e3

e2

x+ ≅ 1 + 𝜇 + 𝜇 2 + 𝜇 3

2

8

16

1

7 3

3

x− ≅ −1 − 𝜇 + 2 𝜇2 −

𝜇

2e

8e

16e3



4.6



Optimization: Maximize[]/Minimize[]



For a function f(x), the value of x = xm at which this function is a maximum/minimum and the

magnitude of f(xm ) is obtained from

Maximize[{f,con},x]

Minimize[{f,con},x]

where f is the function to be maximized or minimized, con are any constraints that f is

subject to, and x is the independent variable. The output of these functions is often fairly

complex so that several other functions are frequently used in conjunction with them.

To isolate the expression corresponding to the value of f(xm ), Maximize and Minimize,

respectively, are replaced with

MaxValue[{f,con},x]

MinValue[{f,con},x]



Symbolic Operations



113



and to isolate the expression corresponding to xm , Maximize and Minimize, respectively,

are replaced with

ArgMax[{f,con},x]

ArgMin[{f,con},x]

One additional function that is used to further reduce the results to a specific region is

Refine[exp,assum]

where exp is a symbolic expression, in this case the output from one of the above functions,

and assum are the assumptions that specify the region of interest.

The use of these functions is illustrated in the following example.



Example 4.9

Peak Amplitude Response of a Single Degree-of-Freedom System

The amplitude response function for a single degree-of-freedom system is given by

1

H(Ω) = √

(

)2

1 − Ω2 + (2𝜁 Ω)2

where Ω is a frequency ratio and 0 < 𝜁 < 1. Expressions for the maximum value and the value

of Ω at which this maximum occurs are obtained from

homega[Ω_,ζ_]:=1/Sqrt[(1-Ωˆ2)ˆ2+(2 ζ Ω)ˆ2]

hmax=Maximize[{homega[Ω,ζ],0<ζ<1,Ω>0},Ω]//Simplify

which displays

⎧⎡

1

⎪⎢

⎪⎢

⎪⎢ √

1

⎨⎢ 1

⎪⎢ 2 ζ2 - ζ4

⎪⎢

⎪⎣

-∞





1

√ <ζ<1

2

1

0<ζ< √ ,

2

True

[







1

)+

⎪ Root 4+ 2 ( 2



ζ

-1

ζ

Ω











⎩ Indeterminate





(



)

4

2

- (

)

ζ2 - 1 ζ2 ζ 2 - 1



]

#14

#1 + (

) &, 3

ζ2 ζ 2 - 1

2



1 ⎫⎫

0 < ζ < √ ⎪⎪

2 ⎬⎬

⎪⎪

⎭⎭

True





It is seen that the solution of interest is that given for the region 0 < 𝜁 < 1∕ 2. Hence, the

elements of this solution can be accessed in the following manner. To isolate the expression

for H(Ωm ), we instead obtain the solution with

hmax=MaxValue[{homega[Ω,ζ],0<ζ<1,Ω>0},Ω]//Simplify;

sh=Refine[hmax,0<ζ<1/Sqrt[2]]



An Engineer’s Guide to Mathematica®



114



which displays



1

1

2 ζ2 - ζ4

Further simplification is done by using

hmax=PowerExpand[Factor[sh],Assumptions->0<ζ<1/Sqrt[2]]

which displays

1



2 ζ 1 - ζ2

To obtain Ωm , we re-solve the expression using

omegmax=ArgMax[{homega[Ω,ζ],0<ζ<1,Ω>0},Ω]//Simplify;

so=Refine[omegmax,0<ζ<1/Sqrt[2]][[1]]

Solve[so[Ω]==0,Ω]

which results in

{{

} {

} {

} {

}}









Ω → - 1 - 2 ζ2 , Ω → - 1 - 2 ζ2 , Ω → 1 - 2 ζ2 , Ω → 1 - 2 ζ2

Thus,

Ωm =







1 − 2 𝜁2



and, therefore,

Hm (Ωm ) = H



4.7



)

(√

1 − 2𝜁 2 =



1



2𝜁 1 − 𝜁 2



1

0<𝜁 < √

2



Differentiation: D[]



Differentiation with respect to one or more variables is performed using

D[f,{x1,n1},{x2,n2}, ... ]

where f is an expression in one or more of the variables {x1,x2, ... } and n1,n2, ...

are the orders of the derivatives in each variable. Thus, D also obtains the partial derivative.

There are several equivalent syntaxes for D that, along with examples of their usage, are shown

in Table 4.3. Also presented in this table are examples of D applied to several classes of

functions.



Differentiate a

function within an

integral#



Arbitrary function of

two variables

evaluated at a

point b



Arbitrary function of

two variables



Arbitrary function of

one variable

evaluated at a

point b



[



d(y)



d

f (y, x) dx

dy ∫c(y)



d

f (y, x) dx

dy ∫c(y)



d(y)



𝜕f (x, y) ||

𝜕x ||x=b



𝜕 3 f (x, y)

𝜕x2 𝜕y



df (x) ||

dx ||x=b



d f

dx4



4



Mathematical form



y=r



]



D[Integrate[f[y,x],

{x,c[y],d[y]}],y]/.y->r



D[Integrate[f[y,x],

{x,c[y],d[y]}],y]



D[f[x,y],x]/.x->b or

Derivative[1,0][f][b,y] or

𝜕x f [x] ∕.x- > b



D[f[x,y],{x,2},{y,1}] or

D[f[x,y],x,x,y] or

D[f[x,y],y,x,x] or

Derivative[2,1][f][x,y]

or

[

]

𝜕x,x,y f x, y



D[f[x],{x,4}] or

D[f[x],x,x,x,x] or

Derivative[4][f][x] or

f′′′′ [x] or

𝜕x,x,x,x f[x]

D[f[x],x]/.x->b or

Derivative[1][f][b] or

f′ [x]/.x->b or

𝜕x f [x] ∕.x- > b



Mathematica expression‡



Examples of the symbolic derivative of different types of functions



Arbitrary function of

one variable



Type



Table 4.3



(continued)



f(1,0) (r, x) dx - c′ [r] f[r, c[r]]

∫c[r]

+d′ [r] f[r, d[y]]



d[r]



f(1,0) (y, x) dx - c′ [y] f[y, c[y]]

∫c[y]

+d′ [y] f[y, d[y]]



d[y]



f(1,0) [b,y]



f(2,1) [x,y]



f′ [b]



f(4) [x]



Output



D[Log10[a x],x] or

𝝏 x Log10[a x]

D[BesselJ[n,a x],x] or

𝝏 x BesselJ[n,a x]

D[LegendreP[n,a x],x] or

𝝏 x LegendreP[n,a x]



log10 ax



Jn (ax)



Pn (ax)



Special–Bessel



Special–Legendre



1

a (BesselJ[-1+n, a x]

2

-BesselJ[1+n, a x])

(

a

a (-1 - n) x LegendreP[n, a x]

-1+a2 x2

)

+(1+n) LegendreP[1+n, a x]



1

x Log[10]



1

x



a ea x



a





-1+ax 1+ax



a Sinh[a x]



a



1 - a2 x 2



a Cos[a x]



an x n Log[a]



a n f[a x]-1+n f′ [a x]



n x-1+n



Output







As indicated, the differentiation also can be accomplished with 𝝏x f, where f is the expression appearing in the column labeled Mathematical form and

𝜕▫ ▫ is obtained from a template in the Basic Math Assistant.

#

See Section 4.8 for the use of Integrate[].



D[Log[a x],x] or

𝝏 x Log[a x]



eax



cosh−1 ax



cosh ax



sin−1 ax



sin ax



anx



ln ax



Exponential and

logarithmic



Hyperbolic



Trigonometric



D[xˆn,x] or

𝝏 x xn

D[f[a x]ˆn,x] or

𝝏 x f[a x]n

D[aˆ(n x),x] or

𝝏 x an x

D[Sin[a x],x] or

𝝏 x Sin[a x]

D[ArcSin[a x],x] or

𝝏 x ArcSin[a x]

D[Cosh[a x],x] or

𝝏 x Cosh[a x]

D[ArcCosh[a x],x] or

𝝏 x ArcCosh[a x]

D[Eˆ(a x),x] or

𝝏 x Ea x



xn



Power



[f(ax)]n



Mathematica expression‡



Mathematical form



(Continued)



Type



Table 4.3



Symbolic Operations



117



For an example, consider the expression

z = x3 y4

/

To determine 𝜕 5 z 𝜕x2 𝜕y3 , we proceed as follows

D[xˆ3 yˆ4,{x,2},{y,3}] (* or D[xˆ3 yˆ4,x,x,y,y,y] *)

which gives

144 x y

When f is a function of one variable, D can be replaced by a prime (′ ) provided that f

is explicitly represented as a function of the independent variable. Consider the following

expression

y(x) = x3 cos ax

Then the second derivative of y can be determined using primes as follows

y[x_]=xˆ3 Cos[a x];

y''[x] (* or D[y[x],x,x] *)

The execution of these statements displays

6 x Cos[a x]-a2 x3 Cos[a x]-6 a x2 Sin[a x]

The command D can also be used to perform differentiation using functional representation

and a change of variables. Consider the function f(u), where u = z(x). Then df/dx is obtained

from

u=z[x];

D[f[u],x] (* or in a compact form as D[f[z[x]],x] *)

which displays

f'[z[x]] z'[x]

where the prime denotes the derivative with respect to its argument; that is,

f'[z[x]]z'[x] →



df dz

dz dx



For example, if z = bxg , then we can use the previous command and the transformation rule

to determine df/dx as follows

D[f[z[x]],x]/.D[z[x],x]->D[b xˆg,x]



An Engineer’s Guide to Mathematica®



118



which gives

b g x-1+g f'[z[x]]

An expression for d2 f/dx2 is obtained from

D[f[z[x]],x,x]

which displays

z'[x]ˆ2 f''[z[x]]+f'[z[x]] z''[x]

where the prime denotes the derivative with respect to its argument; that is,

z'[x]2 f''[z[x]]+f'[z[x]] z''[x] →



(



dz

dx



)2 d2 f df 2

d z

+

dz2 dz dx2



Again letting z = bxg , we can use the previous command and the transformation rule to

determine d2 f/dx2 as follows

Simplify[D[f[z[x]],x,x]/.{D[z[x],x]->D[b xˆg,x],

D[z[x],x,x]->D[b xˆg,x,x]}]

which yields

b g x-2+g ((-1+g) f'[z[x]]+b g xg f''[z[x]])

We shall now illustrate the use of D with several additional examples.



Example 4.10

Radius of Curvature

The curvature of a plane curve in terms of the parametric quantities x(t) and y(t) is given by

x′ y′′ − y′ x′′

𝜅=(

)3∕2

x′2 + y′2

where the prime indicates the derivative with respect to t. We shall determine 𝜅 when

x = a(t − tanh t)

y = a sech t

where a is a constant.



Symbolic Operations



119



The program to determine 𝜅 is

xp=D[a (t-Tanh[t]),t];

yp=D[a Sech[t],t];

kap=Simplify[(xp D[yp,t]-yp D[xp,t])/(xpˆ2+ypˆ2)ˆ(3/2)]

Execution of these instructions gives

Sech[t]



a2 Tanh[t]2

This result can be further simplified by using PowerExpand. Thus, we add the statement

kap=PowerExpand[kap]

which, upon execution, gives the final result

Csch[t]

a



Example 4.11

Euler–Lagrange Equation

The governing differential for the dynamic response of a thin beam resting on an elastic

foundation can be obtained from the Euler–Lagrange equation

Fw +



𝜕 2 Fwxx

𝜕x2







𝜕Fẇ

=0

𝜕t



where F is an expression relating the kinetic energy, the potential energy, and the external

work of the system and

F𝛼 =



𝜕F

,

𝜕𝛼



wx =



𝜕w

,

𝜕x



wxx =



𝜕2w

,

𝜕x2



ẇ =



𝜕w

𝜕t



The quantity F for this beam system is given by

( 2 )2

( )2

1

1

1

𝜕 w

𝜕w

F = c1

− c2

− c3 w2 + g(x, t)w

2

𝜕t

2

2

𝜕x2

where ck are constants.

We shall now use these equations to derive the governing equation as follows

fF=1/2 c1 D[w[x,t],t]ˆ2-1/2 c2 D[w[x,t],{x,2}]ˆ2

-1/2 c3 w[x,t]ˆ2+g[x,t] w[x,t];

eqn=D[fF,w[x,t]]+D[D[fF,D[w[x,t],x,x]],x,x]

-D[D[fF,D[w[x,t],t]],t]



Xem Thêm
Tải bản đầy đủ (.pdf) (453 trang)

×