an engineer’s guide to mathematica - homepage | wiley · an engineer’s guide to mathematica® 2...

29
An Engineer’s Guide to Mathematica ® Update to Mathematica 10 Edward B. Magrab © 2014 John Wiley & Sons, Ltd

Upload: buidang

Post on 02-Dec-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

Update to Mathematica 10

Edward B. Magrab

© 2014 John Wiley & Sons, Ltd

Page 2: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

2

Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained a very large number of new commands and expanded the capabilities of a number of existing commands. This update introduces and illustrates those commands that directly impact the material presented in An Engineer’s Guide to Mathematica, which was based on Mathematica 9 and became available in April 2014. The commands that impact the material in this book are primarily those that provide the capability of creating regions and volumes of arbitrary shape. To make the most of these new capabilities, Mathematica 10 has extended several of the commands discussed in Chapter 5 to perform their operations within specified regions. These commands are: numerical integration (NIntegrate), finding the maximum or minimum (NMaximum/NMinimum), numerically solving equations and polynomials (NSolve), and obtaining numerical solutions to a class of second-order partial differential equations (NDSolveValue). Complementing these region and volume creation commands is the capability of discretizing them and then linking them to the finite element method, which is then used by NDSolveValue to solve a class of linear second-order partial differential equations. In addition, several new commands have been introduced to determine the area, centroid, length of a boundary, and volume of regions. We shall introduce and illustrate these additional capabilities in the context of the appropriate sections within the book. A list of the topics addressed is given in Table S.1, a list of commands whose capabilities have been extended is given in Table S.2, a list of commands introduced in this update is given in Table S.3, and a list of tutorials available for this new material is given in Table S.4. In addition, a list of the engineering applications presented in the update is given in Table S.5. Table S.1 Updates and their points of insertion in the book

Page Section Update Topic

11 1.3 Notebook Cells Context sensitive input assistant

126 4.9 Solutions to Ordinary Differential Equations Introduction of new command DSolveValue

151 New section Creating regions and volumes of arbitrary shape

152 5.2 Numerical Integration Numerical integration over regions and volumes

154 New section Determining properties of curves, regions, and volumes

178 New section

Solving second-order partial differential equations with finite elements using expanded capabilities of NDSolveValue

178 Section 5.4 Numerical Solutions of Equations

Determine numerically the solution to an equation over a region

183 Section 5.6 Minimum and Maximum Numerically determine minimum/maximum over a region

210 Section 6.2.1 Basic Plotting Selecting plotting themes

246 Section 6.3 3D Graphics New commands for special cases of GraphicsComplex

© 2014 John Wiley & Sons, Ltd

Page 3: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

3

Table S.2 Commands with extended capability

Command Capability upgrade

NDSolveValue Find numerically the solution of a class of linear second-order partial differential equations using finite elements over a region of arbitrary shape

NIntegrate Numerically integrate over specified region of arbitrary shape

NMaximize/NMinimize Find numerically the maximum/minimum of the boundary of a specified region of arbitrary shape

NSolve Find numerically the solution to equations within specified regions of arbitrary shape

Table S.3 Functions introduced in this update

Command Usage

ArcLength Determines the length of planar and spatial lines, curves, and region perimeters

Area Determines the area of a two-dimensional region

Div Gives the divergence of a function

DSolveValue Attempts to obtain the symbolic solution to an ordinary or partial differential equation

Grad Gives the gradient of a function

ImplicitRegion Creates a two-dimensional region or a volume subject to certain conditions

InfiniteLine Creates a representation of an infinite line passing through two points

InfinitePlane Creates a representation of an infinite plane passing through three points

Laplacian Gives the Laplacian of a function

Parallelogram Creates a parallelogram

ParametricRegion Creates a representation of a region described by one or more parameters

RegionBoundary Represents the boundary of a region

RegionCentroid Determines the centroid of a region

RegionDifference Determines the region resulting from the difference of two regions

RegionIntersection Determines the region resulting from the intersection of two or more regions

RegionUnion Determines the region resulting from the union of two or more regions

ToBoundaryMesh Partitions a boundary into a connected set of smaller elements

ToElementMesh Partitions a region or volume into a connected set of smaller regions or volumes

Volume Determines the volume of a three-dimensional shape

© 2014 John Wiley & Sons, Ltd

Page 4: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

4

Table S.4 Topical search entries in the Documentation Center

Topic Search Entry

Creation and analysis of regions with finite elements

FEMDocumentation/tutorial/ElementMeshCreation FEMDocumentation/tutorial/ElementMeshVisualization FEMDocumentation/tutorial/FiniteElementProgramming

Second-order partial differential equations FEMDocumentation/tutorial/SolvingPDEwithFEM

Table S.5 Engineering Applications

Topic Example

Heat Transfer Steady-State Temperature Distribution in a Slab with a Circular Hole Structures Area moment of Inertia Torsion of Channel Beams Stress Distribution in a Plate with a Hole Subjected to an In-Plane Tensile Force Vibrations Response of a Membrane to a Concentrated Impulse Force

Example S.2 Example S.1 Example S.3 Example S.4 Example S.5

© 2014 John Wiley & Sons, Ltd

Page 5: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

5

Insert to Page 11 [Before start of last paragraph]

Another aspect of the Context Sensitive Input Assistant is the Function and Option Template, which displays when the cursor hovers over a Mathematica command. Clicking on the double downward facing carats displays the syntax for that command. Clicking on the circled i brings up the Help page for the command. The assistant also provides a context sensitive auto completion capability in those commands that have options. See guide/WolframPredictiveInterface in the Help window for examples of its usage. Note: This feature can be disabled by selecting the Advanced tab in the Preferences window. Then the Open Option Inspector is chosen and the Editing Options is selected. Under Private Editing Options, the box to the right of ShowCodeAssist is clicked so that its value reads False.

Insert to Page 126 [Before Example 4.19]

Consider an ordinary differential equation in terms of y(x). If the differential equation is denoted eqn and the boundary conditions are denoted bc, then the symbolic solution can be obtained with

solV=DSolveValue[{eqn,bc},y[x],x]

The symbolic solution given by solV is the same as that obtained from

sol=y[x]/.DSolve[{eqn,bc},y,x][[1]]

Notice that in DSolveValue the dependent variable is specified as y[x] whereas in the DSolve it is specified as y. Thus, in Examples 4.19 to 4.24, these two constructs can be used interchangeably.

