+ All Categories
Home > Documents > Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program...

Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program...

Date post: 18-Apr-2018
Category:
Upload: hadang
View: 217 times
Download: 2 times
Share this document with a friend
28
4 Plane Truss Analysis by a CAS 4–1
Transcript
Page 1: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

4Plane Truss

Analysisby a CAS

4–1

Page 2: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

TABLE OF CONTENTS

Page§4.1 Computer Algebra Systems . . . . . . . . . . . . . . . . 4–3

§4.1.1 Why Mathematica? . . . . . . . . . . . . . . . 4–3§4.1.2 How to Get It . . . . . . . . . . . . . . . . . 4–4§4.1.3 Programming Style and Prerequisites . . . . . . . . . 4–4§4.1.4 Class Demo Scripts . . . . . . . . . . . . . . . 4–5§4.1.5 Color Coding . . . . . . . . . . . . . . . . . 4–5§4.1.6 Expressions, Names and Symbols . . . . . . . . . . 4–5§4.1.7 Replacing and Assigning Values . . . . . . . . . . 4–7§4.1.8 Atoms and Lists . . . . . . . . . . . . . . . . 4–7§4.1.9 Matrices and Vectors . . . . . . . . . . . . . . 4–8§4.1.10 Functions and Modules . . . . . . . . . . . . . . 4–8

§4.2 Program Organization . . . . . . . . . . . . . . . . . 4–8

§4.3 Data Structures . . . . . . . . . . . . . . . . . . . . 4–8

§4.4 Plane Bar Stiffness Module . . . . . . . . . . . . . . . 4–9

§4.5 Plane Truss Stiffness Assembly . . . . . . . . . . . . . . 4–13

§4.6 Application of Boundary Conditions . . . . . . . . . . . . 4–15

§4.7 Solving For Displacements and Recovering The Full Force Vector . . 4–17

§4.8 Plane Bar Internal Force . . . . . . . . . . . . . . . . 4–17

§4.9 Plane Truss Internal Forces and Stresses . . . . . . . . . . . 4–18

§4.10 Display Utilities . . . . . . . . . . . . . . . . . . . 4–19§4.10.1 *Utility Print Modules . . . . . . . . . . . . . . 4–19§4.10.2 *Utility Plot Modules . . . . . . . . . . . . . . 4–19

§4.11 Putting the Pieces Together . . . . . . . . . . . . . . . 4–21

§4.12 Driver Scripts . . . . . . . . . . . . . . . . . . . . 4–21§4.12.1 Example Truss With All Numeric Data . . . . . . . . . 4–22§4.12.2 Example Truss With Symbolic Forces . . . . . . . . . 4–22§4.12.3 Is All of This Worthwhile? . . . . . . . . . . . . . 4–23

§4. Notes and Bibliography . . . . . . . . . . . . . . . . . 4–25

§4. References . . . . . . . . . . . . . . . . . . . . . . 4–26

§4. Exercises . . . . . . . . . . . . . . . . . . . . . . 4–27

4–2

Page 3: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.1 COMPUTER ALGEBRA SYSTEMS

§4.1. Computer Algebra Systems

Computer algebra systems, known by the acronym CAS, are programs designed to perform sym-bolic and numeric manipulations following the rules of mathematics.1 The development of suchprograms began in the mid 1960s. The first comprehensive system — the “granddaddy” of themall, called Macsyma (an acronym for Project Mac Symbolic Manipulator) — was developed usingthe programming language Lisp at MIT’s famous Artificial Intelligence Laboratory over the period1967 to 1980.

The number and quality of symbolic-manipulation programs has expanded dramatically since theavailability of graphical workstations and personal computers has encouraged interactive and ex-perimental programming. As of this writing the leading general-purpose contenders are Maple andMathematica.2 In addition there are a dozen or so more specialized programs, some of which areavailable free or at very reasonable cost. See Notes and Bibliography at the end of the Chapter.

§4.1.1. Why Mathematica?

In the present book Mathematica will be used for Chapters and Exercises that develop symbolicand numerical computation for matrix structural analysis and FEM implementations. Mathematicais a commercial product developed by Wolfram Research, web site: http://www.wolfram.com.The version used to construct the code fragments presented in this Chapter is 4.1, which wascommercially released in 2001. (Update: The latest version is 11, released in 2017.) The mainadvantages of Mathematica for technical computing are:

1. Availability on a wide range of platforms that range from PCs and Macs through Unix work-stations. At CU Boulder, it is available through a free campus license (see §4.1.2).

2. Up-to-date user interface. On all machines Mathematica offers a graphics user interfacecalled the Notebook front-end. This is mandatory for serious work. It provides professionaltypesetting for results.

3. A powerful programming language and excellent graphics.

4. Good documentation and abundance of application books at all levels.

One of the major advantages noted by the writer is that the same code can be used for symbolic andnumeric analysis, depending only on the data. This avoids the need to write two different programs,and facilitates testing.

One common disadvantage of CAS, and Mathematica is no exception, is computational inefficiencyin numerical calculations compared with a low-level implementation in, for instance, C or Fortran.The relative penalty can reach several orders of magnitude. For instructional use, however, thepenalty is acceptable when compared to human efficiency. This means the ability to get FEM

1 Some CAS vendors call that kind of activity “doing mathematics by computer.” It is more appropriate to regard suchprograms as enabling tools that help humans with complicated and error-prone manipulations. Mettle and metal. As ofnow, only humans can do mathematics.

2 Another widely used program for engineering computations: Matlab, does primarily numerical computations althoughan interface to a CAS can be purchased as a symbolic toolbox. Historical notes: Macsyma died as a commercial productin 1999, along with related codes (e.g. Vaxima), although the Lisp source code of some versions is freely available.The Maple developer company Waterloo Maple Inc., also known as Maplesoft, was purchased in 2009 by the Japanesesoftware retailer Cybernet Systems.

4–3

Page 4: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

Eligibility: students, faculty, staff and departments of all CU campusesPlatforms: Mac OSX, Windows, Linux, Solaris, AIX, HP-UX

How to Get It

1) Download and install software as per instructions at http://oit.colorado.edu/software-hardware/site-licenses/mathematicaor request an installation CD from the Site Licensing office: [email protected], 303-492-8995

2) Register your copy online at http://register.wolfram.com/ usingcampus license number L2437-5121 plus your computer MathID number.Be sure to use your CU mail address.

3) A password (unique to your computer) will be forwarded to you viaemail from Site Licensing

ITS Support

Question & tech support problems: send email to [email protected] hands-on workshops are available for those new to the software,click on Workshops on the Web page given above.Details (for example: what is a MathID?) about licensing & support are posted at the above web site.

Figure 4.1. Instructions to get Mathematica for free from CU-OIT (Office of InformationTechnology). One correction: the CD version is no longer available.

programs up and running in very short time, with capabilities for symbolic manipulation andpublication-quality graphics as a bonus. This makes both Mathematica and Matlab good choicesfor education and project prototyping.

§4.1.2. How to Get It

Starting August 2007, a free one-year license from CU’s Office of Information Technology (OIT)is available. Students may renew this license as long as they are registered. See Figure 4.1 for the“How to Get It” instructions.

If you plan to keep Mathematica for a longer time, an academic version may be available. Consultthe vendor.

One word of caution about the campus-licensed free copy: once installed on your laptop or desktop,it cannot be transferred to another computer since the license is forever keyed to the disk identifier.(For example, it won’t launch if the disk is rebuilt or replaced.)

§4.1.3. Programming Style and Prerequisites

The following material assumes that you are a moderately experienced user of Mathematica, orare willing to learn to be one. See Notes and Bibliography for a brief discussion of tutorial andreference materials in case you are interested.

The best way to learn it from scratch is trying it as a calculator and using online help as needed.Practice with the program until you reach the level of writing functions, modules and scripts with

4–4

Page 5: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.1 COMPUTER ALGEBRA SYSTEMS

relative ease. With the Notebook interface and a good primer it takes only a few hours. Whenapproaching that level you may notice that functions in Mathematica display many aspects similarto C and C++.3 You can exploit this similarity if you are proficient in either language. ButMathematica functions do have some unique aspects, such as matching arguments by pattern, andthe fact that internal variables are global unless otherwise made local.4

Modification of function arguments should be avoided because it may be difficult to trace sideeffects. The programming style enforced here outlaws output arguments and a function can onlyreturn its name. But since the name can be a list of arbitrary objects the restriction is not serious.5

Our objective is to develop a symbolic program written in Mathematica that solves the exampleplane truss as well as some symbolic versions thereof. The program will rely heavily on thedevelopment and use of functions implemented using the Module construct of Mathematica. Thusthe style will be one of procedural programming.6 The program will not be particularly modular(in the computer science sense) because Mathematica is not suitable for that programming style.7

The code presented in §4.2 through §4.11 uses a few language constructs that may be deemed asadvanced, and these are briefly noted in the text so that appropriate reference to the Mathematicaonline documentation can be made.

§4.1.4. Class Demo Scripts

