1. Trang chủ
  2. » Khoa Học Tự Nhiên

Applied numerical methods with MATLAB for engineers and scientists

585 6 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 585
Dung lượng 29,97 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

About the Aufhor ivPrefoce xiii Guided Tour xvii Panr Our Modeling, Computers, ond Error Anolysis I 1 .2 Conservotion Lows in Engineering ond Science 12 1 .3 Numericol Methods Covered in

Trang 1

www.elsolucionario.net www.elsolucionario.net

Trang 3

About the Aufhor ivPrefoce xiii

Guided Tour xvii

Panr Our Modeling, Computers, ond Error Anolysis I

1 2 Conservotion Lows in Engineering ond Science 12

1 3 Numericol Methods Covered in This Book l3

2 4 U s e o f B u i l t l n F u n c t i o n s 3 0

2 5 G r o o h i c s 3 32.6 Other Resources 36

2.7 Cose Study: Explorotory Doto Anolysis 37

^ l l

r r o b l e m s J YCHAPTER 3

Progromming with MATTAB 42

www.elsolucionario.net

Trang 4

vl CONTENTS

3 3 S h u c t u r e d P r o g r o m m i n g 5 l

3 4 N e s t i n g o n d I n d e n t o t i o n 6 3

3 5 P o s s i n g F u n c t i o n s t o M - F i l e s 6 63.6 Cose Study: Bungee Jumper Velocity 71Problems 75

CHAPTER 4

Roundoff qnd Truncotion Errors 79

4 1 E r r o r s B 04.2 Roundoff Errors 844.3 Truncotion Errors 92

www.elsolucionario.net

Trang 5

CONTENTS YrtCHAPTER 7

Optimizofion 1667.1 Introduciion ond Bockground 167

Lineqr Algebroic Equofions ond Motrices | 938.1 Motrix Algebro Overview 194

8.2 Solving Lineor Algebroic Equotions with MATLAB 2038.3 Cose Study: Currents ond Voltoges in Circuits 205Problems 209

MATLAB Left Division 246Problems 247

www.elsolucionario.net

Trang 6

v I t ! CONIENTS

CHAPTER I I

Motrix lnverse ond Condition 249

1 i l The Motrix lnverse 249

I I 2 Error Anolysis ond System Condition 253

I 1 3 C o s e S t u d y : I n d o o r A i r P o l l u t i o n 2 5 8Problems 261

CHAPTER I2

Iterotive Methods 264l2.l Lineor Systems: Gouss-Seidel 264, l 2 2

CHAPTER I3

Lineor Regression 284

1 3 I S t o t i s t i c s R e v i e w 2 8 6

1 3 2 L i n e o r L e o s t - S q u o r e s R e g r e s s i o n 2 9 2, l 3 3

1 4 5 N o n l i n e o r R e g r e s s i o n 3 2 6

1 4 6 C o s e S l u d y : F i t t i n g S i n u s o i d s 3 2 8

www.elsolucionario.net

Trang 7

'I 5.'l lntroduction to Interpotofion

336I5.2 Newron Interpoloring polynomiol

33gj: j tosron9e tnrerpoloring polynomiol

347rJ.4 tnverse tnterpolotion 350

I J J t x k o p o l o t i o n o n d O s c i l l o t i o n s

3 5 1Problems 355

r r o b t e m s 386Pnnr Fvr Infegrotion ond Differentiotion

3g9 5.1 Overview 3g9

5.2 Port Orgonizotion 39O

1 7 4 S i m p s o n , s R u l e s 4 0 517.5 Higher-Order Newfon_Cotes

Formulos 4j jl7 6 lntegration with Unequol

1 8 2 R o m b e r q I n i e q r o t i o n 4 2 7Numericof Integrotion of Functions

www.elsolucionario.net

Trang 8

1 8 3 G o u s s Q u o d r o t u r e 4 3 2

I 8 4 A d o p t i v e Q u o d r o t u r e 4 3 9I8.5 Cose Study: Root-Meon-Squore Current 440Problems 444

Derivotives of Unequolly Spoced Doto 457,l9.5

Derivotives ond lntegrols for Dofo with Errors 45819.6 Portiol Derivotives 459

I9.2 Numericol Differentiotion with MATLAB 460

I 9 8 C o s e S t u d y : V i s u o l i z i n g F i e l d s 4 6 5Problems 467

Pnnr 5x Ordinory Differentiol Equotions 473

6.1 Overview 473 6.2 Porl Orgonizofion 477 CHAPTER 20

Initiol-Volue Problems 47920.I Overview 481

20.2 Euleis Method 48120.3 lmprovemenls of Euler's Method 48720.4 Runge-Kutfo Methods 493

20.5 Systems of Equotions 49820.6 Cose Study: Predotory-Prey Models ond Choos 50AProblems 509

CHAPTER 2I

Adopfive Merhods ond Stiff Systems 514

21 'l Adoptive Runge-Kutto Methods 5142l 2 Multistep Methods 521

2l 3 Stiffness 525

2 l 4 M A T L A B A p p l i c o t i o n : B u n g e e J u m p e r w i t h C o r d 5 3 12l 5 Cose Study: Pliny's lntermittent Fountoin 532

r r o D l e m s 3 J /

www.elsolucionario.net

Trang 9

C O N T E N T S xl

CHAPTER 22

Boundory-Volue Problems 54022.1 lntrodvction ond Bockground 54122.2 lhe Shooting Method 54522.3 Finite-Difference Methods 552

P r o b l e m s 5 5 9

APPENDIX A: EIGENVALUES 565 APPENDIX B: MATLAB BUILT-IN FUNCTIONS 576 APPENDIX €: MATIAB M-FltE FUNCTIONS 578 BIBLIOGRAPHY 579

rNDEX 580