Insert to Page 151 [New section between Sections 5.1 and 5.2]

S.1 Creating Regions and Volumes of Arbitrary Shape Regions and volumes of arbitrary shape can be created as follows. If condxy is a conditional function of x and y, then the basic region creation commands are

reg=ImplicitRegion[condxy,{x,y}]

for all x and y that satisfy condxy or

reg=ImplicitRegion[condxy,{{x,a,b},{y,c,d}}]

for all a ≤ x ≤ b and c ≤ y ≤ d that satisfy condxy. When condxyz is a conditional function of x, y, and z, then the basic volume creation commands are

vol=ImplicitRegion[condxyz,{x,y,z}]

© 2014 John Wiley & Sons, Ltd

Page 6: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

6

for all x, y, and z that satisfy condxyz or

vol=ImplicitRegion[condxyz,{{x,a,b},{y,c,d},{z,e,f}}]

for all a ≤ x ≤ b, c ≤ y ≤ d, and e ≤ z ≤ f that satisfy condxyz. For those regions that can be defined parametrically,

reg=ParametricRegion[{{f1,f2},a≤p1≤b && c≤p2≤d}]

where, in general, f1 and f2 are functions of the parameters p1 and p2. There are several region manipulation commands that can be used one or more times to create regions of arbitrary shape. To create volumes of arbitrary shape, regN appearing in the definitions below is replaced with volN.

Union

To form the union of N (≥ 2) regions reg1, reg2, …, regN, one uses

reg=RegionUnion[reg1,reg2,...]

Intersection

To determine the region resulting from the intersection of N (≥ 2) regions reg1, reg2, …, regN, one uses

reg=RegionIntersection[reg1,reg2,...]

Difference

To determine the region resulting from the difference of two regions reg1 and reg2, one uses

reg=RegionDifference[reg1,reg2]

Examples of the use of these region creation commands are given in Table S.6 and examples of the use of these commands to create volumes are given in Table S.7. The regions have been plotted using RegionPlot, which is introduced in Table 6.2 and the volumes with RegionPlot3D, which is used in a manner similar to RegionPlot.

Insert to Page 152 [Before: Important option:]

When the integration of a function h is performed over a region reg, which is created in the manner shown in Section S.1, the numerical integration is performed with

NIntegrate[h,{x,y}∈reg,opts]

When the integration of a function h is performed over a volume vol, which is created in the manner shown in Section S.1, the numerical integration is performed with

NIntegrate[h,{x,y,z}∈vol,opts]

© 2014 John Wiley & Sons, Ltd

Page 7: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

7

Table S.6 Examples of commands that create regions of arbitrary shape

Operation Mathematica statements Result

1

Create three regions: Ellipse (reg1) Circle (reg2) Rectangle (reg3)

reg1=ImplicitRegion[y^2 +(x/2)^2<=1,{x,y}]; reg2=ImplicitRegion[(y-0.5)^2 +(x-0.8)^2<=1,{x,y}]; reg3=ParametricRegion[{u,v}, {{u,-1.6,-0.7},{v,-1,0.8}}]; RegionPlot[{reg1,reg2,reg3}]

2 Union of reg1 and reg2

reg1u2=RegionUnion[reg1,reg2]; RegionPlot[reg1u2]

3 Intersection of reg1 and reg2

reg1i2=RegionIntersection[reg1, reg2]; RegionPlot[reg1i2]

4 Difference of reg1 and reg2

reg1d2=RegionDifference[reg1, reg2]; RegionPlot[reg1d2]

5 Difference of reg1 and reg2 and union of reg3

reg1d2=RegionDifference[reg1, reg2]; reg1d2u3=RegionUnion[reg3, reg1d2]; RegionPlot[reg1d2u3]

These two forms of NIntegrate provide a very straightforward way to integrate over regions and volumes of arbitrary shape. Based on this capability, Mathematica has introduced several special- purpose functions to simplify the determination of area, volume, and centroid. These commands are introduced in Section S.2.

Example S.1

Area Moment of Inertia

The area moment of inertia of a region about the x-axis in the Cartesian coordinate system is determined from

-2 -1 0 1 2-1.0

-0.5

0.0

0.5

1.0

1.5

-2 -1 0 1 2-1.0

-0.5

0.0

0.5

1.0

1.5

-2 -1 0 1 2-1.0

-0.5

0.0

0.5

1.0

1.5

-2 -1 0 1 2-1.0

-0.5

0.0

0.5

1.0

1.5

-2 -1 0 1 2-1.0

-0.5

0.0

0.5

1.0

1.5

© 2014 John Wiley & Sons, Ltd

Page 8: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

8

Table S.7 Examples of commands that create volumes of arbitrary shape

Operation Mathematica statements Result

1 Create two volumes: Cube (veg1) Ellipsoid (veg2)

veg1=ParametricRegion[{u,v,w}, {{u,0,1},{v,0,1},{w,0,1}}]; veg2=ImplicitRegion[ ((x-0.85)/1.2)^2+ ((y-0.25)/2)^2+(z-0.5)^2<=0.1, {x,y,z}]; RegionPlot3D[{veg1,veg2}]

2 Union of veg1 and veg2

veg1u2=RegionUnion[veg1,veg2]; RegionPlot3D[veg1u2]

3 Intersection of veg1 and veg2

veg1i2=RegionIntersection[veg1, veg2]; RegionPlot3D[veg1i2]

4 Difference of veg1 and veg2

veg1d2=RegionDifference[veg1, veg2]; RegionPlot3D[veg1d2]

Ixx = y2 dxdyR∫∫

Using this relation, the area moment of inertia of the region given by Case 5 of Table S.6 is determined from the following program

��������

0.0

0.5

1.0

0.0

0.5

1.0

0.0

0.5

1.0

��������

0.0

0.5

1.0

-0.5

0.0

0.5

1.0

0.0

0.5

1.0

��������

0.0

0.5

1.0

-0.5

0.0

0.5

1.0

0.0

0.5

1.0

��������

0.0

0.5

1.0

-0.5

0.0

0.5

1.0

0.0

0.5

1.0

© 2014 John Wiley & Sons, Ltd

Page 9: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

9