The cell scripts shown in Figures 4.2 and 4.3 will be used to illustrate the organization of a Notebookfile and the “look and feel” of some basic Mathematica commands.

§4.1.5. Color Coding

Cell background color indicates the type of cell. Yellow, green and white backgrounds denote text,input and output cells, respectively. Sometimes a print output cell is backgrounded light yellow forcontrast when moved to a figure or document.

Text color in input cells (green background) also follow conventions. Black denotes working code,while blue text identifies module testing statements. Red text marks debugging statements, oftenPrint commands; these are usually commented out if left within working code.

§4.1.6. Expressions, Names and Symbols

Mathematica operates through expressions consisting of symbols and values.

3 No accident since Mathematica is written in C++. Simple functions can be implemented in Mathematica directly, forinstance DotProduct[x ,y ]:=x.y; more complicated ones are handled by the Module construct. Those constructsare called rules by computer scientists.

4 In Mathematica every operation that involves square brackets is a function, including programming constructs. Example:in the C language, for is a loop-opening reserved keyword, whereas in Mathematica For is a function that runs a loopaccording to its 4 arguments: start, end, increment, body.

5 Such restrictions on arguments and function returns are closer in spirit to C than Fortran although you can of coursemodify C-function arguments using pointers — exceedingly dangerous but often unavoidable.

6 The name Module should not be taken too seriously: it is far away from the concept of modules in Ada, Modula, Oberonor Fortran 90. But such precise levels of interface control are rarely needed in symbolic languages.

7 Indeed none of the CAS packages in popular use is designed for strong modularity because of historical and interactivityconstraints.

4–5

Page 6: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

Integration example