www.elsolucionario.net

Trang 10

Modqling, CoTpute''i ,

qnd Erior Anolysis

t.t MoTtvATtoN

What are numerical methods and why should you stridy them?

Numerical methods are techniques by which mathematical problems are formulated so

that they can be solved with arithmetic and logical operations Because digital computers

excel at perform.ing such operations numerical methods are sometimes referred to as

com-puter mathematics

In the pre-computer era, the time and drudgery of implementing such calculations riously limited their practical use However, with the advent of fast, inexpensive digttul

se. computers, the role of numerical methods in engineering and scientific problem solving

has exploded Because they figure so prominently in,:'much of our work, I believe that numerical methodsshould be a part of every engineer's and scientist'sbasic education Just as we a.ll must have solid foun-dations in the other areas of mathematics and science,

we should also have a fundamental understanding ofnumerical methods In particular, we should have asolid appreciation of both their capabilities and theirlimitations

Beyond contributing to your overall education

.thog T9 several additibnat reasons why you shoutOstudy numerical methods: ",,,,rr,,,r,,,r,,,,,,

1 Numerical methods greatly expqld the types of ,problems you can address They are capable ofhandling large systems of equations nonlineari-, , d.l, and complicated geometries that are not un-common in engineering and science and that areoften impossible to solve analytically with stan-dard calculus As such" they greatly enhance yourproblem-solving skills

2 Numorical methods allow you to use "canned"

so-ftware with insight During your career, you will

"'T" q*"

www.elsolucionario.net

Trang 11

PART I MODELING, COMPUTERS, AND ERROR ANALYSIS

invariably have occasion to use commercially available prepackaged computer

pro-grarns that involve numerical methods The intelligent use of these programs is greatly

enhanced by an understanding of the basic theory underlying the methods In the

ab-sence of such understanding, you will be left to treat such packages as "black boxes"

with little critical insight into their inner workings or the validity of the results they

produce

3 Many problems cannot be approached using canned programs If you are conversant

with numerical methods, and are adept at computer programming, you can design

your own programs to solve problems without having to buy or commission expensive

software

4 Nr.rrnerical methods are an efficient vehicle fbr learning to use computers Because

nu-merical methods ale expressly designed for computer implementation, they are ideal tbr

illustrating the conrputer's powers and limitations When you successfully implement

numerical methods on a computer, and then apply them to solve otherwise intractable

problenrs, you will be plovided with a dramatic dernonstration of how computers can

serve your professional development At the sarne lime, you rvilI also learn to

acknowl-edge and control the errors of approximation that are part and parcel of large-scale

numerical calculations

5 Numerical methods provide a vehicle fbr you to reinforce your understanding of

math-ernatics Because one tunction of numerical methods is to reduce higher mathematics

to basic arithmetic operations they get at the "nuts and bolts" of some otherwise

obscure topics Enhanced understanding and insight can result from this alternative

perspective

With these reasons lls motivation we can now set out to understand how numerical

methods and digital computers work in tandem to generate reliable solutions to

mathemat-ical problems The remainder of this book is devoted to this task

1.2 PART ORGANIZATION

This book is divided into six parts The latter five parts focus on the major areas of

numer-ical methods Although it might be tempting to jump right into this material, Part One

con-sists of four chapters dealng with essential background material

Chapter 1 provides a concrete example of how a numerical method can be employed

to solve a real problem To do this, we develop tt muthematical model of a fiee-falling

bungee jumper The model, which is based on Newton's second law, results in an ordinary

differential equation After first using calculus to develop a closed-form solution, we then

show how a comparable solution can be generated with a simple numerical method We

end the chapter with an overview of the major areers of numerical rnethods that we cover in

Parts Two through Sir

Chapters 2 and 3 provide an introduction to the MATLAB' software environment

Chapter 2 deals with the standard way of operating MATLAB by entering commands one

at a time in the so-called t'alculator nuttle.This interactive mode provides a straightforward

means to orient you kl the enviroument and illustrates how it is used ibr common

www.elsolucionario.net

Trang 12

I.2 PART ORGANIZATION

Chapter -l shows how MATLAB's programming mode provides a vehicle for

assem-bling individual commands into algorithms Thus, our intent is to illustrate how MATLAB

serves as a convenient programming environment to develop your own software

Chapter I deals with the irnportant topic of error analysis, which must be understood

for the effective use of numerical methods The first part of the chapter focuses on the

roundoJf errors thar result because digital computers cannot represent some quantities

exactly The latter part addresses truncation errctrs that arise fiom using an approximation

in place of an exact mathematical procedure

www.elsolucionario.net

Trang 13

o Learning how mathematical models can be formulated on the basis of scientificprinciples to simulate the behavior of a simple physical system.

r Understanding how numerical methods irlford a means to generate solutions in arnanner that can be irnplemented on a digital computer

o Understanding the different types of conservation laws that lie beneath the modelsused in the various engineering disciplines and appreciating the diff'erencebetween steady-state irnd dynamic solutions of these models

r Learning about the difterent types of numerical methods we will cover in thisbook

YOU'VE GOT A PROBTEM

uppose that a bungee-jumping company hires you You're given the task of ing the velocity of a jumper (Fig l.l ) as a function of time during the free-fall part

predict-of the jump This inlbrmation will be used as part predict-of a larger analysis to determine thelength and required strength of the bungee cord for jumpers of different mass

You know from your studies ofphysics that the acceleration should be equal to the ratio