reg1=ImplicitRegion[y^2+(x/2)^2<=1,{x,y}]; reg2=ImplicitRegion[(y-0.5)^2+(x-0.8)^2<=1,{x,y}]; reg3=ParametricRegion[{u,v},{{u,-1.6,-0.7},{v,-1,0.8}}]; reg1d2=RegionDifference[reg1,reg2]; reg1d2u3=RegionUnion[reg3,reg1d2];

Chop[NIntegrate[y^2,{x,y}∈reg1d2u3]]

which displays 1.25357. The Chop command is used to eliminate the extremely small imaginary part that results from the solution method. The coordinates (xC, yC) of the centroid of a region are defined as

xC = 1

Axdxdy

R∫∫

yC = 1A

ydxdyR∫∫

where

A = dxdyR∫∫

Thus, to determine the centroid of the region given by Case 5 of Table S.6, we use the following program assuming that reg1d2u3 determined previously hasn’t been cleared

aA=NIntegrate[1,{x,y}∈reg1d2u3]; Print["A= ",Chop[aA]]

Print["xC= ",Chop[NIntegrate[x,{x,y}∈reg1d2u3]/aA]]

Print["yC= ",Chop[NIntegrate[y,{x,y}∈reg1d2u3]/aA]]

which displays

A= 4.23633 xC= -0.458755 yC= -0.173836

Knowing the location of the centroid of the region, one can now determine the area moment of inertia about a line that passes through this point and is parallel to, say, the x-axis by using the parallel axis theorem; that is,

IxCxC = Ixx − xC2A

where, from our previous results, Ixx = 1.25357, xC = −0.458755, and A = 4.23633. It is mentioned that the area and the centroid of the region can be determined more directly using Area and RegionCentroid, which are introduced in Section S.2.

© 2014 John Wiley & Sons, Ltd

Page 10: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

10

Insert to Page 154 [New section after Figure 5.2]

S.2 Determining Properties of Curves, Regions, and Volumes There are several special purpose versions of NIntegrate that determine various properties of regions and volumes of arbitrary shape: area (Area), volume (Volume), and centroid (RegionCentoid). These regions and volumes can be the graphic primitives given in Tables 6.11 and 6.21 or those created by using the commands illustrated in Tables S.6 and S.7. In addition, commands have been introduced to determine the arc length of curves using ArcLength and the perimeters of regions using RegionBoundary and ArcLength. We shall now introduce and illustrate these commands by determining the various properties of the region shown in Case 5 of Table S.6 and the volume shown in Case 4 of Table S.7.

Area

If reg is a two-dimensional region, the area of reg is determined from

Area[reg]

For example, to determine the area of the region represented by Case 5 of Table S.6, the program is

reg1=ImplicitRegion[y^2+(x/2)^2<=1,{x,y}]; reg2=ImplicitRegion[(y-0.5)^2+(x-0.8)^2<=1,{x,y}]; reg3=ParametricRegion[{u,v},{{u,-1.6,-0.7},{v,-1,0.8}}]; reg1d2=RegionDifference[reg1,reg2]; reg1d2u3=RegionUnion[reg3,reg1d2];

Area[reg1d2u3]

which displays 4.23633.

Volume

When a region denoted vol is a three-dimensional shape, then its volume is determined from

Volume[vol]

For example, if the three-dimensional shape it that shown in Case 4 of Table S.7, then its volume is determined from

veg1=ParametricRegion[{u,v,w},{{u,0,1},{v,0,1},{w,0,1}}]; veg2=ImplicitRegion[((x-0.85)/1.2)^2+((y-0.25)/2)^2 +(z-0.5)^2<=0.1,{x,y,z}]; veg1d2=RegionDifference[veg1,veg2]; Volume[veg1d2]

which displays 0.808752.

© 2014 John Wiley & Sons, Ltd

Page 11: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

11

Centroid

To determine the coordinates (xC, yC) of the centroid of a region (as defined in Example S.1), which is denoted reg, one uses

{xC,yC}=RegionCentroid[reg]

where xC = xC and yC = yC. For example, the coordinates of the region represented by Case 5 of Table S.6, is determined from the following program, assuming that reg1d2u3 determined previously hasn’t been cleared

RegionCentroid[reg1d2u3]

The output is {-0.458755,-0.173836}. Thus, xC = −0.458755 and yC = −0.173836, which agree with those obtained in Example S.1. To determine the coordinates (xC, yC, zC) of the centroid of a three-dimensional shape vol, the command is

{xC,yC,zC}=RegionCentroid[vol]

For example, the coordinates of the centroid of the volume shown Case 4 of Table S.7 is obtained from the following program, assuming that veg1d2 determined previously hasn’t been cleared

RegionCentroid[veg1d2]

The output is {0.433809,0.531494,0.5}; thus, xC = 0.433809, yC = 0.531494, and zC = 0.5.

Arc Length and Perimeter

The arc length of a two-dimensional curve expressed in parametric form is determined from

ArcLength[{x,y},{p,pmin,pmax}]

and that for a three-dimensional curve

ArcLength[{x,y,z},{p,pmin,pmax}]

where x = x(p), y = y(p), z = z(p), p is the parameter, pmin is the minimum value of p, and pmax is the maximum value of p. As an example, consider the curve shown in Figure 6.27, which is described by

x = a(1+ cosϕ )y = asinϕz = 2asin(ϕ / 2)

where 0 ≤ ϕ ≤ 4π. If we let a = 1, then the program to determine the length of this spatial curve is

a=1.;

ArcLength[{a (1+Cos[ϕ]),a Sin[ϕ],2 a Sin[ϕ/2]},{ϕ,0,4 π}]

which yields 15.2808.

© 2014 John Wiley & Sons, Ltd

Page 12: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

12

ArcLength can also be used to determine the perimeter of a region reg of arbitrary shape with the use of

RegionBoundary[reg]

as follows

ArcLength[RegionBoundary[reg]]

For example, to determine the perimeter of the region given by Case 5 of Table S.6, assuming that reg1d2u3 determined previously has not been cleared, we use

ArcLength[RegionBoundary[reg1d2u3]]

which gives 11.8449.

Insert to Page 178 [New section between Sections 5.3 and 5.4]

S.3 Solving Second-Order partial Differential Equations with Finite Elements S.3.1 Creating Finite Element Meshed Regions

