ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

15
ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Transcript of ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Page 1: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

ES 314 Nov 27, 2012

• Numerical Analysis

Source: Maurice Herlihy, Brown Univ.

Page 2: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

topics covered

• Numerical Analysis– Solving equations– Finding min/max– Integrating– linear systems: eigenvalue, eigenvector

computation

• Examples - applications

Page 3: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Why Numerical Methodsare Important

• Exact answers are sometimes hard or impossible to achieve in practice

• Numerical methods provide an approximation that is generally good enough

• Useful in all fields of engineering and physical sciences, but growing in utility in the life sciences and the arts

– Movement of planets, stars, and galaxies– Investment portfolio management by hedge funds– Quantitative psychology– Simulations of living cells– Airline ticket pricing, crew scheduling, fuel planning

Figure is a Babylonian clay tablet showing an approximation of 21/2.

Page 4: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Equations in One Variable

• General form f (x ) = 0• Approximation may be

good enough• Iterative approach with

the bisection method

Page 5: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Equations in One Variable (cont.)

• Function can be specified as– a mathematical expression as a string with no

predefined variables– function handle– name of an anonymous function

• Must be in the form f (x ) = 0f (x ) = c f (x ) - c = 0

x = fzero(function, x0)

function: function to be solvedx0: initial guess at solutionx: the solution

Page 6: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Solving a Nonlinear Equation• Find the solution of

• Rewrite as

• Plot it to get estimate

2.0 xxe

2.0)( xxexf

Page 7: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Newton's Method

• Solve f (x ) = 0 by repeating the assignment

until x is close enough to 0

)(

)(

xf

xfxx

Page 8: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Finding Minima and Maxima

• Local minima or maxima occur when the derivative of the function is zero

x = fminbnd(function, x1, x2)

function: function to be solvedx1,x2: interval for minimumx: function minimum

5.3625.4012)( 23 xxxxf

m-files: lect12_1

Page 9: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

ExampleMaximum Viewing Angle

• For best view in a theater, sit at distance x such that angle Θ is maximum

• Find x with the configuration shown

• Applying Law of Cosines

2222

22222

4152

36)41()5()cos(

xx

xx

Page 10: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Maximum Viewing Angle• Angle is between 0 and π/2• Cosine decreases from 1 at Θ = 0, thus

maximum angle corresponds to minimum cos(Θ)

1. Do a quick plot of cos(Θ) as a function of x to estimate the solution range

2. Find the minimum with fminbnd

Page 11: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Numerical Integration

• Find the area under the curve of a function

• Examples– Area and volume– Velocity from acceleration– Work from force and

displacement• Integrand can be

a function or set of data points

b

adxxfq )(

Page 12: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Integration in MATLAB

• Function must be written for element-by-element operations

• Function must be well-behaved between a and b (no vertical asymptote)

• Difference is in method of integration

q = quad(function, a, b)q = quadl(function, a, b)

function: function to be solveda,b: integration limitsq: value of integral

Page 13: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Integrating with Data Points

• Example

q = trapz(x, y)

x,y: vectors of data pointsq: value of integral

2)sin(0

dxx

Page 14: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Water Flow in a River• To estimate the amount

of water that flows in a river during a year, consider the cross section shown.

• The height h and speed v are measured on the first of each month.

Day 1 32 60 91 121 152 182 213 244 274 305 335 366

h (m) 2.0 2.1 2.3 2.4 3.0 2.9 2.7 2.6 2.5 2.3 2.2 2.1 2.0

v (m/s) 2.0 2.2 2.5 2.7 5 4.7 4.1 3.8 3.7 2.8 2.5 2.3 2.0

Page 15: ES 314 Nov 27, 2012 Numerical Analysis Source: Maurice Herlihy, Brown Univ.

Water Flow in a River

• Flow rate (volume per second)

• Total amount of water

hwvQ

2

1

)246060(t

tQdtV