of the tbrce to the mass (Newton's second law) Based on this insight and your knowledge

www.elsolucionario.net

Trang 14

I I A SIMPTE MATHEMATICAL MODEL

Because this is a ditlerential equation, you know that calculus might be used to obtain

an analytical or exact solution for u as a function of / However, in the following pages, wewill illustrate an alternative solution approach This will involve developing a con.rputer-oriented numerical or approximate solution

Aside from showing you how the computer can be used to solve this particular lem, our more general objective will be to illustrate (a) what numerical methods are and(b) how they figure in engineering and scientific problen solving In so doing, we will alsoshow how mathematical n.rodels figure prominently in the way engineers and scientists usenumerical methods in their work

prob-I l A SIMPTE MATHEMATICAT MODET

A motlrcnntical ntodel can be broadly defined as a tbrmulation or equation that expressesthe essential features of a physical system or process in mathematical terms In a very gen-eral sense, it can be represented as a functional relationship of the fonn

D e o e n d e n ( - / i n d e n e n c l e n t f o r c i n e \ ' , _ , : J [ ' , , p u r a n ) e t e r s | ( l l )

v a n a o l e \ v a n a D t e s l u n c t l o n s , fwhere the de;tendent variable is a characteristic that usually reflects the behavior or state

of the system:- the independettt variables are usually dimensions such as time and space,along which the system's behavior is being determined; the parameters are retlective of thesystem's properlies or composition; and thelbrring.functiotts are external intluences actingupon it

The actual mathematical expression of Eq (1.1) can range from a sirnple algebraicrelationship to large complicated sets of diff-erential equations For example, on the basis ofhis observations, Newton formulated his second law of motion, which states that the timerate of change of momentum of a body is equal to the resultant force acting on it The ntath-ematical expression, or model, of the second law is the well-known equation

Trang 15

6 MATHEMATICAL MODELING, NUMERICAL METHODS, AND PROBLEM SOLVING

The second law can be recast in the format of Eq ( 1 l) by merely dividing both sides

func-Equation ( 1.3) has a number of characteristics that are typical of mathematical models

of the physical world

It describes a natural process or system in mathematical terms.

It represents an idealization and sirnplification of reality That is the model ignores ligible details of the natural process and focuses on its essential manif'estations Thus,the second law does not include the effects of relativity that are of minimal importancewhen applied to objects and forces that interact on or about the earth's surface at veloc-ities and on scales visible to humans

neg- Finally, it yields reproducible results and, consequently, can be used fbr predictive poses For example, if the force on an object and its mass are known, Eq ( 1.3) can beused to compLlte acceleration

pur-Because of its simple algebraic form, the solution of Eq (1.2) was obtained easily

However, other mathernatical models of physical phenomena may be much more complex

and either cannot be solved exactly or require more sophisticated mathematical techniquesthan simple algebra for their solution To illustrate a more complex model of this kind,Newton's second law can be used to determine the terminal velocity of a free-falling bodynear the earth's surface Our falling body will be a bungee jumper (Fig 1.1) For this case,

a model can be derived by expressing the acceleration as the time rate of change of ther,'elocity (tluldr) and substituting it into Eq (1.3) to yield

d u F

where u is velocity (in meters per second) Thus, the rate of change of the velocity is equal

to the net force acting on the body normalized to its mass If the net force is positive, theobject will accelerate Ifit is negative the object will decelerate Ifthe net force is zero, theobject's velocity will remain at a constant level

Next, we will express the net force in terms of measurable variables and parameters

For a body talling witlrin the vicinity of the earth, the net force is composed of two ing forces: the downward pull of gravity Fp and the upward force of air resistance Fy( F i g 1 1 ) :

If force in the downward direction is assigned a positive sign, the second law can beu.sed to formulate the force due to pravity as

F o : m 8where g is the acceleration due to gravity (9.81 m/s2)

( 1 6 )

www.elsolucionario.net

Trang 16

I I A SIMPLE MATHEMATICAL MODEI 7

Air resistance can be fbrmulated in i.i variety of ways Knowledge from the science offluid ntechanics suggests that a gtrod first approxirrration wouliJ be to assume that it is pro-portional to the square of the velocitl,,

- l

where r',1 is a proporticlnalitv constant called the drag coefticient (kg/m) Thus the greaterthe fall velocity, the greater the uprvard fbrce due to air resistance The parameter c./ ac-counts lbr properties ofthe ialling object, such as shape or surface roughness, that affect airresistance For the present c&s€, c,7 might be a function of the type of clothing or the orien-tation used by the jumper during free tall

The rlet fbrce is the difference between the downward and upwi.rrd force Therefbre,

of change (d u I dt 1 of the variable that we are interested in predicting However, in contrast

to the solution of Newton's second law in Eq ( 1.3), the exact solution of Eq ( 1.8) for thevelocity of the jumper cannot be obtirined using simple algebraic manipulation Rather,more adt'anced techniques such as those of calculus nrust be applied to obtain an exact oranalytical solution For example, if the jumper is initially at rest (r., : 0 at / : 0), calculuscan be used to solve Eq ( 1.8) for

u(/) :r,ff*"n( ,8,)y i l t /

EXAMPLE I I

www.elsolucionario.net

Trang 17

MATHEMATICAL MODELING, NUMERICAL METHODSAND PROBTEM SOLVING

Solution Inserting the parameters into Eq (1.9) yields

which can be used to compute

increoses with time ond osympfoiicolly opprooches o terminol velociiy

Trang 18

] I A SIMPLE MATHEMATICAL MODEL 9

time, a constant velocity called the terminol velocitt', of 51.6983 m/s (115.6 mi/h) is

reached This velocity is constant because, eventually, the force of gravity will be in

bal-ance with the air resistbal-ance Thus the net force is zero and acceleration has ceased

Equation ( I 9) is called an anabtical or closed-form solution because it exactly

satis-fies the oliginal diffbrential equation Unfortunately, tlrere are mirny matlrematical nrodels

that cannot be solved exactly In many of these cases, the only alternative is to develop a

numerical solution that approximates the exact solution

Nttnterical ntethods are those in which the mathemirtical problerr is refbrmulated so it

can be solved by arithmetic operations This can be illustrated for Eq ( 1 8) by realizing that

the time tate of change of velocity can be approximated by (Fig 1.3):

d t t

-d t

A uN

where Au and At are differences in velocity and time computed overflnite intervals, u(r1)

is velocity at an initial time ri, and u(ria;) is velocity at some later time f11 Note that

du ldt = Lu I Lt is approximate because Ar is flnite Remember from calculus that

Trang 19

t o MATHEMATICAL MODELING, NUMERICAL MEIHODS, AND PROBLEM SOLVING

Equation ( 1.1 I ) is callecl a Jinite-diJJeren.ce opprcrirnation of the derivative Jt Iirnc /,

It can be substituted into Eq (1.8) to give

{1t

where the nomenclature u; clesignates velocity attinle /i and At : ti+t - ti

We can now see that the differential equation has been transformed into an equation thatcan be used to determine the velocity algebraically at ri+l using the slope and previous val-ues of u and t If you are given an initial value for velocity at some time l;, you can easily com-pute velocity at a later time f 11 This new value of velocity at l;11 can in tum be employed toextend the cornputation to velocity at l;12 and so on Thus at any time along the way,New valne : old vahle * slope x step size

This approach is tbrnrally called Euler's metlnd We'll discuss it in more detail when weturn to diff'erential equations later in this book

E X A M P L E 1 2 N u m e r i c o l S o l u i i o n t o t h e B u n g e e J u m p e r P r o b l e m

' Problem Stoiement Perform t h e s a m e c o r n p L l t a t i o n a s in E x a m p l e 1 1 b u t u s e E q ( J 1 3 )

to colnpute velocity with Euler's method Employ a step size of 2 s fbr the calculation

Solution At the start of the computation (/{) :0), the velocity of the jumper is zero.Using this infbrmation and the parameter values from Example I I , Eq ( 1.13) can be used

to corxpute velocity at 11 - 2 s:

r, : o * fr.r' - H,o,rl x 2 : te.62rls

L 6 8 r IFor the next interval lfiom r : 2 b 4 sJ, the colnplrtation is repeated, with the result

Trang 20

I 1 A SIMPLE MATHEMATICAL MODEL t t

Terminal velocity

F I G U R E I 4

Compcrison of the numericol ond onclyticol solutions for the bungee iumper problem

The calculation is continued in a similar fashion to obtain additional values:

u, m/s0

The results are plotted in Fig 1.4 along with the exact solution We can see that the

nu-merical method captures the essential features of the exact solution However, because we

have employed straighfline segments to approximate a continuously curving function,

there is some discrepancy between the two results One way to minimize such

discrepan-cies is to use a smaller step size Forexample, applying Eq (1.13) at 1-s intervals results in

a smaller error, as the straighrline segments track closer to the true solution Using hand

calculations, the effort associated with using smaller and smaller step sizes would make

such numerical solutions impractical However, with the aid of the computer, large

num-bers of calculations can be performed easily Thus, you can accurately model the velocity

of the jumper without having to solve the differential equation exactly

Trang 21

r 2 MATHEMATICAL MODELINGNUMERICAL METHODS, AND PROBLEM SOLVING

As in Example 1.2, a cornputational price nrust be paid for a nrore accurate numericalresult Each halving of the step size to attain morc accuracy leads to a doubling of the nurn-ber of computations Thus, we see that there is a trade-off between accuracy and computa-tional effort Such trade-offs figure prominently in numerical methods and constitute animportant theme of this book

1.2 CONSERVATION L/AWS lN ENGINEERING AND SCIENCE

Aside from Newton's second law there are other major organizing principles in scienceand engineering Among the most important of these are the conserv,ation lan:s Althoughthey form the basis for a variety of complicated and powerful mathematical models, thegreat conservation laws of science and engineering are conceptually easy to understand.They all boil down to

This is precisely the fbrmat that we empioyed when using Newton's law to develop a forcebalance for the bungee jumper tEq ( 1.8)1

Although simple, Eq (1.14) embodies one of the most fundarnental ways in whichconservation laws are used in engineering and science-that is to predict changeswith respect to time We will give it a special name-the time-variable (or transient)computation

Aside from predicting changes, another way in which conservation laws are applied isfbr cases where change is nonexistent If change is zero, Eq (I.14) becomes

Change : 0 : increases - decreasesor

Thns, ifno change occurs, the increases and decreases nrust be in balance This case, which

is also given a special narne-the stea(ly-state calculation-has many applications in neering and science For example, fbr steady-state incompressible fluid flow in pipes, theflow into a junction musl be balanced by flow going out as in

engi-Flow in : flow outFor the junction in Fig I 5, the balance can be used to compute that the flow out of thefourth pipe must be 60

For the bungee jumper, the steady-state condition would correspond to the case wherethe net lbrce was zero or [Eq (1.8) with du ldt : 0l

www.elsolucionario.net

Trang 22

I.3 NUMERICAL METHODS COVERED IN THIS BOOK r 3

F I G U R E I 5

A f o w b o o n c e f o r s t e o d y i n c o m p r e s s i b e f u i d fl o t v o t t h e ju n c l i o n o f p i p e s

Table l I summarizes some models and associated conservation laws that figure nently in engineering Many chemical engineering problems involve mass balances forreactors The mass balance is derived from the conservation of mass It specifies that thechange of mass of a chemical in the reactor depends on the amount of mass flowing inminus the n.rass flowing out

promr-Civil and mechanical engineers often focus on models developed from the tion of momentum Forcivil engineering, force balances are utilized to analyze structuressuch as the simple truss in Table 1.1 The same principles are employed for the mechanicalengineering case studies to analyze the transient up-and-down motion or vibrations of anautomobile

conserva-Finally electrical engineering studies en-rploy both current and energy balances to modelelectric circuits The current balance, which results from the conservation of charge, is simi-lar in spirit to the flow balance depicted in Fig 1.5 Just as flow mnstbalance at the junction

of pipes, electric current must balance at the junction of electric wires The energy balancespecifies that the clranges of voltage around any loop of the circuit must add up to zero

We should note that there are many otherbranches of engineering beyond chemical, civi,,electrical, and mechanical Many of these ale related to the Big Four For exalnple, chemicalengineering skills are used extensively in areas such as environmental, petroleum, and bio-rnedical engineering Sirnilarly, aerospace engineering has much in cornmon with mechani-cal engineering We will endeavor to include examples from these areas in the coming pages

I.3 NUMERICAT METHODS COVERED IN THIS BOOK

We chose Euler's method for this introductory chapter because it is typical of many otherclasses of numerical methods In essence, most consist of recasting mathematical opera-tions into the simple kind of algebraic and logical operations compatible with digital com-pllters Figure 1.6 summarizes the major areas covered in this text

P i p e 3

F l o w o u t : 1 2 0

www.elsolucionario.net

Trang 23

l 4 MATHEMATICAT MODELING, NUMERICAT METHODS, AND PROBLEM SOLVING

TABTE l.l Devices ond types of bolonces fhot ore commonly used in ihe four moior oreos of engineering For

eoch cose, lhe conservotion low on which the bolonce is bosed is specified

Field Device OrganizingPrinciple MathematicalExpression

I current (i) = 0

I ' R '

Voltage balance:

a{A&-l, , R , - - 2 r * z YJ - - f

L \A7\ Ji:R:

Around each loop

I emf's - I voltage drops for resistors

> 6 - > a : 0

Mass balance: ffi

inort ff_ * ourpurOver a unit of time period

I vertical forces (I'u) : 0

Force balance: I Upward force

I

l r = 0 I

V Downward force

m Li = downward force - upward force

www.elsolucionario.net

Trang 24

I.3 NUMERICAL METHODS COVERED IN THIS BOOK r 5

lal Part 2: Roots and optimization f(xl

Roots: Solve for.r so thatfi-r) = 0

Optimization: Solve for x so that/'(r) = 0

lbl Part 3: Linear algebraic equations

f\x\

Given the a's and the b's solve for the.r's

a ' , r x t t a r 2 x a = b ,

arrx, 1- a,x, = b2

ldl Part 5: Integration and differentiation

Integration: Find the area under the curve

Differentiation: Find the slooe of the curve

lel Part 6: Differential equations

G i v e n

dv Av

, h : N : f l t ' Y l

solve for r as a function of r

.,Ii+r = -]'i + "f(ti, yJAr

Trang 25

t 6 MATHEMATICAL MODELING, NUMERICAT METHODS, AND PROBLEM SOLVING

Part Two deals with two related topics: root finding and optimization As depicted inFig 1.6a, root locotiorr involves searching for the zeros of a function In contrast, optimiza-rion involves determining a value or values of an independent variable that correspond to a

"best" or optirnal value of a function Thus, as in Fig 1 6a, optimization involves ing maximir and minima Although somewhat different approaches are used, root locationand optimization both typically arise in design contexts

identify-Part Three is devoted to solving systems of simultaneous linear algebraic equations(Fig 1.6&) Such systerns are similar in spirit to l'oots of equations in the sense that they areconcemed with values that satisfy equations However, in contrast to satistying a singleequatiou, a set of values is sought that simultaneously satisfies a set of linear algebraicequations Such equations arise in a variety of problem contexts and in all disciplines of en-gineeriug and science In particular, they originate in the mathenratical modeling of Jargesystems of interconnected elements such as structures, electric circuits and fluid networks.However, they are also encountered in other areas of numerical methods such as curve tit-

l i n g l r n d d i f f e r e n t i a l e q u u t i o n s

As an engineer or scientist you will often have occasion to fit curves to data points Thetechniques developed for this pulpose can be divided into two general categories: regressionand interpolation As described in Part Four tFig 1.6c'1, regression is ernployed where there

is a significant degree of error associirted with the data Experimental results are often of thiskind For these situations the strategy is to derive a single curve that represents the generaltrend of the data without necessarily matching any individual points

In contrast, interpolution is used where the objective is to determine intermediate ues between relatively error-free data points Such is usually the case for tabulated infor-mation The strategy in such cases is to flt a curve directly through the data points and r.rsethe curve to predict the intermediate values

val-As depicted in Fig 1.6d, Part Five is devoted to integlation and differentiation Aplrysical interpretation of ruurrcricctl iltegratiott is tlre determination of the area under acurve Integration has many applications in engineering and science, ranging from the de-termination of the centroids of oddly shaped objects to the calculation of total quantitiesbased on sets of discrete measurements In addition, nurnerical integration formulas play animporttrnt role in the solution of diffbrential equations Part Five also covers methods fornume.rical difr'erentiation As you know fiom your study of calculus, this involves the de-termination of a function's slope or its rate of change

Finally Part Si.x focuses on the solution of ordirro'v di.fterential equations (Fig 1.6e).Such equations are of great significance in all areirs of engineering and science This is be-cause many physical laws are couched in terms of the rate of change of a quantity rather thanthe magnitude of the quantity itself Examples range from population-forecasting rnodels(rate ofchange of population) to tlre acceleration of a tallin-e body (rate ofchange ofvelocity).Two types of problems are addressed: initial-value and boundary-value problems

www.elsolucionario.net

Trang 26

Use the conservation of cash to compute the balance on 6/ l,

111.811, and 9/1 Show each stcp in thc computation ls this

a steady-state or a transient computation?

1,3 Repeat Example 1.2 Compute thc velocity to t: l2 s,

with a step size of (a) I and (b) 0.5 s Can you make any

statement regarding the crrors of thc calculation based on the

results?

1.4 Rather than the nonlinear rclationship of Eq ( 1.7), you

might choose to model the upward fbrce on the bungee

j u m p c r a s a l i n e a r r e l a t i o n r h i p :

r l

wherer'' : a first-order drag coefTicient (kg/s)

(a) Using calculus, obtain the closed-fbnn solution fbr thc

case where thejurnper is initially at rcst (u : 0 at 1: 0)

(b) Repeat the numerical calculation in Example 1.2 with

the same initial condition and oarameter values Use a

value of 12.5 kg/s fbr c'

1.5 For the free-talling bungee jumper with linear drag

(Prob I 4) assume a first jumper is 70 kg and has a drag

co-efficient of l2 kg/s If a secondjurnper has a drag coefficient

of 15 kg/s and a mass of 75 kg, how long will it take her to

reach the same velocity jumpcr I rcached in l0 s'l

1.6 For the fiee-falling bungce jumper with linear drag

(Prob 1.4), compule the velocity of a free-talling parachutist

usrng Er-rler's method fbr thc casc whcre rr : 80 kg and c' :

l0 kg/s Perfbrm thc calculation from / : 0 to 20 s with a

step size of I s Use an initial condition that the parachutist

has an upward vclocity of 20 m/s at /: 0 At r: l0 s,

as-sume that the chute is instantaneously deployed so that thc

drag cocllicient jumps to 50 kg/s

1.7 Thc amount of a uniformly distributed radioactive taminant contained in a closed reactor is measured by itsconcentration c (becquerel/liter or Bq/L) The contaminantdecrcases a1 a decay rate proportional to its concentration;

con-that isDecay rate : -tc

I 5 I 2 3 3 where ft is a constant with units of day I Thercfore,

accord-ing to Eq (1.14), a rrass balance fbr the reactor can bewntten as

d c

k t

d t/ changc \ / decrease \

t " t : t , l

\ i n m a r s / \ U l d e c a S /(a) Use Euler's mcthod to solve this equation from t : 0 to

I d w i t h k : 0 2 d r E m p l o y a s t e p s i z e o f A r : 0 I d The concentration at /:0 is l0 Bq/L

(b) Plot the solution on a semilog graph (i.e., ln c versus /)and detennine the slopc Intcrpret your results

l ll A storage tank (Fig Pl.8) contains a liquid at depth )where ,r' : 0 when the tank is half full Liquid is withdrawn

at a constant flow rate Q to meet demands The contents areresupplied at a sinusoidal rate 3Q sin2(t) Equation (1.14)can be written fbr this systcrn as

Trang 27

r 8 MATHEMATICAL MODELING, NUMERICAL METHODS, AND PROBLEM SOTVING

or, since the surface area A is constant

r / t ' O O

: : 3 : s i n - f t ) _ :

d r A A

Use Euler's method to solve for the depth _v fron-r r : 0 to

I0 d with a step size of 0.5 d The parameter values are A :

1200 m2 and p : 500 m3/d Assume that the initial condition

i s y : 0

1.9 For the same storage tank described in Prob 1.8,

sup-pose that the outflow is not constant but rather depends on

the depth For this case, the differential equation fbr depth

is the molecular weight of the gas (1br air 28.97 kg/krnol),and rR is the ideal gas constant [8.31,1 kPa m]/(kmol K)]

1.12 Figure P1.12 depicts the various ways in which an ilge man gains and loses water in one day One liter is ingested

aver-as food, and the body metabolically produces 0.3 liters Inbreathing air, the exchange is 0.05 liters while inhaling, and0.4 liters while exhaling over a one-day period The body willalso lose 0.2, 1.4.0.2 and 0.35 liters through sweat, urine,feces, and through the skin, respectively To maintain steadystate, how much water must be drunk per day?

l.13 In our example of the fiee-falling parachutist, we sumed that the acceleration due to gravity was a constantvalue of 9.8 m/s2 Although this is a decent approxinrationwhen we are examining falling objects near the surtace ofthe earth, the gravitational lbrce decreases as we lroveabove sea level A rnore general representation based onNewton's inverse square law of gravitational attraction can

Use Euler's method to solve for the depth )' fiom t : 0 to

10 d with a step siz-e of 0.5 d The parameter values are A :

1200 m2, O:500 mr/d, and cv: -300 Assurne that the

ini-tial condition is _r : 0

1.10 The volume flow rate through a pipe is given by Q :

rA, whele u is the average velocity and A is the

cross-sectional area Use volume-continuity to solve for the required

area in pipe 3 of Fig P I 10

l.ll A group of 30 students attend a class in a room which

lneasures l0 m by 8 m by 3 m Each student takes up about

0.075 mr and gives out about 80 W of heat (l W = I J/s)

Calculate the air temperature rise during the first l5 minutes

of the class if the room is completely sealed and insulated

Assume the heat capacity C, tbr air is 0.7 18 kJ/(kg K)

As-sume air is an ideal gas at 20 "C and 101.325 kPa Note that

the heat absorbed by the air O is related to the mass of the air

Trang 28

PROBLEMS r 9

where g(r) : gravitational acceleration at altitude r (in m)

measured upward fronr thc earth's surface tm/s2) gtO) :

gravitational acceleration at the earth's surface (! 9.8 rn/sr),

a n d R : t h e c a r t h ' s r a d i u s ( = 6 3 7 x 1 0 6 m t

(a) In a fashion similar to the derivation of Eq (1.8), use a

force balance to derive a ditlerential equation for

veloc-ity as a function of time that utilizes this more complete

representation of gravitation However lbr this

deriva-tion, assume that upward velocity is positive

(b.1 For the case where drag is negligible, use the chain rule

to express the differential equation as a function of

alti-tude rather than time Recall that the chain rule is

du du d-r

dt d.r dt

(c) Use calculus to obtain the closed form solution where

u = u,, at.r : 0

(d) Use Euler's rnethod to obtain a numerical solution from

r : 0 to 100,000 m using a step of 10,000 m where the

initial velocity is 1400 m/s upward Compare yor,rr result

u ith the analytical solr"rtion

l l{ Suppose that a spherical droplet of liquid evaporates at

a rate that is proportional to its surface area

d V

: : - k A

d t

rvhere V: volume 1mm3), t : time (hr), k : the evapol'ation

rate (mm/hr), and A : surface area 1mmr) Use Euler's

method to conrpute the volume of the droplet from I : 0 to

l0 min using a step size of 0.2,5 min Assume that ft :

0.1 mm/min and that the droplet initially has a radius of 3 mm

Assess the validity oi your results by determining the radius

of your final computed volume and verifying that it rs sistent with the evaporation rate

con-l.l-5 Newton's law oicooling says that the temperature of abody changes at a rate proportional to the difference betweenits temperature and that of the surrounding medium (the am-bient temperature)

d T -;

a t : - k ( T - T " )

where Z: the temperature of the body ("C), r : time (rnin),

k : the proportionality constant (per minute), and 7, : thsarnbient temperature ("C) Suppose that a cup of coft-ee orig-inally has a temperature of 68 'C Use Euler's method tocompute the temperature from I : 0 to l0 min using a stepsize of I min if I : 2l "C and ft : 0.01 7/min

|.16 Afluid is pumped into the network shown in Fig P1.16

lf 0, : 0.6 O., : 0.4 Qt:O.2 and Qo : 0 1 mr/s determinethe other flows

i ilr*?-i=-i I

iri:;$

b o,l "i "i "'i t ' i l i

i- er-:- -s ;-*-*L*-i

F I G U R E P I I 6

www.elsolucionario.net

Trang 29

the colon ope'rator', and thc .l irs;p.r,:c and 1oq1,;piic:, - l'ttnctitlns.

Llnderstanding thc priority rulcs firr constructing mathernatical cxpre-ssions.

Gaining a gencral undcrstanding ol'built-in lr-rnctions and how you can lcarn tnore

a b o u t t h e m w i t h M A ' I ' L A B ' s H e l p f a c i l i t i e s Learning how to usc vectors to crcirtc a sinrplc linc plot basecl on an equation

YOU'VE GOT A PROBLEM

I n Chap l we usctl ir firrce balance to detcrnrine the tcrminal velocity of a fiec-falling

I o h j e c l l i k c i r h L r r r g c e j u r n p c r T

wher-e r.,, : ternrinal velocity (nr/s), ,q : gravilational accelerertion (m/s') m : mass (kg),and t',, : a drag coefl'icient (kg/m) Aside from prcdicting the terminal velocity, this equa-tion can also be rearranged to compute the drag coefficicnt

Trang 30

The clata in Table 2' I

perfornirrg many typcs.ol.ctilculaticrns ln particular,

it prtlvides a very nice tool to inrple.

mass, thiswere col-

2 r

" " !i:H:i:iilll1l;|; "v t o ope rute * *' 1 P, :', :,'^ ::::::: :::):i:I;:;: ii' ffi :l

ff.:ll,'Ji:'.:il{; ilJffill'.":ili: ;::'# "' *.,ln "'" u'T- ":1 crc ati n g p r ot s r n

Chap 3, we show how sr'rch commands can be usecl

to create MAft-AB progralns'

o n e f u r t h e r n o t c ' [ h i s c h a p t e r h a s b e e n w r i t t e n a s a l r a n c l s - t l r r c x c l c i s e T h a t i s , y o t t

shoultl rcad it while ,,tring in fiont o1'youl cornpLrtcr

The m.st elficient way to beconle

o r o f i c i e n t i s t ' o a c t t r a l l y i n l ; l l c t l e n t t h c c t l t n t r r a t r c l s o n M A T L A B a s y o u p r o c c c d t h r o t r g h t h e

following material'

fUeif-A,B uses three primary witrclows:

Conrtnancl winclow' Uscd to enter commancls and data'

C."pt,i.* windtlw' Used kr display plots and graphs'

gaii winclow' Usecl tt'r creute and edit M-filcs'

In this chapter, we wilr r.rake usc of thc c.mmand ancl

graphics wind.ws' ln chap' 3 we

*iii ut the edit window to crcatc M-iiles'

Afier starting Md;;;' tht tu'ntunti window will

open with thc commancl promptbcing disPlaYcd

I a s c q u c n t i i t l l l t s h i t r n a s y o L l t y p c i n c o n t The calculator nlode o1'MATLAB oper''rtcs lr

-mancls line by line' For each cotnurancl' you get'r-result Lh::s'

you can think of it as

oper-^ii"g f if, a uery l'ancy calcttlator' For exanlplc' if you typc tn

Trang 31

to a variable of your own choosing.

> > A = 5 ;

You can type several commands on the same line by separating them with comnlas orsemicolons If you separatethem with commas, they will be displayed, and if you usethesemicolon, they will not For example,

> > a - 4 , A = 6 ; x = 1 ;4

MATLAB treats names in a case-sensitive rnanner-that is the nan)e a is not the same

as the name a To illustrate this enter

Trang 32

2 2 A S S I G N M E N T 23

We can assign complex values to variables since MATLAB handles complex metic automatically The unit irnaginary number

arith-"/J ir preassigned to the variable i.

Consequently, a complex value can be assigned simply as in

> - p i

3 r 4 r 6Notice how MATLAB displays fbur decinral places If you desire additional precision,enter the fbllowing:

to be used to represent the unit for display For example,

Trang 33

24 MATLAB FUNDAMENTALS

2.2.2 Arroys, Vectors qnd Mqtrices

An arrat' is a collection of values that are represented by a single variable name dincnsirnalarral't arc callcd tu'/ort and two-dinensional anavs are c'alled nrutnce: Thescalars used in Section 2.2.1 are actually a matrix with one low and one column

One-Brackets are used to enter arrays in the comnranil mode For exan.rple, a row vector can

be assisned as fbiiows:

1 2 3 4 5 1

Note that this assignment overrides the previous assignment of a : 4

In practice, row vectors are rarely used to solve rnathematical problerns When wespeak of vectors we usually ret-er to column vectors, which are more contmonly used Acolumn vector can be entered in several ways Try them

4 b S

1 t )

A rnatrix of values can be assigned as lblkrws:

In addition the Enter key (carriage return) can be used to separirte the rows For example

in the following case, the Enter key woulcl be struck after the 3 the 6 and the I to assign thematrix:

Trang 34

d n s

l ) x-

Note that subscript notation can be used to access an individual elcment of an array

For exarnple the firurth element o['thc column vccfor t) can be displayed as

: > b ( 4 ), t l t s i .

8

F o r a n a r r a y , A ( n r , n ) s e l e c t s l h e c l e m c n t i n m t h r o w a n d t h c n t h c o l u r n n F o r e x a m p l e ,

A ( : , 1 )6

Thsre are sevcral built-in functions that can be used 1o creatc matrices For cxarnplc,the ones llnd zero:i l'unctions creatc vcctol's or matrices filled with ones and zeros

respectively Both have two argumcnts, thc first tbr the nulnber of rows and the second tbrthc number-of columns For example to creatc a 2 x 3 matrix tl1'zeros:

2.2.3 The Colon Operotor

The colon opefator is a powerfll tool fbr crerting andused to separate tw'o nunrbers, MATLAB generales lhe

manipulating arrays If a colon is

Trang 35

> - " f = i 0 : - 1 : 5

Aside from creating series of numbers, the colon can also be used as a wildcard to lect the individual rows and columns of a matrix When a colon is used in place of a spe-cific subscript, the colon reprcsents the entire row or column For example, the second row

se-of the matrix A can be selected as in

2 2 4 T h e r l n s p a c e o n d l o s s p a c e F u n c t i o n sThe iinspacre and logspace functions provide other handy tools to generate vectors ofspaced points The 1 inspace function generates a row vector ofequally spaced points Ithas the form

I i n s p a c e ( x l x 2 , n )which generates n points between xl and x2 For example' > l i n s p a c e ( 0 , 1 , 6 )

0 0 2 0 0 0 0 4 0 0 0 0 6 0 0 0 o B O O O 1 0 0 0 0

lf the n is omitted, the function alromatically generates 100 points

The logspace l-unction generates a row vector that is logarithmically equally spaced

It has the form

I f n

whiFor

Alsc

Res'

plv

thesing

Trang 36

> > Y - P t / 4 ;

> > y ^ 2 4 5

0 5 5 3 3Results of calculations can be assigned to a variable, as in the next-to-last example, or sim-ply displayed, as in the Iast example

As with other computer calculation, the priority order can be overridden with theses For example, because exponentiation has higher priority then negation, the follow-ing result would be obtained:

paren-> paren-> Y = 4 ^ 2

y

-_ r 6Thus,4 is first squared and then negated Parentheses can be used to override the priorities

Trang 37

c a l c u l a t i o n s A l t h o u g h w e w i l l d e s c r i b e s u c h c a l c u l a t i o n s i n d e t a i l i n C h a p 8 i t i s w o r t hintroducing sorne of those manipulations here.

The irtner product of two vectors (dot product) can be calculated using the * operator,: : , d * b

r 1 0and likewise, the outer pnrluct

> > b = f 4 5 t j l ' ;Now try

Trang 38

> > A * aMATLAB automatically displays the error message:

? ? ? E T r a r u s i n g = - > m t i m e s

I n n e r m a t r i x d i m e n s i o n s m u s t a Q f r e e Matrix-rnatrix multiplication is carried out in likewise fashion:

> > A * A

3 0 3 5 4 2

6 6 B 1 9 6

1 0 2 1 2 6 1 5 0Mixcd operations with scalars are also possible:

> > A / p i

a n s =

0 3 1 8 3 0 5 3 6 6 0 9 5 4 9' I

2 1 3 2 I 5 9 1 5 1 9 0 9 9

? , 2 , ? , 8 2 2 , \ 4 6 \ 2 , 8 6 4 8

We must always remember that MATLAB will apply the simple arithmetic operators

in vector-matrix fashion if possible At times, you will want to carry out calculations item

by item in a matrix or vector MATLAB provides for that too For example,

3 0 3 5 4 ? ,

6 6 8 1 9 t r

r 0 2 t 2 , 6 1 5 0results in matrix multiplication of a with itself

What if you want to square each element of e? That can be done with

Lo as el ement - hy -c I eme n t t tpa rut it tn.s

Trang 39

F *

-Alternatively, you can type b and press the up-arrow once and it will automatically bring

up the last command beginning with the letter b The up-arrow shortcut is a quick way tofix errors without having to retype the entire line

2.4 USE OF BUIIT.IN FUNCTIONS

MATLAB and its Toolboxes have a rich collection of built-in functions You can use onlinehelp to find out nrore about them For example if you want to learn about the 1og function,type rn

Trang 40

2,4 USE OF BUILT-IN FUNCTIONS 3 l

the function name Try

There are also functions that perform special actions on the elements of matrices and

arrays For example, the sum function returns the sum of the elements:

Ngày đăng: 16/10/2021, 20:13