The command NDSolveValue has the ability to solve a general class of second-order linear partial differential equations over a region of arbitrary shape using finite elements. One part of this method consists of being able to convert a region created by those commands appearing in Tables 6.11 and 6.21 or those generated by the commands illustrated in Tables S.6 and S.7 into a mesh of interconnected two-dimensional regions or three-dimensional shapes. Options are available to choose the mesh elements to be different than the default elements. The results of the commands used to create meshed regions and volumes are primarily for use in NDSolveValue. To use these mesh generation commands, one must first load the appropriate package by executing

Needs["NDSolve`FEM`"]

The boundary of a region reg is converted to a boundary mesh using

bmesh=ToBoundaryMesh[reg,opt]

and to an element mesh of the entire region reg using either

mesh=ToElementMesh[reg,opt]

or

mesh=ToElementMesh[bmesh,opt] (* bmesh obtained from above *)

where mesh and bmesh are user-selected variable names and opt are options. Two options that can be used to refine the mesh are

© 2014 John Wiley & Sons, Ltd

Page 13: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

13

"BoundaryMeshGenerator"->{"Continuation"}

which is good for handling those boundaries that have cusps, corners, and abrupt changes and

"MeshRefinementFunction"->fcn

which is used to refine the mesh or portions of it. The function fcn is usually of the form

fcn=Function[{v,m},Block[{x,y},cond]]

where v is a list of vertices of the mesh elements and m is a measure of the mesh element (area or volume), Block is used to make x and y local variables within the funciton and cond is a condition test on x and/or y such that depending on the results of the condition test the appropriate m is selected. The results from ToBoundaryMesh and ToElementMesh, respectively, can be displayed with the following syntax

bmesh["Wireframe"]

and mesh["Wireframe"]

where bmesh and mesh are user-selected names as indicated above. We shall illustrate these commands with the following examples that use the region described by Case 5 of Table S.6, and which we shall denote R5. The first example will illustrate the need for option "BoundaryMeshGenerator" by determining and displaying the boundary of R5 with and without this option. The program is

Needs["NDSolve`FEM`"] reg1=ImplicitRegion[y^2+(x/2)^2<=1,{x,y}]; reg2=ImplicitRegion[(y-0.5)^2+(x-0.8)^2<=1,{x,y}]; reg3=ParametricRegion[{u,v},{{u,-1.6,-0.7},{v,-1,0.8}}]; reg1d2=RegionDifference[reg1,reg2]; reg1d2u3=RegionUnion[reg3,reg1d2]; bmeshwo=ToBoundaryMesh[reg1d2u3]; bmeshwo["Wireframe"] bmeshw=ToBoundaryMesh[reg1d2u3,"BoundaryMeshGenerator"-> {"Continuation"}];

bmeshw["Wireframe"]

which displays the boundaries shown in Figure S.1. To generate the default mesh of the region given in Figure S.1(b), we use the following statements, assuming that bmeshw determined previously has not been cleared

meshw=ToElementMesh[bmeshw]

mesh1["Wireframe"]

The result is shown in Figure S.2.

© 2014 John Wiley & Sons, Ltd

Page 14: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

14

(a) (b) Figure S.1 Effect of the option "BoundaryMeshGenerator"->{"Continuation"} on a region boundary with cusps (a) without the option; (b) with the option

Figure S.2 The result of using default triangular mesh elements on the region shown in Figure S.1(b) The second example will illustrate how to refine the default mesh resolution shown in Figure S.2. It is seen from the figures in Table S.6 that the limits of R5 are −2 ≤ x ≤ 2 and −1 ≤ y ≤ 1.5. We shall show how to specify the mesh refinement option so that the region −0.5 ≤ x ≤ 2 and −1 ≤ y ≤ 1.5 is finer than the region−2 ≤ x ≤ −0.5 and −1 ≤ y ≤ 1.5, which in turn is finer than the default mesh. Assuming that the region given by reg1d2u3 has not been cleared, the program is

fcn=Function[{v,m},Block[{x,y},{x,y}=Mean[v]; If[-0.5<=x<=2&&-1<=y<=1.5,m>0.002,m>0.005]]]; mesh3=ToElementMesh[reg1d2u3,"BoundaryMeshGenerator"-> {"Continuation"},"MeshRefinementFunction"->fcn]; mesh3["Wireframe"]

The result is shown in Figure S.3.

S3.2 Solving a Class of Linear Second-Order Partial Differential Equations over Regions

The command NDSolveValue can solve numerically a class of linear second-order partial differential equations in regions of arbitrary shape in either two or three dimensions using finite

© 2014 John Wiley & Sons, Ltd

Page 15: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

15

Figure S.3 Result of refining the default triangular mesh elements of the region shown in Figure S.2 elements.1 The regions can be created as shown Tables S.6 and S.7 or, when the characteristics of the default meshes are modified, using the commands introduced in Section S.2.1. The general form of the partial differential equation with one dependent variable that can be solved is

m ∂2u∂t 2

+ d ∂u∂t

+∇⋅ −c ⋅∇u −αu + γ( ) + β ⋅∇u + au − f = 0 (S.1)

where ∇ is the gradient, the coefficients m, d, a, and f are scalar functions of time and space, the coefficients α , γ , and β are vectors, and c is an n×n matrix. The solution to Eq. (S.1) is obtained using NDSolveValue. For specificity, we shall let u = u(t,x,y) and set α = α1i + α2j, β = β1i + β2j, γ = γ1i + γ2j, and let the elements of c be cij. Then, Eq. (S.1) in Cartesian coordinates is represented as

eqn=m D[u[t,x,y],t,t]+d D[u[t,x,y],t] +Div[-{{c11,c12},{c21,c22}}.Grad[u[t,x,y],{x,y}]

-{α1,α2} u[t,x,y]+{γ1,γ2},{x,y}]+{β1,β2}.Grad[u[t,x,y],{x,y}]

+a u[t,x,y]-f

When this statement is executed, the following is displayed

-f+a u[t,x,y]-α2 u(0,0,1)[t,x,y]+β2 u(0,0,1)[t,x,y]

-c22 u(0,0,2)[t,x,y]-α1 u(0,1,0)[t,x,y]+β1 u(0,1,0)[t,x,y] -c12 u(0,1,1)[t,x,y]-c21 u(0,1,1)[t,x,y]-c11 u(0,2,0)[t,x,y]

+d u(1,0,0)[t,x,y]+m u(2,0,0)[t,x,y]

When there are two dependent variables u and v, the general form of the coupled partial differential equation that can be solved is

