6
Chapter 5: Basic Calculus Derivatives Deriva tives can be evaluated in  Mathematica using many di fferent commands. The D command requires three arguments inside the square brackets: the function, the variable and the number of derivatives. The last two arguments must be in a li st. Clear f f  = Sin x ; firstDer  = D f, x, 1 ; Print  "1 st deri va ti ve of f  =  ", firstDer 1 st derivative of f  =  Cos x secDer  = D f, x, 2 ; Print  "2 nd deri va ti ve of f  =  ", secD er 2nd derivative of f  = -  Sin x Partial Derivatives Anot her way of evaluati ng deriv ati ves is to use the pal ett es. The symbol  x  f   will evaluate the partial derivative of the function f  with respect to the variable x: x  f Cos x Try this command on a function containing two variables,  x and y: g  = Sin x  -  Cos y ; x  g; Print  "T he pa rt ia l de ri va ti ve of g wi th re sp ect to x  =  ", %D The partial derivative of g with respect to x  =  Cos x y  g; Print "The partial de ri va ti ve of g wi th respect to y  =  ", % The partial derivative of g with respect to y  =  Sin y 3

Ch5_calc

Embed Size (px)

Citation preview

Page 1: Ch5_calc

8/13/2019 Ch5_calc

http://slidepdf.com/reader/full/ch5calc 1/6

Chapter 5: Basic Calculus

Derivatives

Derivatives can be evaluated in  Mathematica  using many different commands. The D

command requires three arguments inside the square brackets: the function, the variableand the number of derivatives. The last two arguments must be in a list.

Clear f

f  =Sin x ;

firstDer  =D f, x, 1 ;

Print   "1st derivative of f   =   ", firstDer

1st derivative of f   =   Cos x

secDer  =D f, x, 2 ;

Print   "2nd derivative of f   =   ", secDer2nd derivative of f   = -   Sin x

Partial Derivatives

Another way of evaluating derivatives is to use the palettes. The symbol ¶ x   f    will

evaluate the partial derivative of the function f  with respect to the variable x:

¶x   f

Cos x

Try this command on a function containing two variables, x and y:

g  =Sin x   -   Cos y ;

¶x   g;

Print   "The partial derivative of g with respect to x   =   ",

%DThe partial derivative of g with respect to x   =   Cos x

¶y   g;

Print "The partial derivative of g with respect to y   =   ",

%

The partial derivative of g with respect to y   =   Sin y

3

Page 2: Ch5_calc

8/13/2019 Ch5_calc

http://slidepdf.com/reader/full/ch5calc 2/6

!ou can also evaluate the derivative of a function with respect to several variables using

the palettes. The e"pression ¶x ¶y   h  will allow you to evaluate the partial derivative of

h with respect to y and the partial derivative of the result with respect to x.

h  =x2 y4;

¶x   ¶y   h

8 x y3

The e"pression above can also be written as ¶y,x h  where the list of variables after the

symbol gives the order of differentiation:

¶y,x h

8 x y3

From Physical Chemistry A Molecular Approach, by Donald McQuarrie and John

D !imon:

"#ample $%&

"valuate the t'o (irst partial derivatives o( the molar pressure  P  (or the van der

)aals e*uation:

P + R T 

V  -   b  %  a

V #

 P  depends on T  and V  so P  $ P (T, V). Define an equation for P :

P  = *   T ! -     -   a ! 2

-  a

V2 +

  R T

-   b +V

%sing D, take the partial derivative of P  with respect to T  at constant V :

der1  =D P, T, 1 ;

Print   "¶P

¶T !    =   ", der1

¶ P

¶ TV  =

  R

-   b +V

%sing ¶V  P , take the partial derivative of P  with respect to V  at constant T :

der2  =¶ !   P;

Print   "¶P

¶ ! T   =   ", der2

¶ P

¶ VT  =

  2 a

V3  -

  R T

-   b +V   2

