Presentation is loading. Please wait.

Presentation is loading. Please wait.

topics covered Numerical Analysis Examples - applications

Similar presentations


Presentation on theme: "topics covered Numerical Analysis Examples - applications"— Presentation transcript:

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

1 topics covered Numerical Analysis Examples - applications
Solving equations Finding min/max Integrating linear systems: eigenvalue, eigenvector computation Examples - applications

2 Why Numerical Methods are 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.

3 Equations in One Variable
General form f (x ) = 0 Approximation may be good enough Iterative approach with the bisection method Solution where function changes sign and crosses x-axis Functions can have none, one, several, or an infinite number of solutions. Can be solved exactly (algebraically) or numerically.

4 Equations in One Variable (cont.)
x = fzero(function, x0) function: function to be solved x0: initial guess at solution x: the solution 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 ) = 0 f (x ) = c  f (x ) - c = 0 Initial guess: plot the function first. Sometimes the domain can be estimated. Some solutions may not have a physical meaning.

5 Solving a Nonlinear Equation
Find the solution of Rewrite as Plot it to get estimate % Initial plot for estimate fplot('x*exp(-x)-0.2', [0 8]) grid on pause % Find the solution between 0 and 1, guess 0.3 x1 = fzero('x*exp(-x)-0.2', 0.3) % Find the second solution between 2 and 3 % Define an anonymous function F F x*exp(-x)-0.2 fzero(F, 2.5) % What if there is no solution? fzero('x^2+1', 1) Plot: one solution between 0 and 1, another between 2 and 3 No solution case: NaN not a number Other fzero options??? Roots: can use to solve functions in the form of polynomials

6 Newton's Method Solve f (x ) = 0 by repeating the assignment until x is close enough to 0 function y = f(x) y = x^3 + x - 3; function y = df(x) y = 3*x^2 + 1; function [x f conv] = newtfun(fh, dfh, x0) % newtfun solves f(x)=0 using Newton's Method % Input arguments % fh handle to f(x) % dfh handle to f'(x) % x0 initial guess % Output arguments % x root % f f(x) % conv convergence=1, 0 otherwise format long e steps = 0; x = x0; re = 1e-8; myrel = 1; while (myrel > re) & (steps < 20) xold = x; x = x - fh(x)/dfh(x); steps = steps + 1; disp([x fh(x)]) myrel = abs((x-xold)/x); end if myrel <= re conv = 1; else conv = 0; f = fh(x); [r fr conv] 1) Use 2]) set breakpoint, note workspace, myrel clear bkpt continue set cond breakpoint step == 3

7 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 solved x1,x2: interval for minimum x: function minimum Try 0 to 8 Note still local min Try 0 to 1 and note problem with endpoints % lect12_1: Minima and maxima % (single step) % Plot the function F (x) x^3 - 12*x^ *x fplot(F, [0 8]) grid on % Find the minimum between 5 and 6 [x fval] = fminbnd(F, 5, 6) % Change interval to 0 to 8 [x fval] = fminbnd(F, 0, 8) % Change interval to 0 to 1 [x fval] = fminbnd(F, 0, 1) % Find maxima by multiplying function by -1 % and finding minima F2 (x) -F(x) [x fval] = fminbnd(F2, 0, 8) m-files: lect12_1

8 Example Maximum 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

9 Maximum Viewing Angle Angle is between 0 and π/2
Cosine decreases from 1 at Θ = 0, thus maximum angle corresponds to minimum cos(Θ) Do a quick plot of cos(Θ) as a function of x to estimate the solution range Find the minimum with fminbnd Step 1: notice minimum between 10 and 20

10 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 In calculus, integrad is usually a function. In science and engineering, can be a function or data points In numerical intergration, area is found by dividing up into small sections and summing them. Various methods developed to do this. Matlab has three ways

11 Integration in MATLAB q = quad(function, a, b) q = quadl(function, a, b) function: function to be solved a,b: integration limits q: value of integral 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

12 Integrating with Data Points
% lect12_2: Integration with data points % Generate the data points X = 0:pi/100:pi; Y = sin(X); plot(X, Y, 'o-’) % Use trapz to find area under points Q = trapz(X,Y) % Integrate with quad q = 0, pi) q = trapz(x, y) x,y: vectors of data points q: value of integral Example

13 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.2 v (m/s) 5 4.7 4.1 3.8 3.7 2.8

14 Water Flow in a River Flow rate (volume per second)
Total amount of water 60x60x24 converts days to seconds


Download ppt "topics covered Numerical Analysis Examples - applications"

Similar presentations


Ads by Google