1 For a detailed discussion of this capability, the implementation of the boundary conditions, and several examples, refer to the tutorial FEMDocumentation/tutorial/SolvingPDEwithFEM in the Help window.

© 2014 John Wiley & Sons, Ltd

Page 16: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

16

∇⋅ −e11 ⋅∇u − e12 ⋅∇v −α11u +α12v + γ 1( ) + β11 ⋅∇u + β12 ⋅∇v + a11u + a12v − f1 = 0

∇⋅ −e21 ⋅∇u − e22 ⋅∇v −α 21u +α 22v + γ 2( ) + β21 ⋅∇u + β22 ⋅∇v + a21u + a22v − f2 = 0 (S.2)

where the coefficients α ij, γ i, and β ij are vectors, eij are n×n matrices, and fi are scalars. There are many special cases of Eq. (S.1) that reduce to well-known equations of physics and engineering. For example, when α = γ = β = 0, n = 2, c12 = c21 = 0, and c11 = c22 = co, Eq. (S.1) simplifies to

co∇2u −m ∂2u

∂t 2− d ∂u

∂t− au + f = 0 (S.3)

where

∇2 = ∂2

∂x2+ ∂2

∂y2 (S.4)

It is seen that several well-known equations are special cases of Eq. (S.3). For example, when: (1) m = d = f = 0, we have the Helmholtz equation; (2) d = a = f = 0, we get the wave equation; (3) m = d = a = 0, we obtain the Poisson equation; (4) m = d = f = a = 0, we arrive at the Laplace equation; and (5) when m = a = f = 0, we have the diffusion equation. When Eq. (S.1) is in the form of Eq. (S.3), its representation in Mathematica can be simplified with the use of Laplacian so that Eq. (S.3) can be represented as

eqn=-m D[u[t,x,y],t,t]-d D[u[t,x,y],t]-a u[t,x,y]+f

+co Laplacian[u[t,x,y],{x,y}]

The boundary conditions can be specified as either a Dirichlet boundary condition or a Neumann boundary condition. We shall denote the Dirichlet boundary condition as bcD and the Neumann boundary condition as bcNeu. If the dependent variable of the differential equation is u, then the Dirichlet boundary condition specifies u on the entire boundary or on portions of the boundary. The Neumann boundary condition is

n ⋅ −c ⋅∇u −αu + γ( )

where n is a vector that is normal to the boundary. In Mathematica, this relation is replaced with g − qu and, as shown subsequently, always appears on the right hand side of Eq. (S.1) when appearing in the argument of NDSolveValue. Thus,

n ⋅ −c ⋅∇u −αu + γ( ) = g − qu (S.5)

For the case of two dependent variables, the Neumann boundary conditions in Mathematica are approximated by

n ⋅ −e11 ⋅∇u − e12 ⋅∇v −α11u +α12v + γ 1( ) = g1 − q1un ⋅ −e21 ⋅∇u − e22 ⋅∇v −α 21u +α 22v + γ 2( ) = g2 − q2v

(S.6)

© 2014 John Wiley & Sons, Ltd

Page 17: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

17

The Dirichlet boundary conditions are specified with

bcD=DirichletCondition[u[t,x,y]==b1,bc1]

or

bcD={DirichletCondition[u[t,x,y]==b1,bc1], DirichletCondition[u[t,x,y]==b2,bc2],...}

where bN is the value of u on the portion of the boundary given by bcN. The Neumann boundary conditions are specified with

bcNeu=NeumannValue[g1-q1 u[t,x,y],bc1]

+NeumannValue[g2-q2 u[t,x,y],bc2]+...

where gN and qN are specified. Before obtaining the solution, the finite element package needed by NDSolveValue must be loaded by executing

Needs["NDSolve`FEM`"]

Then, with these definitions, the solution to Eq. (S.1) for the two-dimensional spatial region reg is obtained by using

solu=NDSolveValue[{eqn==bcN,bcD,ic0,ic1},u,{t,tmn,tmx},

{x,y}∈reg];

where tmn and tmx, respectively, are the minimum and maximum values of t, ic0 and ic1, respectively, are the initial conditions given by

ico=u[0,x,y]==f0[x,y];

ic1=Derivative[1,0,0][u][0,x,y]==f1[x,y]

and f0[x,y] and f1[x,y] are specified. The initial condition ic1 is omitted when m = 0 in Eq. (S.1). When Eq. (S.1) is independent of time; that is, m = d = 0,

solu=NDSolveValue[{eqn==bcN,bcD},u,{x,y}∈reg];

We shall illustrate these commands with several examples.

Example S.2

Steady-State Temperature Distribution in a Slab with a Circular Hole

We shall determine the steady-state temperature distribution in a rectangular region represented by the non-dimensional coordinates 0 ≤ η ≤ ηe and −β ≤ ξ ≤ β. Within this region there is a circular hole of non-dimensional radius rh that has its center at (ηh,ξh). The governing equation is

© 2014 John Wiley & Sons, Ltd

Page 18: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

18

Figure S.4 Steady-state temperature distribution in a rectangular region with a hole. A temperature distribution has been specified along the left and bottom edges of the rectangular region and on the perimeter of the hole a constant temperature has been specified.

∇2u = ∂2u∂η2 +

∂2u∂ξ 2

= 0

where u = u(η,ξ) is the non-dimensional temperature. The boundary conditions are assumed to be

u(η,β ) = u(ηe,ξ ) = 0u(0,ξ ) = 2sin π (ξ + β ) / (2β )( )

u(η,−β ) = 2sin πη /ηe( )u(η,ξ ) = 1.8 (η −ηh )2 + (ξ −ξh )2 = rh

2

These are all Dirichlet boundary conditions. The program to solve for the temperature distribution, which is displayed as a plot of contours of constant temperature, is as follows. It is assumed that ηe = 1.5, β = 2, rh = 0.25, ηh = 0.5, and ξh = 0.35. The results are shown in Figure S.4.

0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4

-2

-1

0

1

2

© 2014 John Wiley & Sons, Ltd

Page 19: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

19

Needs["NDSolve`FEM`"] (* Execute if not done previously *)