f[x_,α_,β_]:=(1+β*x^2)/(1+α*x+x^2);F=Integrate[f[x,-1,2],{x,0,5}]; F=Simplify[F]; Print[F]; Print[N[F]]; F=NIntegrate[f[x,-1,2],{x,0,5}]; Print["F=",F//InputForm];

13.0445F=13.044522437723455

Input Cell

Text Cell

Print Output Cell10 + Log[21]

Figure 4.2. A Mathematica file (Notebook) is a sequence of cells. Threecommon cell types: text, input and output, are illustrated.

Fa=Integrate[f[z,a,b],{z,0,5}]; Fa=Simplify[Fa]; Print["Fa=",Fa]; Plot3D[Fa,{a,-1.5,1.5},{b,-10,10},ViewPoint->{-1,-1,1}];Fa=FullSimplify[Fa]; (* very slow but you get *) Print["Fa=",Fa];

-1

0

1

-10

-5

0

5

10-50

0

50

-1

0

1

12

Print Output after Simplify[ ..]

Print Output after FullSimplify[ .. ]

Plot Output Cell

Input Cell

Fa=5b - a b Log[26+5a] -

(2 + (-2 + a2) b) (Log[1- ]- Log[1+ ] - Log[1- ]+ Log[1+ ])4-a24-a2 4-a2 4-a2

a a (10+a)(10+a)

4 - a 22

4 - a 22

4 - a 2

4 - a 2

4 - a 2 4 - a 2 4 - a 2

4 - a 2 4 - a 2

4 - a 2

4 - a 24 - a 2

Fa= (10 4-a 2 b - a 4-a2 b Log[26+5a] - (2+(-2+a2) b) Log[1- ] +

2 Log[1 + ] - 2 b Log[1 + ] + a2 b Log[1 + ] +

2 Log[ ] - 2 b Log[ ] + a2 b Log[ ] -

2 Log[ ] + 2 b Log[ ] - a2 b Log[ ])

1

a

a

a a

-10 - a + 4-a2

10 + a + 4-a2 10 + a + 4-a2 10 + a + 4-a2

-10 - a + 4-a2-10 - a + 4-a2

Figure 4.3. Continuation of previous example. This one illustrates a plot output cell. Note: displayed resultswere obtained with Mathematica version 4.2. Integration answers from versions 5 and up are quite different.

4–6

Page 7: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.1 COMPUTER ALGEBRA SYSTEMS

Each symbol is identified by a symbol name. A name can be any sequence of letters and numbers,except that the first character must be a letter.8 Letters from other alphabets are permitted; forexample αβγ is a valid symbol. There is no limit on name length.

A symbol is defined once it appears for the first time in an expression. program. For example: x;,x+x;, Clear[x];, or x=4; defines symbol x. In the last example x is assigned a value: the integer4. In the other examples x is defined but has no associated value.

Mathematica is a case sensitive language so for example a and A are different symbols.

Some symbols are reserved by Mathematica. They begin either with a capital letter or the dollarsign $, the latter being mostly used for system-related values. For example the letter E is reservedas the base of natural logs, and the letter I as the imaginary unit.

Reserved symbols cannot be modified by the user. Saying For=4 or Print=1+2*x will produceand error message, since those are reserved keywords.

§4.1.7. Replacing and Assigning Values

Having just a bunch of symbols with no assigned values floating around is not very useful. Assig-nation of values is dome by transformations. These can be applied by two operators: replacement/. and assignment =.

The equals operator = works like the assignation form of languages such as C or Fortran. Sayingx=4-a; assigns the value 4-a to x. This is remembered in subsequent expressions so that y=1+xsets y. to 5-a.

The replacement operator /. is unique to Mathematica. Suppose x is an unassigned symbol. Theny=(1+x)/.x->4-a; results in y being assigned the value 5-a as before, but x remains unchanged.A replacement rule can be identified by a symbol; thus saying rep=x->4-a; y=(1+x)/.rep; hasthe same effect.

§4.1.8. Atoms and Lists

Atomic elements (abbreviated to atoms) are values that cannot be further subdivided. All expressionsin Mathematica are ultimately built of atoms.

Atoms may be ordinary numbers (integer, rationals, real, complex), character strings, or symbols.Atom type is idenfied by a function called Head. For example, Head[4], Head[3/5], Head[2.],Head[2+3I], and Head["start"] return Integer, Rational, Real, Complex, and String,respectively. An unassigned symbol (user defined or reserved) is identified as such, for exampleHead[For] returns Symbol. Atoms have also attributes in addition to type, but their description isnot necessary here.

A list is the most general data structure provided by Mathematica. It is a sequence of atoms and/orlists. They can represent collections, arrays, sets and sequences of all kinds; e.g., a matrix, a plotdescription or a sound record is a list. A list entry, whether atom or list, is called an item.

Lists are delimited by curly braces. For example, pow={ 1,2,4,8,16 } is a list of 5 items, each ofwhich is a integer atom. Taking Head[pow] returns List. A list entry, whether atom or list, iscalled an item. To extract the ith item of pow, say pow[[i]]. Thus pow[[4]] returns 8.

8 Some of Mathematica reserved symbols start with a dollar sign, e.g., $VersionNumber.

4–7

Page 8: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

A list that contains only atoms is called a level-1 list, or (alternatively) a flat list. A list of level-1lists is called a level-2 list, and so on. Particularly important instances of level-1 nd level-2 lists arevectors and matrices, as outlined below.

§4.1.9. Matrices and Vectors

These are fundamental data structures for engineering computations. A matrix is represented by alevel-2 list of rows. For example

A={ { 1,2,3,4 },{ 5,6,7,8 },{ 9,10,11,12 } }, (4.1)

is a 3 × 4 numerical matrix (3 rows, 4 columns) whereas

v={ a,b,c,d,e,f }, (4.2)

is a symbolic 6-vector. In Mathematica vectors and single-row matrices (or single-column ma-trices) are not necessarily equivalent, because they are one-dimensional and two-dimenional lists,respectively. For instance, one can take the transpose of a matrix using the built-in Transposefunction. But the transpose of a vector does not make sense, and an error message will be issued.

§4.1.10. Functions and Modules

Every action in Mathematica is carried out by a function although the fact may be concealed by theuse of operators. For example the statement x=a+1 actually used the add and assignment functions,which are called Plus and Set, respectively.

Simple functions may be defined compactly. For example ScalarProduct[x ,y ]:=x.y definesthe scalar product of two vectors: x and y so that ScalarProduct[{ 1,2,3 }, { 3,2,1 }] returns10. (Actually that function would be redundant since the dot operator does it.) The operator :=is called a delayed assignment, meaning that the assignment is done when the function is invokedrather that when it is defined.

For more complicated function-like operations, it is convenient to use the Module construct. Thatwill be abundantly exemplified in the FEM implemntation of the PlaneTruss program.9

§4.2. Program Organization

The functional organization of thePlaneTrussprogram is flowcharted in Figure 4.4. This schemat-ics pictures the program as divided into functional tasks. For example the driver script calls thestiffness assembler, which in turn calls a subordinate module to form the stiffness of bar element.This kind of functional separation would be provided by any programming language.

On the other hand, Figure 4.5 is Mathematica specific. It displays the names of the module(s) thatimplement the functional tasks and the cells in which they reside. (Those program objects: modulesand cells, are described in the sections below.)

The following sections describe each of the code segments of Figure 4.5. For didactic purposes thisis done in a “bottom up” fashion, that is, going cell by cell, from left to right and bottom to top.

9 As noted, everything in Mathematica is a function, and modules are no exception. The reserved name Module is thename of a built-in function that expects two arguments: the local variable list, and the body.

4–8

Page 9: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.4 PLANE BAR STIFFNESS MODULE

Built-in Equation Solver

Derived inChapter 2

User preparedscript

Element Library Pre- and Postprocessing Utilities

Printing PlottingBar Element Stiffness

Bar InternalForce

Application ofSupport BCs

Problem Driver

StiffnessAssembler

Internal Force Recovery

Figure 4.4. Organization of PlaneTruss program by function.

Cell 6:PrintPlaneTrussNodeCoordinatesPrintPlaneTrussElementDataPrintPlaneTrussFreedomActivityPrintPlaneTrussNodeDisplacementsPrintPlaneTrussNodeForcesPrintNodeTrussIntForcesPrintPlaneTrussStresses

Cell 1: PlaneBarStiffness

Cell 4:PlaneBarIntForce

Built in Equation Solver

Print Plot

Cell 3:AppliedForceVectorModifiedMasterStiffnessModifiedNodeForcePrescDispBCTagsPrescDispBCVals

Cells 10 & higher: Driver Scripts

User preparedscripts

Cell 2:PlaneTrussMasterSttiffness

Cell 5: PlaneTrussIntForcesPlaneTrussStresses

Pre- and Postprocessing Utilities

Processing

Cells 7,8,9:PlotPlaneTrussElementsPlotPlaneTrussElementsAndNodesPlotPlaneTrussDeformedShapePlotPlaneTrussStressesLineColor

Figure 4.5. Organization of PlaneTruss program by cell and module names.

§4.3. Data Structures

Tables 4.1 and 4.2 collect names of data structures and variables used by the PlaneTruss program.Gathering these definitions in one place simplify the description of module inputs and outputs.

§4.4. Plane Bar Stiffness Module

As our first FEM code segment, the top box of Figure 4.6 shows a module that evaluates and returnsthe element stiffness matrix of a plane truss member (two-node bar) in global coordinates. The textin the top box is placed in Cell 1 of the PlaneTruss.nb Notebook. Executing the cell, by clickingon it and then hitting an appropriate key, typically <Shift-Enter>, gives the output shown in thebottom box.

4–9

Page 10: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

Table 4.1. Data Structures Used in Pre- and Postprocessing

Name Definition

nodxyz Node coordinates: { { x1,y1 },{ x2,y2 }, . . . }For example truss: { { 0,0 },{ 10,0 },{ 10,10 } }

elenod Element end nodes: { { n(1)

i ,n(1)

j },{ n(2)

i ,n(2)

j },. . . }, in which n(e)i < n(e)

j

For example truss: { { 1,2 },{ 2,3 },{ 1,3 } }elemat Element material data: flat list of elastic moduli: { E (1),E (2), . . . }

For example truss: { 100,100,100 }elefab Element fabrication data: flat list of x-section areas: { A(1),A(2), . . . }

For example truss: { 1,1/2,2*Sqrt[2] }nodtag Node DOF activity: { { tx1,ty1 },{ tx2,ty2 }, . . . }, in which txn = 1 if the

x-displacement of node n is prescribed, else 0; and likewise for the y componentFor example truss: { { 1,1 },{ 0,1 },{ 0,0 } }

nodval Node prescribed DOF values: { { vx1,vy1 },{ vx2,vy2 }, . . . }, in which vxn

is the value of x-displacement of node n if tag txn = 1, else value of appliedforce if tag txn = 0; and likewise for the y component.For example truss: { { 0,0 },{ 0,0 },{ 2,1 } }

noddis Node displacements arranged node by node: { { ux1,uy1 },{ ux2,uy2 }, . . . }nodfor Node forces arranged node by node: { { fx1, fy1 },{ fx2, fy2 }, . . . }

Includes reactions once the displacement solution is obtained and premultiplied by K

elefor Internal element forces arranged { p(1),p(2), . . . }elesig Internal element stresses arranged { σ (1),σ (2), . . . }

Preprocessing must define nodxyz through nodval; processing provides the last four.

The name shown on the left is called the “short name” and is that used in the processing modules.Script names are longer and more descriptive; for example NodeCoordinates for nodxyz.

The element stiffness module is called PlaneBarStiffness.10 It is invoked as

Ke = PlaneBarStiffness[{ { x1,y1 },{ x2,y2 } },Em,A] (4.3)

The arguments are

{ { x1,y1 },{ x2,y2 } } Global {x, y} coordinates of the bar end nodes, locally labeled as 1and 2, stored as a two-level list11

Em Bar elastic modulus.12

A Bar cross section area.

The use of the underscore after argument item names in the declaration of the Module is a require-ment for pattern-matching in Mathematica. If, as recommended, you have learned functions andmodules this language-specific feature should not come as a surprise.

10 Such descriptive names are permitted by the language. This reduces the need for detailed comments.11 For a quick intro to lists, see §4.1.8.12 E cannot be used as variable name since it is reserved by Mathematica; see Remark 4.1.

4–10

Page 11: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.4 PLANE BAR STIFFNESS MODULE

Table 4.2. Miscellaneous Variables Used During Processing

Name Definition

K Master stiffness matrix before application of displacement BCf Node forces stored as a flat (DOF by DOF) list

To convert to node-by-node list use nodfor=Partition[f,2]To convert nodfor to flat list use f=Flatten[nodfor]

u Node displacements stored as a flat (DOF by DOF) listTo convert to node-by-node list use noddis=Partition[u,2]To convert noddis to flat list use u=Flatten[noddis]

Kmod Master stiffness matrix modified by application of displacement BCfmod Flat force vector modified by application of displacement BCKe Element stiffness matrixeft Element Freedom Table that links local (element) and global DOF numbers.pdof Displacement-constrained DOF (a.k.a. essential BC) stored as flat liste Element loop indexi,j,ii,jj,m,n Array and loop-control indicesnumnod Number of nodesnumele Number of elementsnumdof Number of degrees of freedomEm Elastic modulus of barA Cross section of barpe Element internal forceLe Element lengthLLe Square of element lengthx1,y1,x2,y2,. . . Node coordinates extracted as single variablesux1,uy1,ux2,uy2,. . . Node displacements extracted as single variables

Variables used in print and plot utilities are not included in this list.

The module returns

Ke The 4 × 4 member stiffness matrix internally called Ke. The logic that leads to theformation of that matrix is straightforward. Note the elegant direct declaration of thematrix Ke as a level-two list, which eliminates the fiddling around with array indicestypical of low-level programming languages. The specification following Ke = in factclosely matches the mathematical expression given as (2.18) in Chapter 2.

Remark 4.1. Localizing variables. The module shown in Figure 4.6 uses several intermediate variables withshort names: dx, dy, s, c, LLe, and Le. It is strongly advisable to make these symbols local to avoid potentialnames clashes somewhere else.13 In the Module[ ...] construct this is done by listing those names in a listimmediately after the opening bracket. Local variables may be initialized when they are constants or simplefunctions of the argument items; for example on entry to the module dx=x2-x1 initializes variable dx to bethe difference of x node coordinates, namely �x = x2 − x1.

13 This “global by default” choice is the worst one, but we must live within the rules of the language.

4–11

Page 12: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

Numerical Elem Stiff Matrix:

Symb Elem Stiff Matrix:

10 10 -10 -10-10 10 -10 -10-10 -10 10 10-10 -10 10 10

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

A Em 2 2 L

- -

- -

- -

- -

1 1 -1 -1-1 1 -1 -1-1 -1 1 1-1 -1 1 1

= *

PlaneBarStiffness[{{x1_,y1_},{x2_,y2_}},Em_,A_]:= Module[ {c,s,x21=x2-x1,y21=y2-y1,LLe,Le,Ke}, LLe=x21^2+y21^2; Le=PowerExpand[Sqrt[LLe]]; c=x21/Le; s=y21/Le; Ke=(Em*A/Le)*{{ c^2, c*s,-c^2,-c*s},

{ c*s, s^2,-s*c,-s^2}, {-c^2,-s*c, c^2, s*c}, {-s*c,-s^2, s*c, s^2}};

Return[Ke]];

Ke= PlaneBarStiffness[{{0,0},{10,10}},100,2*Sqrt[2]];Print["Numerical Elem Stiff Matrix: ",Ke//MatrixForm];ClearAll[Em,A,L]; Ke= PlaneBarStiffness[{{0,0},{L,L}},Em,A];Ke=Simplify[Ke,L>0]; fac=Em*A/(2*Sqrt[2]*L); Kesc=Simplify[Ke/fac];Print["Symb Elem Stiff Matrix: ",Ke//MatrixForm, " = ",fac,"*",Kesc//MatrixForm];

Figure 4.6. Module PlaneBarStiffness provided in Cell 1, which returns the element stiffness of a 2-nodeplane truss (bar) element in global coordinates. Test statements (blue text) on top cell, and test output in bottom cell.

Remark 4.2. Case Sensitivity. Mathematica, like most recent computer languages, is case sensitive so that forinstance A is not the same as a. This is fine. But the language designer decided that names of system-definedobjects such as built-in functions and constants must begin with a capital letter. Consequently the liberal useof names beginning with a capital letter may run into clashes. For example, you cannot use E because of itsbuilt-in meaning as the base of natural logarithms. In retrospect this appears to have been a highly questionabledecision. System defined names should have been identified by a reserved prefix or postfix to avoid surprises,as done in Macsyma or Maple. Mathematica issues a warning message, however, if an attempt to redefine a“protected symbol” is made.

In the code fragments presented throughout this book, identifiers beginning with upper case are used for objectssuch as stiffness matrices, modulus of elasticity, and cross section area. This follows established usage inMechanics. When there is danger of clashing with a protected system symbol, additional lower case lettersare used. For example, Em is used for the elastic modulus instead of E because — as noted above — the latteris a reserved symbol.

Remark 4.3. The Return statement. That statement fulfills the same purpose as in C, C++ or Fortran 90.Mathematica guides and textbooks advise against the use of that construct. The writer strongly disagrees: theReturn statement makes clear what the module gives back to its invoker and is self-documenting.

Following the definition of PlaneBarStiffness in Figure 4.6 there are statements in blue textthat constitute the module test script. This script calls the module and prints returned results. Twocases are tested. First, the stiffness of member (3) of the example truss, using all-numerical values.

4–12

Page 13: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.5 PLANE TRUSS STIFFNESS ASSEMBLY

Master stiffness of example truss:

20 10 −10 0 −10 −1010 10 0 0 −10 −10

−10 0 10 0 0 0

0 0 0 5 0 −5−10 −10 0 0 10 10

−10 −10 0 −5 10 15

PlaneTrussMasterStiffness[nodxyz_,elenod_,elemat_,elefab_]:= Module[{numele=Length[elenod],numnod=Length[nodxyz],e,eft, ni,nj,ncoor,Em,A,Ke,K}, K=Table[0,{2*numnod},{2*numnod}]; For [e=1,e<=numele,e++, {ni,nj}=elenod[[e]]; eft={2*ni-1,2*ni,2*nj-1,2*nj}; ncoor={nodxyz[[ni]],nodxyz[[nj]]}; Em=elemat[[e]]; A=elefab[[e]]; Ke=PlaneBarStiffness[ncoor,Em,A]; For [i=1,i<=4,i++, ii=eft[[i]];

For [j=i,j<=4,j++, jj=eft[[j]]; K[[jj,ii]]=K[[ii,jj]]+=Ke[[i,j]]; ];

]; ]; Return[K]];

nodxyz={{0,0},{10,0},{10,10}}; elenod={{1,2},{2,3},{1,3}};elemat={100,100,100}; elefab={1,1/2,2*Sqrt[2]}; K=PlaneTrussMasterStiffness[nodxyz,elenod,elemat,elefab];Print["Master stiffness of example truss: ",K//MatrixForm];

Figure 4.7. Module PlaneTrussMasterStiffness provided in Cell 2, which returns the master stiffnessmatrix of a plane struss to the driver script. Test statements (blue text) in top box, and test output in lower box.

Next, some of input arguments are given symbolic names so they stand for variables. For example,the elastic module is given as Em instead of 100 as in the foregoing test. The print output of the testis shown in the lower portion of Figure 4.6.

The first test returns the stiffness matrix listed in (2.21), as may be expected. The second test returnsa form in which three symbols appear:L, Em, and A. (The coordinates of global node 3 were set to{ L,L } instead of {10, 10}.) The returning matrix Ke is subject to a Simplify step before printingit, the reason for which is the subject of an Exercise. The ability to carry along variables is of coursea fundamental capability of any CAS, and a key reason for which such programs are used.

§4.5. Plane Truss Stiffness Assembly

Module PlaneTrussMasterStiffness, listed in Figure ?, assembles the master stiffness matrixof a plane truss. The module is invoked as

K = PlaneTrussMasterStiffness[nodxyz,elenod,elemat,elefab] (4.4)

The arguments are

nodxyz Nodal coordinates placed in a node by node list: see Table 4.1.

elenod Element end nodes placed in an element-by-element list: see Table 4.1.

4–13

Page 14: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

AppliedForceVector[nodtag_,nodval_]:= Module[{i,ftag,fval, numdof,f}, {ftag,fval}={Flatten[nodtag],Flatten[nodval]}; numdof=Length[ftag]; f=Table[0,{numdof}]; For [i=1,i<=numdof,i++, If [ftag[[i]]==0, f[[i]]=fval[[i]]]]; Return[f]];

ModifiedMasterStiffness[nodtag_,K_] := Module[ {i,j,k,n=Length[K],pdof,np,Kmod=K}, pdof=PrescDispDOFTags[nodtag]; np=Length[pdof]; For [k=1,k<=np,k++, i=pdof[[k]]; For [j=1,j<=n,j++, Kmod[[i,j]]=Kmod[[j,i]]=0]; Kmod[[i,i]]=1]; Return[Kmod]];

ModifiedNodeForces[nodtag_,nodval_,K_,f_]:= Module[ {i,j,k,n=Length[K],pdof,pval,np,d,c,fmod=f}, pdof=PrescDispDOFTags[nodtag]; np=Length[pdof]; pval=PrescDispDOFValues[nodtag,nodval]; c=Table[1,{n}]; For [k=1,k<=np,k++, i=pdof[[k]]; c[[i]]=0]; For [k=1,k<=np,k++, i=pdof[[k]]; d=pval[[k]]; fmod[[i]]=d; If [d==0, Continue[]]; For [j=1,j<=n,j++, fmod[[j]]-=K[[i,j]]*c[[j]]*d]; ]; Return[fmod]];

Figure 4.8. Modules AppliedForceVector, ModifiedMasterStiffness and ModifiedForceVector,which are included in the top half of Cell 4. These three modules are called (in that order) by the driver scriptto apply displacement and force boundary conditions to the master stiffness equations from DOF-activity data

provided in nodtag and nodval. Test statements appear in the next Figure, which completes Cell 3.

elemat Element-by-element list of element elastc moduli: see Table 4.1.

elefab Element fabrication properties. Element-by-element list of element cross sectionareas: see Table 4.1.

The module returns

K The master stiffness matrix of the plane truss. This matrix does not account forboundary conditions, which are applied by modules described in the next section.

The blue text test statements shown at the bottom of the top box in Figure ? are set to assemblethe master stiffness matrix example truss. On executing the cell, the output shown in the lower boxagrees with the hand result (3.12) of Chapter 3.

Remark 4.4. The assembly process in PlaneTrussMasterStiffness is not done through the augment-and-add method covered in Chapter 3, which is only useful for hand computations in small systems. Instead thepointer technique alluded to in Chapter 3 and fully explained in Chapter 25 is used. That technique maps thelocal (element level) freedoms to global (master stiffness level) ones through the “Element Freedom Table”array denoted by eft in the source code.

4–14

Page 15: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.6 APPLICATION OF BOUNDARY CONDITIONS

K before BC:

K11 K22 K13 K14 K15 K16K12 K22 K23 K24 K25 K26K13 K23 K33 K34 K35 K36K14 K24 K34 K44 K45 K46K15 K25 K35 K45 K55 K56K16 K26 K36 K46 K56 K66

f before BC:{0, 0, 0, 0, 2, 1}

K modified for BC:

PrescDispDOFTags[nodtag_]:= Module[ {j,n,numnod=Length[nodtag],pdof={},k=0,m}, For [n=1,n<=numnod,n++, m=Length[nodtag[[n]]]; For [j=1,j<=m,j++, If [nodtag[[n,j]]>0,

AppendTo[pdof,k+j]]]; k+=m; ]; Return[pdof]]; PrescDispDOFValues[nodtag_,nodval_]:= Module[ {j,n,numnod=Length[nodtag],pval={},k=0,m}, For [n=1,n<=numnod,n++, m=Length[nodtag[[n]]]; For [j=1,j<=m,j++, If [nodtag[[n,j]]>0,

AppendTo[pval,nodval[[n,j]]]]]; k+=m; ]; Return[pval]];

nodtag={{1,1},{0,1},{0,0}}; nodval={{-1,2},{0,3},{2,1}};K={{K11,K12,K13,K14,K15,K16},{K12,K22,K23,K24,K25,K26}, {K13,K23,K33,K34,K35,K36},{K14,K24,K34,K44,K45,K46}, {K15,K25,K35,K45,K55,K56},{K16,K26,K36,K46,K56,K66}};Print["K before BC:",K//MatrixForm];f=AppliedForceVector[nodtag,nodval];Print["f before BC:",f]; Kmod=ModifiedMasterStiffness[nodtag,K];Print["K modified for BC:",Kmod//MatrixForm];fmod=ModifiedNodeForces[nodtag,nodval,K,f];Print["f modified for BC:",fmod];

1 0 0 0 0 00 1 0 0 0 00 0 K33 0 K35 K360 0 0 1 0 00 0 K35 0 K55 K560 0 K36 0 K56 K66

f modified for BC:{-1, 2, K13 - 2 K23 - 3 K34, 3, 2 + K15 - 2 K25 - 3 K45, 1 + K16 - 2 K26 - 3 K46}

Figure 4.9. Modules PrescDisplacementsDOFTags and PrescDisplacementsDOFValues, which areprovided in the bottom portion of Cell 3. These are auxiliary modules called by ModifiedMasterStiffness

and ModifiedForceVector, and are not referenced directly by the driver script. Test statements (blue text)for the three modules listed in the previous Figure appear at the bottom of the top box. Test output in lower box.

§4.6. Application of Boundary Conditions

Displacement and force boundary conditions (BC).14 are not applied by the explicit equation removaldescribed in Chapter 3, because that is primarily suitable for hand computation. They are instead

14 In variational calculus nomenclature these are called essential and natural boundary conditions (BC), respectively.

4–15

Page 16: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

applied through the computer-oriented equation modification process outlined in §3.5.2.

The necessary operations are carried out by the five modules provided in Cell 3. Because of thecell length, its listing is split into Figures 4.8 and and 4.9.

The three top modules in Cell 3 are AppliedForceVector, ModifiedMasterStiffness, andModifiedForceVector. These are listed in Figure 4.8. Their calling sequences are

f = AppliedForceVector[nodtag,nodval] (4.5)

Kmod = ModifiedMasterStiffness[nodtag,nodval,K] (4.6)

fmod = ModifiedForceVector[nodtag,nodval,K,f] (4.7)

The two arguments common to the three modules are:

nodtag Node-by-node BC tags; see Table 4.1.

nodval Node-by-node BC values; see Table 4.1.

The other arguments are:

K The master stiffness matrix returned by PlaneTrussStiffness.

f The flat node force vector returned by AppliedForceVector.

The modules return:

f The flat force vector; see Table 4.2.

Kmod The master stiffness matrix modified by displacement BC.

fmod . The flat force vector modified by displacement BC.

The theee modules are supposed to be invoked by the driver script in the order shown above: firstAppliedForceVector,then ModifiedMasterStiffness, and finally ModifiedForceVector.If all displacement BC are homogenous, meaning they are specified to have a zero value, fmod= f, but it is recommended to call ModifiedForceVector as it costs nothing. Be sure not touse Kmod as argument to ModifiedForceVector, as that will procedure incorrect results if thedisplacement BC are non-homogeneous.

Two additional modules: PrescDispDOFTags and PrescDispDOFValues appear in Figure 4.9.These are used by ModifiedMasterStiffness, and ModifiedForceVector as auxiliary proce-dures. Since they are not directly referenced by the driver script, those subordinate modules neednot be described here.

The test statements in Cell 3 use a symbolic 6 × 6 master stiffness matrix to better illustrate theapplication of nonzero prescribed displacements ux1 = −1, uy1 = 2 and uy2 = 3. The The testoutput is shown in the bottom box of Figure 4.9, and should be self explanatory.

4–16

Page 17: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.8 PLANE BAR INTERNAL FORCE

Bar int force (numerical): 2.82843

Bar int force (symbolic): - A Em (ux1 - ux3 + uy1 - uy3)

2L

PlaneBarIntForce[{{x1_,y1_},{x2_,y2_}},Em_,A_,ue_]:= Module[ {x21=x2-x1,y21=y2-y1,dux,duy,LLe,pe}, LLe=x21^2+y21^2; dux=ue[[3]]-ue[[1]]; duy=ue[[4]]-ue[[2]]; pe=(Em*A/LLe)*(x21*dux+y21*duy); Return[pe]];

pe=PlaneBarIntForce[{{0,0},{10,10}},100,2*Sqrt[2],{0,0,0.4,-0.2}];Print["Bar int force (numerical): ",pe]; ClearAll[Em,A,L,ux1,uy1,ux3,uy3];pe=PlaneBarIntForce[{{0,0},{L,L}},Em,A,{ux1,uy1,ux3,uy3}];Print["Bar int force (symbolic): ",Simplify[pe]];

Figure 4.10. Module PlaneBarIntForce for computing the internal force in a barelement. Test statements (blue text) and test output.

§4.7. Solving For Displacements and Recovering The Full Force Vector

Since higher order matrix languages such as Mathematica provides built-in operations for solving alinear system of equations and multiplying matrices by vectors, we do not need to write applicationmodules for two subsequent operations:

(1) Solving the modified stiffness equations Kmod u = fmod . This can be done simply by sayingu=LinearSolve[Kmod,fmod]

(2) Recovering of the full node force vector f = K u. Tis can be done simply as f=K.u, in whichK is the original master stiffness matrix returned by the assembler (before BC modifications)and u is the computed displacement solution provided by LinearSolve. This force vectornow contains reactions.

The last postprocessing operation is recovery of internal forces, namely the axial forces in themembers. This is done as described in the next sections.

§4.8. Plane Bar Internal Force

Function PlaneBarIntForce listed in the top box of Figure 4.10 computes the internal force inan individual plane truss (bar) element. It is invoked as

Ke = PlaneBarIntForce[{ { x1,y1 },{ x2,y2 } },Em,A,ue] (4.8)

The first three arguments are exactly the same as those of the PlaneBarStiffness, described in?. The additional one is

ue the element node displacements stored as a flat list: { ux1,uy1,ux2,uy2 } in which1 and 2 denote local end node numbers.

The test statements provided at the bottom of the top cell of Figure 4.10 exercise this module twice.The numerical test supplies the proper data for member (3) of the example truss, including the

4–17

Page 18: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

Bar int force (numerical): 2.82843

Bar int force (symbolic): - A Em (ux1 - ux3 + uy1 - uy3)

2L

PlaneBarIntForce[{{x1_,y1_},{x2_,y2_}},Em_,A_,ue_]:= Module[ {x21=x2-x1,y21=y2-y1,dux,duy,LLe,pe}, LLe=x21^2+y21^2; dux=ue[[3]]-ue[[1]]; duy=ue[[4]]-ue[[2]]; pe=(Em*A/LLe)*(x21*dux+y21*duy); Return[pe]];

pe=PlaneBarIntForce[{{0,0},{10,10}},100,2*Sqrt[2],{0,0,0.4,-0.2}];Print["Bar int force (numerical): ",pe]; ClearAll[Em,A,L,ux1,uy1,ux3,uy3];pe=PlaneBarIntForce[{{0,0},{L,L}},Em,A,{ux1,uy1,ux3,uy3}];Print["Bar int force (symbolic): ",Simplify[pe]];

Figure 4.11. Module PlaneTrussIntForces that computes internal forces in all members of aplane truss Test statements (in blue) at bottom of top box and test output in the bottom box.

computed node displacements { 0,0,0.4,-0.2 } as ue. The symbolic tests feeds some of the inputarguments as variables.

§4.9. Plane Truss Internal Forces and Stresses

The top box of Figure 4.11 lists two modules: PlaneTrussIntForces andPlaneTrussStresses.The former computes and returns the internal (axial) forces of all members of a plane truss, usingthe module PlaneBarIntForce described in the previous section, in an element by element loop.The latter returns the axial stress in all members.

These modules are called by the driver script in sequence. They are invoked as

elefor = PlaneTrussIntForces[nodxyz,elenod,elemat,elefab,noddis] (4.9)

elesig = PlaneTrussIntForces[elefab,elefor] (4.10)

The first four arguments of PlaneTrussIntForces, namely nodxyz through elefab are exactlythe same as in the call of the assembler module PlaneTrussAssembler, as described in ?. Its lastargument is

noddis The computed node displacements arranged node by node as described in Table 4.1.

The PlaneTrussIntForces module returns

elefor The member internal forces; see Table 4.1.

The two arguments ofPlaneTrussStresses areelefab, which stores cross section areas as shownin table 4.1, and elefor, which collects the member forces returned by PlaneTrussIntForces.

The PlaneTrussStresses module returns

elesig The member axial stresses; see Table 4.1.

The test statements (blue text) shown at the bottom of the top box in Figure 4.11 exercises bothmodules for the example truss case. The test output is shown in the bottom box of that figure.

4–18

Page 19: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.10 DISPLAY UTILITIES

The internal forces are in agreement with the values found in §3.4.2. The stress values are readilyverified on dividing those values by the corresponding cross section areas.

§4.10. Display Utilities

To improve result presentation, several utilities for printing and plotting are included in Cells 6–9 of thePlaneStress.nb Notebook. The code volume for such utilities dwarfs that of the processing modules, whichis not atypical of finite element codes. Only the calling sequences are briefly described here, omitting internaldetails.

§4.10.1. *Utility Print Modules

Utility print modules are convenient for displaying the data structures of Table 4.1 in tabular form. They shouldonly be used for all-numerical computations, as they are not designed to accommodate symbolic expressions.The following modules are provided in Cell 6 of the Notebook.

To print the node coordinates in nodxyz:

PrintPlaneTrussNodeCoordinates[nodxyz,title,digits] (4.11)

To print the element data in elenod, elemat and elefab:

PrintPlaneTrussElementData[elenod,elemat,elefab,title,digits] (4.12)

To print the freedom activity data in nodtag and nodval:

PrintPlaneTrussFreedomActivity[nodtag,nodval,title,digits] (4.13)

To print the node displacements in noddis (configured in node-by-node form, cf. Table 4.1):

PrintPlaneTrussNodeDisplacements[noddis,title,digits] (4.14)

To print the node forces in nodfor (configured in node-by-node form, cf. Table 4.1):

PrintPlaneTrussNodeForces[nodfor,title,digits] (4.15)

To print the element internal forces in elefor and element stresses in elesig:

PrintPlaneTrussElemForcesAndStresses[elefor,elesig,title,digits] (4.16)

In all cases, title is an optional character string to be printed as a title before the table; e.g., "Nodecoordinates of bridge truss:". To suppress it specify "" (two quote marks together).

The last argument of the print modules: digits, is optional. If set to { d,f } it specifies that floating pointnumbers are to be printed with room for at least d digits, with f digits after the decimal point. If digits isspecified as a void list: { }, a preset default is used for d and f.

Print modules do not return values, since all their output goes to the system print file.

4–19

Page 20: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

§4.10.2. *Utility Plot Modules

Plot modules that support preprocessing and postprocessing are placed in Cells 7–9 of the Notebook. Thesedisplay unlabeled elements, elements and nodes with labels, deformed shapes and element stress levels.

To plot elements only:

PlotPlaneTrussElements[nodxyz,elenod,title,{ aspect,imgsiz,{ } }] (4.17)

To plot element and nodes with optional labeling:

PlotPlaneTrussElementsAndNodes[nodxyz,elenod,title,{ aspect,imgsiz,labels }] (4.18)

To plot deformed shape of the truss under computed node displacements:

PlotPlaneTrussDeformedShape[nodxyz,elenod,noddis,amplif,box,title,

{ aspect,imgsiz,colors }] (4.19)

To plot element axial stress levels using a coloring scheme:

PlotPlaneTrussStresses[nodxyz,elenod,elesig,sigfac,box,title,

{ aspect,imgsiz,{ } }] (4.20)

In the foregoing the data structures nodxyz, elenod, noddis, elefor and elesig are defined in Table 4.1.The other arguments are as follows.

aspect Vertical-to-horizontal aspect ratio of the plot as it appears on a Notebook cell. Three possibilities.If set to −1, the Mathematica default Aspect->Automatic is chosen. If set to zero, an aspectratio is computed by the plot module as appropriate. If set to a positive number, the aspect ratiois set to that number.

imgsiz The plot horizontal dimension specified in printer points (1 inch = 72.27 pt, 1 mm = 2.845 pt).No default is provided.

labels Only used in PlotPlaneTrussElementsAndNodes. A list with the following configuration:{ { nlabels,frn,fex,fey }, { elabels,fre },{ fntfam,fntsiz,fntwgt,fntslt } }.nlabels A logical flag. Set to True to get node labels in plot.

frn Radius of circle drawn around each node expressed as percentage of plot size.

fex Horizontal eccentricity in points of node label from node location.

fey Vertical eccentricity in points of node label from node location.

elabels A logical flag. Set to True to get element labels in plot.

fre Radius of circle drawn around each element number expressed as percentage ofplot size.

fntfam Font family used for labels, for example "Times"

fntsiz Size in points of font used for labels; usually 10 through 14.

fntwgt Font weight used for element labels. Typical settings are "Plain" or ”Bold”.Node labels are always drawn in boldface.

fntslt Font slant used for element labels. Typical settings are "Plain", "Italics" or"Slanted". Node labels are always drawn in Plain.

amplif The displacement amplification factor to be used by PlotPlaneTrussDeformedShape. Usu-ally a value larger than one (say 100 or 1000) is necessary to visualize displacements in actual

4–20

Page 21: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.12 DRIVER SCRIPTS

structures. Becomes a list if the call is to draw several shapes — e.g., undeformed and deformed.For example setting amplif to { 0,10 } will draw two shapes: the undeformed configuration andone with magnification of 10. If more than one shape is to be drawn the colors specificationbelow comes in handy.

box A list of points, specified by their {x, y, z} global coordinates, that forms a box that encloses theplot. Used in PlotPlaneTrussDeformedShape and PlotPlaneTrussStresses. The box isconverted to a frame by the view projector. This is useful for various purposes, one being to dorealistic animations by drawing a sequence of deformed shapes moving inside the box.

colors Defines element colors to be used by PlotPlaneTrussDeformedShape, specified as lowercase character string. Legal ones are "black", "red", "blue", "green" and ”white”. If thecall is to draw several shapes (for example undeformed and deformed), this argument can be alist, such as { "black","red" }, in which case the colors are in one to one correspondence withthe amplification values in amplif. If no color is specified, black is assumed.

sigfac A stress scaling factor for PlotPlaneTrussStresses. Normally set to 1.

Because of the way Mathematica handles plots, (some features do scale with plot size while others, such asfont sizes, do not), some interactive experimentation with dimension specs seems inevitable.

§4.11. Putting the Pieces Together

After all this development and testing effort, documented in Figures 4.6 through 4.11, we are readyto make use of all these bits and pieces of code to analyze the example plane truss. This is actuallydone with the logic shown in Figure 4.12. This particular piece of code is called the driver script.Note that it is not a Module. It uses the seven previously described modules

Cell 1: PlaneBarStiffnessCell 2: PlaneTrussMasterStiffnessCell 3: AppliedForceVectorCell 3: ModifiedMasterStiffnessCell 3: ModifiedNodeForcesCell 3: PrescDispDOFTagsCell 3: PrescDispDOFValuesCell 4: PlaneBarIntForceCell 5: PlaneTrussIntForcesCell 5: PlaneTrussStressesCell 6: Print utilities: 8 modulesCells 7-9: Plot utilities: 5 modules (4.21)

These modules and functions must have been defined (”compiled”) at the time the driver scriptsdescribed below are run. A simple way to making sure that all of them are defined is to put all thesefunctions in the same Notebook file and to mark them as initialization cells. These cells may beexecuted by picking up Kernel → Initialize → Execute Initialization in Mathematica versions 5and lower. For versions ≥ 6 pick Kernel → Evaluate Initialization Cells. (An even simpler schemewould to group them all in one cell, but that would make placing separate test statements messy.)

4–21

Page 22: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

ClearAll[a,Em,A1,A2,A3,fx2,fx3,fy3]; a=10; Em=100; A1=1; A2=1/2; A3=2*Sqrt[2]; fx2=0; fx3=2; fy3=1;nodxyz={{0,0},{a,0},{a,a}}; elenod={{1,2},{2,3},{1,3}};elemat={Em,Em,Em}; elefab=N[{A1,A2,A3}];nodtag={{1,1},{0,1},{0,0}}; nodval={{0,0},{fx2,0},{fx3,fy3}};PrintPlaneTrussNodeCoordinates[nodxyz,"Node coords of example truss:",{6,4}];PrintPlaneTrussElementData[elenod,elemat,elefab,"Element data of example truss:"{7,4}]; PrintPlaneTrussFreedomActivity[nodtag,nodval,"DOF activity of example truss:",{}];aspect=1.0; imgsiz=250; box={{0-d,0-d},{a+d,0-d},{a+d,a+d},{0-d,a+d}}/.d->.5; labels={{True,0.02,-1.5,1.5},{True,0.04},{"Times",12,"Plain","Italic"}};PlotPlaneTrussElementsAndNodes[nodxyz,elenod,"Example truss elems & nodes:", {aspect,imgsiz,labels}];K=PlaneTrussMasterStiffness[nodxyz,elenod,elemat,elefab];f=AppliedForceVector[nodtag,nodval];Kmod=ModifiedMasterStiffness[nodtag,K];Print["K=",K//MatrixForm," Kmod=",Kmod//MatrixForm];fmod=ModifiedNodeForces[nodtag,nodval,K,f];Print["f=",f//MatrixForm," fmod=",fmod//MatrixForm];u=Simplify[LinearSolve[Kmod,fmod]]; u=Chop[u]; noddis=Partition[u,2];PrintPlaneTrussNodeDisplacements[noddis,"Example truss node displacements:",{10,6}];box={{0-d,0-d},{a+d,0-d},{a+d,a+d},{0-d,a+d}}/.d->1; PlotPlaneTrussDeformedShape[nodxyz,elenod,noddis,{0,1,2},box,"Example truss"<> " orig & 2 deformed shapes",{aspect,imgsiz,{"red","blue","green"}}]; f=Simplify[K.u]; nodfor=Partition[f,2];PrintPlaneTrussNodeForces[nodfor,"Example truss node forces w/ reactions:",{10,6}];elefor=PlaneTrussIntForces[nodxyz,elenod,elemat,elefab,noddis];elesig=PlaneTrussStresses[elefab,elefor]; {elefor,elesig}=Chop[{elefor,elesig}];PrintPlaneTrussElemForcesAndStresses[elefor,elesig,"Example truss elem"<>

" forces & stresses:",{7,4}];box={{0-d,0-d},{a+d,0-d},{a+d,a+d},{0-d,a+d}}/.d->.5; PlotPlaneTrussStresses[nodxyz,elenod,elesig,1,box, "Example truss elem stresses",{aspect,imgsiz,labels}];

Figure 4.12. Driver script for numerical analysis of example truss. Output shown in next figure.

§4.12. Driver Scripts

Three sample driver scripts are stored in Cells 10 through 12. All of them pertain to the 3-memberexample truss used in Chapters 2–3 to illustrate the DSM, and are described below.

Cells 13 and 14 are empty in the posted Notebook. They are supposed to be used for the scriptssolving Exercise 5.1.

§4.12.1. Example Truss With All Numeric Data

A script to analyze the example truss is shown in Figure 4.12 The output is shown in the followingfigure, and has been rearranged through Adome Illustrator to fit within a page.

§4.12.2. Example Truss With Symbolic Forces

A script to analyze the example truss with symbolic forces is shown in the top box of Figure 4.14.Its output appears in the lower box. Note that print and plot utilities are not used: just direct printstatements.

4–22

Page 23: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4.12 DRIVER SCRIPTS

Node coords of example truss:

node x−coor y−coor1 0.0000 0.00002 10.0000 0.00003 10.0000 10.0000

Element data of example truss:

elem nodes modulus area1 {1, 2} 100.0000 1.00002 {2, 3} 100.0000 0.50003 {1, 3} 100.0000 2.8284

DOF activity of example truss:

node x−tag y−tag x−value y−value1 1 1 0 02 0 1 0 03 0 0 2 1

Example truss elems & nodes:

1

23

1 2

3

K=

20. 10. −10. 0 −10. −10.10. 10. 0 0 −10. −10.

−10. 0 10. 0 0 0

0 0 0 5. 0 −5.−10. −10. 0 0 10. 10.

−10. −10. 0 −5. 10. 15.

Kmod=

1 0 0 0 0 0

0 1 0 0 0 0

0 0 10. 0 0 0

0 0 0 1 0 0

0 0 0 0 10. 10.

0 0 0 0 10. 15.

f

0

0

0

0

2

1

fmod=

0

0

0

0

2

1

Example truss node displacements:

node x−displ y−displ1 0.000000 0.0000002 0.000000 0.0000003 0.400000 −0.200000

Example truss orig & 2 deformed shapes

Example truss node forces w reactions:

node x−force y−force1 −2.000000 −2.0000002 0.000000 1.0000003 2.000000 1.000000

Example truss elem forces & stresses:

elem axial force axial stress1 0.0000 0.00002 −1.0000 −2.00003 2.8284 1.0000

Example truss elem stresses

Figure 4.13. Output from script of Figure 4.12. it has been rearranged into three columnsthrough Adobe Illustrator (and plot shrunk) to fit comfortably into one Figure.

Running the script produces the output shown in Figure 4.12 produces the output shown in thebottom box of that figure. The results confirm the hand calculations of Chapter 3.

§4.12.3. Is All of This Worthwhile?

At this point you may wonder whether preparing this kind of program is worth the trouble. For theexample truss, with all-numeric data, a hand calculation (typically helped by a programable calcu-lator) would be quicker in terms of flow time. Typing and debugging the Mathematica fragmentsdisplayed here — excluding the porint and plot utilities — took the writer about six hours (althoughabout two thirds of this was spent in editing and getting the fragment listings into the Chapter.)Preparing and testing the utilities took a week of flowtime.

For larger problems, however, Mathematica would certainly beat hand-plus-calculator computa-tions, the cross-over typically appearing for 10 to 20 equations. For up to about 500 equations andusing floating-point arithmetic, Mathematica gives answers within minutes on a fast PC or Macwith sufficient memory but eventually runs out of steam at about 1000 equations. For a range of1000 to about 50000 equations, Matlab, using built-in sparse solvers, would be the best compro-mise between human and computer flow time. Beyond 50000 equations a program in a low-levellanguage, such as C or Fortran, would be most efficient in terms of computer time.15

15 The current record for FEM structural applications is about 300 million equations, done on a massively parallel super-

4–23

Page 24: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

ClearAll[fx2,fx3,fy3];nodxyz={{0,0},{10,0},{10,10}}; elenod={{1,2},{2,3},{1,3}};elemat={100,100,100}; elefab={1,1/2,2*Sqrt[2]}; nodtag={{1,1},{0,1},{0,0}}; nodval={{0,0},{fx2,0},{fx3,fy3}};Print["Node coord of example truss:",nodxyz];Print["Element data of example truss:",{elenod,elemat,elefab}];Print["DOF activity of example truss:",{nodtag,nodval}];K=PlaneTrussMasterStiffness[nodxyz,elenod,elemat,elefab];f=AppliedForceVector[nodtag,nodval];Kmod=ModifiedMasterStiffness[nodtag,K];fmod=ModifiedNodeForces[nodtag,nodval,K,f];u=Simplify[LinearSolve[Kmod,fmod]]; noddis=Partition[u,2]; Print["Computed node displacements:",u];f=Simplify[K.u]; nodfor=Partition[f,2];Print["Node forces including reactions:",f];elefor=PlaneTrussIntForces[nodxyz,elenod,elemat,elefab,noddis];elesig=PlaneTrussStresses[elefab,elefor];Print["Elem forces: ",elefor]; Print["Elem stresses: ",elesig];

Node coord of example truss:{{0, 0}, {10, 0}, {10, 10}}

Element data of example truss:{{{1, 2}, {2, 3}, {1, 3}, {100, 100, 100}, {1, , 2 2 }}

DOF activity of example truss:{{{1, 1},{0, 1}, {0, 0}}, {{0, 0}, {fx2, 0}, {fx3, fy3}}}

Computed node displacements: {0, 0, , 0, (3 fx3 - 2 fy3), (-fx3 + fy3)}

Node forces including reactions:{-fx2 - fx3, -fx3, fx2, fx3 - fy3, fx3, fy3}

Element forces: {fx2, -fx3 + fy3, (3 fx3 - 2 fy3 + 2 (-fx3 + fy3))}

Elem stresses: {fx2, 2 (-fx3 + fy3), (3 fx3 - 2 fy3 + 2(-fx3 + fy3))}

12

12

110

15

fx210

2

Figure 4.14. Top box: driver script for analysis of example truss with symbolic appliedforces fx2, fx3 and fy3. Bottom box shows output.

One distinct advantage of computer algebra systems emerges when you need to parametrize a smallproblem by leaving one or more problem quantities as variables. This was done in the scripts shownof previous Figures. Note that the modification is minimal, and the code need not be changed: onlythe script. The results are the answer to an infinite number of numerical problems. Althoughone may try to undertake such studies by hand, the likelyhood of errors grows rapidly with thecomplexity of the system. Symbolic manipulation systems can amplify human abilities in thisregard, as long as the algebra “does not explode” because of combinatorial complexity. Examplesof such nontrivial calculations will appear throughout the following Chapters.

Remark 4.5. The “combinatorial explosion” danger of symbolic computations should be alwayskept in mind. For example, the numerical inversion of a N × N matrix is a O(N 3) process,whereas symbolic inversion goes as O(N !). For N = 48 the floating-point numerical inversewill be typically done in a fraction of a second. But the symbolic adjoint will have 48! =12413915592536072670862289047373375038521486354677760000000000 terms, or O(1061). There maybe enough electrons in our Universe to store that, but barely ... And waiting billions and billions of years fora result is not very practical if your survival depends on the next paycheck.

computer (ASCI Red at SNL). Fluid mechanics problems with about 1 billion equations have been solved.

4–24

Page 25: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

§4. Notes and Bibliography

Node coord of example truss:{{0, 0}, {a, 0}, {a, b}}

Element data of example truss: {{{1, 2}, {2, 3}, {1, 3}}, {Em, Em, Em}, {A1, A2, A3}}

DOF activity of example truss:{{1,1}, {0, 1}, {0, 0}}, {{0, 0}, {fx2, 0}, {fx3,fy3}}}

Computed node displacements:

{0, 0, , 0, , }

Elem forces: { fx2,- + fy3, }

Elem stresses: { , , }

a fx2 A2 (a + b ) fx3 + A3 b (b fx3 - a fy3) b (-b fx3 + a fy3)

b fx3 a + b fx3

b fx3fx2 + fy3 a + b fx3

A1 Em a A2 A3 Em a A2 Em

a a

a A1 A2 a A3

2

3/22 2

2

22

2

2

-

ClearAll[fx2,fx3,fy3,a,b,A1,A2,A3,Em];nodxyz={{0,0},{a,0},{a,b}}; elenod={{1,2},{2,3},{1,3}};elemat={Em,Em,Em}; elefab={A1,A2,A3}; nodtag={{1,1},{0,1},{0,0}}; nodval={{0,0},{fx2,0},{fx3,fy3}};Print["Node coord of example truss:",nodxyz];Print["Element data of example truss:",{elenod,elemat,elefab}];Print["DOF activity of example truss:",{nodtag,nodval}];K=PlaneTrussMasterStiffness[nodxyz,elenod,elemat,elefab];K=Simplify[K,a>0&&b>0];f=AppliedForceVector[nodtag,nodval];Kmod=ModifiedMasterStiffness[nodtag,K];fmod=ModifiedNodeForces[nodtag,nodval,K,f];u=Simplify[LinearSolve[Kmod,fmod],a>0&&b>0]; noddis=Partition[u,2]; Print["Computed node displacements:",u];f=Simplify[K.u,a>0&&b>0]; nodfor=Partition[f,2];Print["Node forces including reactions:",f];elefor=PlaneTrussIntForces[nodxyz,elenod,elemat,elefab,noddis];elefor=Simplify[elefor,a>0&&b>0];elesig=PlaneTrussStresses[elefab,elefor]; elesig=Simplify[elesig,a>0&&b>0];Print["Elem forces: ",elefor]; Print["Elem stresses: ",elesig];

Figure 4.15. Top box: driver script for analysis of example truss with all symbolic inputs. Bottom box shows output.

Notes and Bibliography

The hefty Mathematica Book [887] is a reference manual. Since the contents are available online (click onHelp in topbar), buying the printed book makes little sense.16

The best available tutorial to learn the basic (procedural) level of Mathematica is Schaum’s Outlines: Mathe-matica, McGraw-Hill, New York, second edition 2009. Covers up to version 7.0. Contains 750 exercises withanswers. Can be inexpensively purchased from Amazon at www.amazon.com. Learning that level, which issufficient for this course, should take only a few hours.

There is a another nice tutorial by Glynn and Gray [331], list: $35, dated 1999. (Theodore Gray invented the

16 The fifth edition, covering version 5, lists for $49.95 but older editions are heavily discounted on the web, some under$2. There are no printed manual versions for versions 6 and higher — all documentation is online.

4–25

Page 26: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

Notebook front-end that appeared first in version 2.2.) It has the disadvantage of covering only up to version3.0 and may be difficult to find as used book. More up to date and comprehensive is the recent appearedMathematica Navigator in two volumes [721,722]; list: $69.95 but used copies are discounted, down to about$20. The recently appeared Mathematica Cookbook by S. Mangano, published by O’Reilly, covers far moreadvanced programming techniques (for example, object-oriented and functional programming) that are notneeded for this course.

Beyond these, there are many books at all levels that expound on the use of Mathematica for various applicationsranging from pure mathematics to physics and engineering. A web search on September 2003 done onwww3.addall.com hit 150 book titles containing Mathematica, compared to 111 for Maple and 148 forMatlab. A google search done on August 2005 hit 3,820,000 pages containing Mathematica, but here Matlabwins with 4,130,000.

Wolfram Research hosts the MathWorld web site at http://mathworld.wolfram.com, maintained by EricW. Weisstein. It is essentially a hyperlinked, on-line version of his Encyclopœdia of Mathematics [867].

To close the topic of symbolic versus numerical computation, here is a nice summary by A. Grozin, posted onthe Usenet:

“Computer Algebra Systems (CASs) are programs [that] operate with formulas. Mathematica is apowerful CAS (though quite expensive). Other CASs are, e.g., Maple, REDUCE, MuPAD <...>.There are also quite powerful free CASs: Maxima and Axiom. In all of these systems, it is possibleto do some numerical calculations (e.g., to evaluate the formula you have derived at some numericalvalues of all parameters). But it is a very bad idea to do large-scale numerical work in such systems:performance will suffer. In some special cases (e.g., numerical calculations with very high precision,impossible at the double-precision level), you can use Mathematica to do what you need, but there areother, faster ways to do such things.

There are a number of programs to do numerical calculations with usual double-precision numbers.One example is Matlab; there are similar free programs, e.g., Octave, Scilab, R, ... Matlab is verygood and fast in doing numerical linear algebra: if you want to solve a system of 100 linear equationswhose coefficients are all numbers, use Matlab; if coefficients contain letters (symbolic quantities)and you want the solution as formulas, use Mathematica or some other CAS. Matlab can do a limitedamount of formula manipulations using its “symbolic toolbox,” which is an interface to a cut-downMaple. [In 2009, Maple was replaced by MuPAD.] It’s a pain to use this interface: if you want Maple,just use Maple.”

References

Referenced items have been moved to Appendix R.

4–26

Page 27: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Exercises

Homework Exercises for Chapter 4

Plane Truss Analysis by a CAS

EXERCISE 4.1 [C:25=15+10]

�� ��

1 2

4

3(1) (2)

(3) (4)(5)

P

2a

b

x

y

Same E for all members

Members (3),(4) and (5) have equal cross-section areas, and so do (1) and (2). The former are twice the areas of the latter.

Figure E4.1. Truss structure for Exercise 4.1. It has four nodes and fivemembers. Length, material and fabrication data in Exercise text.

Analize the 4-joint, 5-member plane truss depicted in Figure E4.1 using the PlaneTruss.nb MathematicaNotebook provided on the Chapter 4 Index. FEM model: one 2-node bar element per member. Global axes{x, y} centered at node 2. Only load P as shown. Support conditions: node 1 is fixed while node 3 is on aroller that can move only along x .

(N) All-Numerical Analysis. Analize for the following numerical data: dimensions a = b = 10, elasticmoduli: E = 100 for all members, cross section areas A(1) = A(2) = 2, A(3) = A(4) = A(5) = 4, andonly applied load P = 15 (going down, so set fy2 = −15).

Partial answer: uy2 = −1.28033.

Hints for getting nice plots. After defining the problem data enter

aspect=0.5; imgsiz=300; box={{-a-d,0-d},{0+d,0-d},{a+d,0-d},{0-d,b+d}}/.d->.5;

labels={{True,0.03,-1.8,1.8},{True,0.06},{"Times",12,"Plain","Italic"}};

PlotPlaneTrussElementsAndNodes[nodxyz,elenod,"Ex 4.1 truss elems & nodes:",

{aspect,imgsiz,labels}];

After computing node displacements enter

box={{-a-d,0-2*d},{0+d,0-2*d},{a+2*d,0-2*d},{0-d,b+2*d}}/.d->1.5;

PlotPlaneTrussDeformedShape[nodxyz,elenod,noddis,{0,1,2},box,

"Ex 4.1 orig & two deformed shapes",{aspect,imgsiz,{"red","blue","green"}}];

After computing element stresses enter

box={{-a-d,0-d},{0+d,0-d},{a+d,0-d},{0-d,b+d}}/.d->1;

PlotPlaneTrussStresses[nodxyz,elenod,elesig,1,box,

"Truss member stresses",{aspect,imgsiz,labels}];

The member stress plot should look like that pictured in Figure E4.2.

4–27

Page 28: Plane Truss Analysis by a CAS · plane truss as well as some symbolic versions thereof. The program will rely heavily on the development and use of functions implemented using the

Chapter 4: PLANE TRUSS ANALYSIS BY A CAS

Truss member stresses

Figure E4.2. Member stress plot for 5-member plane trussnumerical analysis. Red indicates tension, blue compression.

(S) Symbolic Analysis. Analize for the following symbolic data: dimensions a and b arbitrary (but bothpositive) elastic moduli: E = 100 for all members, cross section areas A(1) = A(2) = A, A(3) = A(4) =A(5) = 2A, and applied load P (positive value if down, so set set fy2 = −P).

Partial answer using Simplify on the displacement vector (that is, u=Simplify[u]):

uy2 = −(2a3 + a2

√a2 + b2 + b2(2b + √

a2 + b2))

P

4E A b2. (E4.1)

Using u=FullSimplify[u,a>0&&b>0] the above expression is further simplified, as shown in the Solutions.

EXERCISE 4.2 [C:10] The Simplify statement in Mathematica is powerful but may need extra help fromyou. For example, suppose that a is a symbol that represents a positive number.

(a) If you say x=Sqrt[a^2], is x set to a?

(b) How about x=Simplify[Sqrt[a^2]]; any change?

(c) How can you tell Simplify that a is positive so that x is set to a?

EXERCISE 4.3 [C:10] What does the operator += do? (If you are a C or C++ programmer, this should beeasy.) Does it work for a vector or matrix?

EXERCISE 4.4 [C:10] Suppose B is a 12 × 5 matrix. What does the built in function Length[B] returns?How about Dimensions[B]?

EXERCISE 4.5 [C:25] Of the PlaneTruss modules stored in Cells 1 though 6 of the supplied Notebook,which ones are general enough to be used for other FEM programs without major change? Explain.

4–28


Recommended