n(inite !eries

3&

Page 3: Ch5_calc

8/13/2019 Ch5_calc

http://slidepdf.com/reader/full/ch5calc 3/6

The Taylor series of the function f  at xo $ c can be e"pressed as:

 f  '"( $    f    n c

n! x -   c   n $  f  (c) )

c

+!  x )c

#!  x#)

f c $ -, we have the aclauren series:

 f  '"( $  f    n 0

n! x n $ f  (0) )

*  0

+!  x )**  0

#!  x )

The command /eries will e"ecute a Taylor series for any function. The command

requires four arguments: the function, the variable, the initial value of the variable and the

order of the e"pansion. The last three arguments must be in a list.

0or e"ample, e"ecute the Taylor series for c $ + to the th order for the function:

 f (x) = ln x

Series #og x , x, 1, $

x -   1   -  1

2x -   1

  2+

  1

3x -   1

  3-

  1

x -   1

  +

  1

!x -   1

  !+" x -   1

  #

 1ow e"ecute the aclauren series for c $ - to the 2th order for the function:

 g(x) = +

++ x   #

Series 1 1+x   2, x, , 4

1 -   2 x +3 x2 -   x

3 +! x +" x

  !

3

Page 4: Ch5_calc

8/13/2019 Ch5_calc

http://slidepdf.com/reader/full/ch5calc 4/6

From Physical Chemistry A Molecular Approach, by Donald McQuarrie and John

D !imon:

Problem $%-

"valuate¶U 

¶V T  (or an ideal .as and (or a van der )aals .as

¶ U 

¶ V T  +  T  

¶  P 

¶T V   %  P 

deal .as:  P  + R T 

van der )aals .as: P + R T 

V  -   b  %  a

V #

34

Page 5: Ch5_calc

8/13/2019 Ch5_calc

http://slidepdf.com/reader/full/ch5calc 5/6

Ans'ers: Problem $%-

0or an ideal gas:

Define an equation for the molar pressure P  of an ideal gas:

Clear , T, !, P

Pideal = *   T   ! 

R T

V

%sing ¶T  Pideal , take the partial derivative of Pideal  with respect to T  at constant V :

der&deal  =¶T   Pideal

RV

5valuate T  ¶ P 

¶T    V 6 P to get

¶U 

¶V    T and print out the answer:

ans1  =T*   der&deal -   P;

Print   "¶'

¶ ! T   =   ", ans1

¶ $

¶ V T  = -   P +

  R T

V

7ecall that the molar pressure P  was defined as Pideal . %se the substitution command 8.

and print out the actual answer:

ans2  =ans1 (P  ®Pideal;

Print   "¶'

¶ ! T   =   ", ans2, " for an ideal gas"

¶ $

¶ VT  =   % for an ideal gas

The internal energy U  of an ideal gas is independent of V  at constant T .

39

Page 6: Ch5_calc

8/13/2019 Ch5_calc

http://slidepdf.com/reader/full/ch5calc 6/6

0or a van der aals gas:

Define an equation for the molar pressure P  of a van der aals gas:

Clear , T, !, P, a,

Pvdw  = *   T   ! -     -   a ! 2

-  a

V2 +

  R T

-   b +V

%sing ¶T  Pvdw, take the partial derivative of Pvdw with respect to T  at constant V :

dervdw  =¶T   Pvdw

R

-   b +V

5valuate T  ¶ P 

¶T    V 6 P to get

¶U 

¶V    T  and print out the answer:

ans)  =T*  dervdw -   P;

Print   "¶'

¶ ! T   =   ", ans)

¶ $

¶ VT  = -   P +

  R T

-   b +V

7ecall that the molar pressure P  was defined as Pvdw. %se the substitution command 8.and print out the actual answer:

ans4  =ans) (P  ®Pvdw;

Print   "¶'

¶ ! T   =   ", ans4, " for a van der *aals gas"

$

¶ VT  =

  a

V2  for a van der &aals gas

The internal energy U  of a van der aals gas is dependent on V  at constant T .

2-