xe=1.5; bet=2.; rh=0.25; xh=0.5; yh=0.35; flow1=ImplicitRegion[0<=x<=xe&&- bet<=y<= bet,{x,y}]; flow2=ImplicitRegion[(x-xh)^2+(y-yh)^2<=rh^2,{x,y}]; flow=RegionDifference[flow1,flow2]; dir1= DirichletCondition[temp[x,y]==0,x==xe]; dir2=DirichletCondition[temp[x,y]==2 Sin[0.5 Pi (y+bet)/bet], x==0]; dir3=DirichletCondition[temp[x,y]==0,y==bet]; dir4=DirichletCondition[temp[x,y]==2 Sin[Pi x/ xe],y==-bet] dir5=DirichletCondition[temp[x,y]==0,(x-xh)^2+(y-yh)^2==rh^2] dirc={dir1,dir2,dir3,dir4,dir5}; flo=NDSolveValue[{Laplacian[temp[x,y],{x,y}]==0,dirc},temp,

{x,y}∈flow];

ContourPlot[flo[x,y],{x,y}∈flow,AspectRatio->Automatic, ColorFunction->"TemperatureMap"]

The plotting command ContourPlot is introduced in Table 6.2 and ColorFunction is discussed in Section 6.2.2.

Example S.3

Torsion of Channel Beams

We shall determine the shear stresses due to the torsion of a channel beam, the cross section of which is shown in Figure S.5. If the coordinates of the cross section of the channel beam are (η,ξ), the governing non-dimensional equation from which the shear stresses can be determined is

∇2Z = ∂2Z∂η2 + ∂2Z

∂ξ 2 = −2 0 ≤η ≤1, −α ≤ ξ ≤α

where α > 0 and Z is the non-dimensional displacement perpendicular to the plane of the cross section of the beam. The non-dimensional shear stresses are given by

τ yz = − ∂Z

∂η

τ xz =∂Z∂ξ

The boundary conditions are that Z = 0 on the entire boundary. When the Dirichlet boundary conditions are the same around the entire boundary of a region, Mathematica provides a concise way to specify them with the following syntax

© 2014 John Wiley & Sons, Ltd

Page 20: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

20

Figure S.5 Geometry of the cross section of a channel beam

bcD=DirichletCondition[z[x,y]==0,True]

The program that determines the shear stresses and displays the results shown in Figure S.6 when α = 2, β = 0.5, and rf = 0.2 is

Needs["NDSolve`FEM`"] (* Execute if not done previously *)

α=2; β=0.5; rf=0.2;

reg1=ImplicitRegion[-1<=x<=1&&-α<=y<=α,{x,y}];

reg2=ImplicitRegion[-1+β<=x<=1&&-α+β<=y<=α-β,{x,y}]; regd=RegionDifference[reg1,reg2];

regr1=ImplicitRegion[!((x-(-1+β+rf))^2+(y-(α-β-rf))^2<=rf^2),

{{x,-1+β,-1+β+rf},{y,α-β-rf,α-β}}];

regr2=ImplicitRegion[!((x-(-1+β+rf))^2+(y-(-α+β+rf))^2<=rf^2),

{{x,-1+β,-1+β+rf},{y,-α+β,-α+β+rf}}]; regc=RegionUnion[regd,regr1,regr2]; regcb=ToBoundaryMesh[regc]; reg=ToElementMesh[regcb]; oper=Laplacian[z[x,y],{x,y}]+2; dir=DirichletCondition[z[x,y]==0,True];

p=NDSolveValue[{oper==0,dir},z,{x,y}∈reg];

GraphicsRow[{ContourPlot[D[p[w,y],w]/.w->x,{x,y}∈reg, Contours->10,AspectRatio->Automatic],

ContourPlot[D[p[x,w],w]/.w->y,{x,y}∈reg,Contours->10, AspectRatio->Automatic]}]

1 1

α

α

rf β

β

β

rf

(−1 + β + rf, α − β − rf)

(−1 + β + rf, −α + β + rf)

η

ξ

© 2014 John Wiley & Sons, Ltd

Page 21: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

21

(a) (b)

Figure S.6 Non-dimensional shear stress in the cross section of a channel beam subject to torsion (a) τ yz ; (b) τ xz

The command GraphicsRow is illustrated in Table 6.17.

Example S.4

Stress Distribution in a Plate with a Hole Subjected to an In-Plane Tensile Force2

We shall determine the von Mises stress around a hole in a thin rectangular plate when the plate is subjected to a tensile force in the plane of the plate. We let u, v, and w be the respective displacements of an elastic body in the x-, y-, and z-directions, and σxx, σyy, and σzz be the corresponding normal stresses in these directions. To describe the thin plate, we consider the case of plane stress for which σzz = 0, u = u(x,y), v = v(x,y), and w = 0. In this case, the stress-displacement relations reduce to

σ xx =E

1−ν 2∂u∂x

+ν ∂v∂y

⎛⎝⎜

⎞⎠⎟

σ yy =E

1−ν 2∂v∂y

+ν ∂u∂x

⎛⎝⎜

⎞⎠⎟

τ xy = G∂u∂y

+ ∂v∂x

⎛⎝⎜

⎞⎠⎟

(S.7)

where τxy is the shear stress in the x-y plane, E is the Young’s modulus, ν is Poisson’s ratio, and 2 See also Example 7.4.

���������

-1.0 -0.5 0.0 0.5 1.0-2

-1

0

1

2

-1.0 -0.5 0.0 0.5 1.0-2

-1

0

1

2

© 2014 John Wiley & Sons, Ltd

Page 22: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

22

G = E2(1+ν )

= E(1−ν )2(1−ν 2 )

(S.8)

For plane stress, the equations of equilibrium become

∂σ xx

∂x+∂τ xy

∂y= 0

∂τ yx

∂x+∂σ yy

∂y= 0

(S.9)

Substituting Eq. (S.7) into Eq. (S.9) yields

E1−ν 2

∂2u∂x2

+ E(1+ν )2 1−ν 2( )

∂2v∂x∂y

+G ∂2u∂y2

= 0

G ∂2v∂x2

+ E(1+ν )2 1−ν 2( )

∂2u∂x∂y

+ E1−ν 2

∂2v∂y2

= 0 (S.10)

Using a straightforward procedure, Eq. (S.10) is placed in the form given by Eq. (S.2). Then the first equation of Eq. (S.10) becomes

∇⋅

E1−ν 2 0

0 E(1−ν )2(1−ν )2

⎜⎜⎜⎜

⎟⎟⎟⎟

⋅∇u +0 Eν

1−ν 2

E(1−ν )2 1−ν 2( ) 0

⎜⎜⎜⎜

⎟⎟⎟⎟⋅∇v

⎜⎜⎜⎜⎜

⎟⎟⎟⎟⎟

= 0

with the boundary condition given by

n ⋅ σ xxi +τ xy j( ) = g1 − q1u

and the second equation of Eq. (S.10) becomes

∇⋅0 E(1−ν )

2 1−ν 2( )νE1−ν 2 0

⎜⎜⎜⎜

⎟⎟⎟⎟⋅∇u +

E(1−ν )2(1−ν 2 )

0

0 E1−ν 2

⎜⎜⎜⎜

⎟⎟⎟⎟

⋅∇v

⎜⎜⎜⎜⎜

⎟⎟⎟⎟⎟

= 0

with the boundary condition given by

n ⋅ τ xyi +σ yy j( ) = g2 − q2v

The von Mises stress is given by

σ vm = σ xx2 −σ xxσ yy +σ yy

2 + 3τ xy2

© 2014 John Wiley & Sons, Ltd

Page 23: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

23

Figure S.7 Modified mesh of a rectangular region with a circular hole We shall determine the stress contours in a rectangular region 1.1 ≤ x ≤ 1.1 and 0.5 ≤ y ≤ 0.5 that is centered about the origin. The hole has a radius rh = 0.25 and is also centered at the origin. We shall assume that E = 1 and ν = 0.33. The in-plane tensile stress is applied in the x-direction and has a magnitude of 0.001. The normal stress on the boundary at y = ±0.5 is zero. Both of these boundary conditions are Neumann boundary conditions. The mesh about the hole from rh to 1.5rh is modified as shown in Figure S.7. The program used to determine the von Mises stress is given below. The results are shown in Figure S.8, where it is seen that the stress contours exhibit similar attributes to those shown in Figure 7.4.

Needs["NDSolve`FEM`"] (* Execute if not done previously *)

eE=1; ν=0.33; xo=1.1; yo=0.5; force=0.001; r1=0.25;

c={{eE/(1-ν^2),0},{0,0.5 eE (1-ν)/(1-ν^2)}};

d={{0,eE ν/(1-ν^2)},{0.5 eE (1-ν)/(1-ν^2),0}};

e={{0,0.5 eE (1-ν)/(1-ν^2)},{eE ν/(1-ν^2),0}};

f={{0.5 eE (1-ν)/(1-ν^2),0},{0,eE/(1-ν^2)}}; eqn1=Div[c.Grad[u[x,y],{x,y}],{x,y}] +Div[d.Grad[v[x,y],{x,y}],{x,y}]; eqn2=Div[e.Grad[u[x,y],{x,y}],{x,y}] +Div[f.Grad[v[x,y],{x,y}],{x,y}]; reg=ImplicitRegion[!(x^2+y^2<=r1^2),{{x,-xo,xo},{y,-yo,yo}}]; mesh=ToElementMesh[reg,MeshRefinementFunction-> Function[{vert, area},Block[{x,y},{x,y}=Mean[vert]; If[r1^2<=x^2+y^2<=(1.5 r1)^2,area>0.001,area>0.03]]]]; mesh["Wireframe"] {uU,vV}=NDSolveValue[{eqn1==NeumannValue[-force,x==-xo] +NeumannValue[force,x==xo],eqn2==0},

{u,v},{x,y}∈mesh,InterpolationOrder->All]; sigx=D[uU[v,y],v]/.v->x+ν D[vV[x,w],w]/.w->y;

sigy=D[vV[x,v],v]/.v->y+ν D[uU[w,y],w]/.w->x;

© 2014 John Wiley & Sons, Ltd

Page 24: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

24

Figure S.8 von Mises stress contours in a rectangular region with a circular hole subjected to an in-plane tensile force

tauxy=0.5 (1-ν) ( D[vV[w,y],w]/.w->x+D[uU[x,w],w]/.w->y); vonmis=Sqrt[sigx^2-sigx sigy+sigy^2+3 tauxy^2];

ContourPlot[vonmis,{x,y}∈reg,AspectRatio->Automatic, Contours->10]//Quiet

Example S.5

Response of a Membrane to a Concentrated Impulse Force

We shall determine the displacement response of a membrane to an externally applied impulse force at a point on the membrane. The governing equation for the displacement response of a membrane is given by

∇2w = ∂2w∂η2 +

∂2w∂ξ 2

= ∂2w∂τ 2

− f (τ ,η,ξ )

where w(τ,η,ξ) is the displacement, f(τ,η,ξ) is force applied to the membrane, and η and ξ are the coordinates, and τ is time. These quantities are non-dimensional. The concentrated impulse force is approximated by

f (τ ,η,ξ ) = e−1000. t2+ η−η f( )2+ ξ−ξ f( )2( )

where (ηf,ξf) are the coordinates of the concentrated load. The shape of the membrane is created by the differences of an ellipse with two circles of equal diameter as shown in Figure S.9. We shall solve the governing equation for this region and display the displacement for τ = 0.85, ηf = 0.5, and ξf = 0.5 with the following program.

-1.0 -0.5 0.0 0.5 1.0

-0.4

-0.2

0.0

0.2

0.4

© 2014 John Wiley & Sons, Ltd

Page 25: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

25

Figure S.9 Membrane created by the difference of an ellipse and two circles

Needs["NDSolve`FEM`"] (* Execute if not done previously *) reg1=ImplicitRegion[(y)^2+(x/2)^2<=1,{x,y}]; reg2=ImplicitRegion[y^2+(x-1.8)^2<=1,{x,y}]; reg3=ImplicitRegion[y^2+(x+1.8)^2<=1,{x,y}]; reg=RegionDifference[RegionDifference[reg1,reg2],reg3]; mesh=ToElementMesh[reg]; xf=0.5; yf=0.5; f=Exp[-1000. ((x-xf)^2+(y-yf)^2+t^2)]; oper=Laplacian[w[t,x,y],{x,y}]-D[ w[t,x,y],t,t]+f; diri=DirichletCondition[w[t,x,y]==0,True]; solw=NDSolveValue[{oper==0,w[0,x,y]==0, Derivative[1,0,0][w][0,x,y]==0,diri},w,{t,0,6 Pi},

{x,y}∈mesh];

Plot3D[solw[0.85,x,y],{x,y}∈reg,PlotRange->All, PlotPoints->30]//Quiet

The results are shown in Figure S.10. The Plot3D command is illustrated in Table 6.19.

Insert to Page 178 [bottom]

The command NSolve can obtain the numerical solution to a system of equations that is restricted to a region or that directly involves a region’s boundary. The syntax for this capability is best shown through two examples. In the first example, we shall determine the coordinates of the intersections of a straight line with the boundary of the region described in Case 5 of Table S.6. This geometry is displayed in Figure S.11. The following program finds the locations of their intersections.

-2 -1 0 1 2-1.0

-0.5

0.0

0.5

1.0

© 2014 John Wiley & Sons, Ltd

Page 26: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

26

Figure S.10 Membrane response at τ = 0.85 when an impulse is applied at (0.5,0.5)

Figure S.11 Region given by Case 5 of Table S.6 and its intersection with a straight and the intersection of the straight line with an ellipse

reg1=ImplicitRegion[y^2+(x/2)^2<=1,{x,y}]; reg2=ImplicitRegion[(y-0.5)^2+(x-0.8)^2<=1,{x,y}]; reg3=ParametricRegion[{u,v},{{u,-1.6,-0.7},{v,-1,0.8}}]; reg4=ImplicitRegion[(y)^2+(x/0.6)^2==0.5,{x,y}]; reg1d2=RegionDifference[reg1,reg2]; reg1d2u3=RegionUnion[reg3,reg1d2]; inflin=InfiniteLine[{{-2,-0.9},{2,0.3}}];

{x,y}/.NSolve[{x,y}∈inflin&&{x,y}∈RegionBoundary[reg1d2u3], {x,y}]

-2 -1 0 1 2-1.0

-0.5

0.0

0.5

1.0

1.5

© 2014 John Wiley & Sons, Ltd

Page 27: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

27

where InfiniteLine is a function that creates an infinite line passing through two points specified in its argument. See Table S.8. The execution of the program gives

{{1.92197,0.276592},{-1.6,-0.78},{1.76251,0.228753},

{0.145747,-0.256276}}

For the second example, we shall determine the intersection of the straight line with an ellipse as shown in Figure S.11, except that we shall restrict the solution to lie within the shaded region shown in the figure. Assuming that the previously determined values for inflin, reg4, and reg1d2u3 have not been cleared, the program is

{x,y}/.NSolve[{{x,y}∈inflin && {x,y}∈reg4},{x,y}∈reg1d2u3][[1]]

It execution yields

{-0.348028,-0.404408}

Insert to Page 183 [before Example 5.22]

To find the minimum or maximum, respectively, of a function f = f(x,y) within a region reg, it is easier to use NMinimize and NMaximize, which are given by

NMinimize[{f,con},{x,y}∈reg]

and

NMaximize[{f,con},{x,y}∈reg]

where con are the constraints.

Example S.6

Maximum Values in Portions of a Region

We shall determine the location of the maximum vertical value of the boundary given by Case 5 of Table S.6 in the portion of the region x ≥ 0 and in the portion of the region x < 0. The program is

reg1=ImplicitRegion[y^2+(x/2)^2<=1,{x,y}]; reg2=ImplicitRegion[(y-0.5)^2+(x-0.8)^2<=1,{x,y}]; reg3=ParametricRegion[{u,v},{{u,-1.6,-0.7},{v,-1,0.8}}]; reg1d2=RegionDifference[reg1,reg2]; reg1d2u3=RegionUnion[reg3,reg1d2];

{x,y}/.Last[NMaximize[{y,x>=0},{x,y}∈reg1d2u3]]

{x,y}/.Last[NMaximize[{y,x<0},{x,y}∈reg1d2u3]]

© 2014 John Wiley & Sons, Ltd

Page 28: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

An Engineer’s Guide to Mathematica®

28

which gives for the region x ≥ 0 that x = 1.79807 and y = 0.437878 and for the region x < 0 that x = −0.0663433 and y = 0.99945. In this case, values of y are the respective maximum in each region.

Insert to Page 210 [bottom]

In the plotting commands listed in Tables 6.1 to 6.4 and Table 6.19, an option PlotTheme is available that makes use of one of eight overall plotting themes. This option appears in a plotting command as

PlottingCommand[... ,PlotTheme->"Theme"]

where PlottingCommand is the plotting command selected and "Theme" is the name of one of the eight themes: the quotations marks are required. The eight themes can be found by entering PlotTheme in the Help window search area. In addition, each of these eight themes can be individually modified further to obtain the “look” for the figure that one is seeking. These modifications can be applied to: the axes; curve colors, type, and thickness; all labeling; size and aspect ratio of figure; plot markers; and the mesh characteristics of surfaces of 3D plots. If desired, one can change the default theme for all figures by executing

$PlotTheme["Theme"]

One can employ $PlotTheme as often as desired within a notebook session.

Insert to Page 246 [bottom]

The command GraphicsComplex has been specialized to the following special cases: Prism, Hexahedron, Parallelepiped, Tetrahedron, and Pyramid. The advantage of using these commands is that it is not necessary to give the connectivity prim, just the coordinates of the vertices in a list ordered as indicated in the Help screen for each of these commands.

© 2014 John Wiley & Sons, Ltd

Page 29: An Engineer’s Guide to Mathematica - Homepage | Wiley · An Engineer’s Guide to Mathematica® 2 Introduction to Update Wolfram’s release of Mathematica 10 in July 2014 contained

Update to Mathematica 10

29

Addition to Table 6.11 on Page 221

Table S.8 Points, lines and built-in 2D shapes

Shape Mathematica function

Infinite line passing through points p1 and p2

InfiniteLine[{{x1,y1},{x2,y2}}]

Parallelogram

Parallelogram[{{x0,y0},{{x1,y1},{x2,y2}}] {x0,y0} = location of origin of parallelogram {x1,y1} = location of end of one side connected to {x0,y0} {x2,y2} = location of end of other side connected to {x0,y0}

Addition to Table 6.21 on Page 246

Table S.9 Lines and planes in three-dimensions

Shape Mathematica function

Infinite line passing through points p1 and p2

InfiniteLine[{{x1,y1,z1},{x2,y2,z2}]

Infinite plane passing through points p1, p2, and p3

InfinitePlane[{{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}}]

© 2014 John Wiley & Sons, Ltd