COMPUTING AND DATA ANALYSIS WITH EXCEL Numerical integration techniques
Outline 1 Quadrature in one dimension Mid-point method Trapezium method Simpson s methods Uniform random number generation in Excel, RAND Random numbers from other distributions
Numerical Integration The Midpoint method The midpoint rule rectangle method is one of many ways of approximating the area under a curve. It involves dividing the area under the curve into a collection of rectangles whose heights are determined by the values of the function. Evaluate, using the midpoint method with n= 10 the function 1 4 x dx 1
Numerical Integration The Midpoint method Your task Evaluate 2 0 3 27x 4 dx using the Midpoint method with n=10.
Numerical Integration The Trapezium Method The trapezium rule is another method for approximating the area under a curve when it is not feasible to employ integration. It follows the simple rule that the area under the curve can be approximated by sum of the area of strips (of trapezoids) of equal width. Formula: Given y= f(x) b 1 y dx 2 h y 0 2 y1 y2 y3... yn 1 yn a Where h y 0 y n is the width (equal for each trapezium) is the height of the first trapezium (point a) is the height of the last trapezium (point b)
Numerical Integration The Trapezium Method The Trapezium rule under Excel Question: Evaluate intervals 1 4 x dx 1 using the trapezium rule with 10 equal-size 2
Numerical Integration The Trapezium Method Step 1: Set out the table to compute the width and height of each trapezium. From the limits of integral and the number of trapeziums, we can calculate width = (b-a)/n where b and a are respectively the upper and lower limits on integral.
Numerical Integration The Trapezium Method Step 2: Set up a table for the width and the corresponding height or y value
Step 3: Numerical Integration The Trapezium Method Finally we apply the formula or trapezium rule to estimate the area under the curve b 1 y dx 2 h y 0 2 y1 y2 y3... yn 1 yn a
Numerical Integration The Trapezium Method Your task Evaluate 2 0 3 27x 4 dx using the trapezium rule with 10 equal-size intervals
Numerical Integration Simpson s Method (the 1/3 rule) The Simpson method is an improvement on the trapezium approximation of the area under the curve. This works where we have even number of intervals. Formula: b a h f ( x) dx 3 y 0 4 y1 y3... yn 1 2 y2 y4... yn2 yn
Numerical Integration Simpson s Method Example: Using the Simpson s rule with 10 equally spaced intervals, evaluate 1 4 x dx 1
Numerical Integration Simpson s Method Your task Evaluate a) using the Simpson s rule with 10 equal-size intervals (n=10). 3 dx b) For n= 12 x 2 1 2 0 3 27x 4 dx Note: Where the number of intervals, n is a multiple of 3, we may use the 3/8 rule as follows: b 3 y dx 8 h ( y0 yn) 2 y3 ymult. of 3...) 3( y1 y2 y4... yn2 a
Uniform random number generation in Excel Using the RAND function Example: Generate 25 random numbers (5 x 5) between 0 and 1 The RAND function takes no parameters but generates random numbers between 0 and 1. Like all other Excel functions, start the entry with an equal sign and type in the name of the function as in the diagram. You are prompted to select the right function by the intellisense as you type.
Uniform random number generation in Excel Using the RAND function Next, use the autofill handle to fill the next 4 columns, see fig. (a). With the row of data selected, use the autofill handle to scroll down the next 4 rows, see fig. (b). (a) (b)
Uniform random number generation in Excel Using the RANDBETWEEN function Example Generate 100 random numbers (10 x 10) between 0 and 100 The RANDBTWEEN function takes two parameters, the lower and upper bounds and generates random numbers between these (inclusive).
Uniform random number generation in Excel Using the RANDBETWEEN function Next, use the autofill handle to fill the next 9 columns. With the row of data selected, use the autofill handle to scroll down the next 9 rows, see fig. below. You may use the F9 key to recalculate/generate a new set of random values.
Random Numbers from Other Distributions Using the Analysis ToolPak -Random Number Generator Step 1: From the Data Tab, select Data Analysis from the Analysis group. Step 2: From the pop up window, select Random Number Generation and click OK
The output may be displayed in a new window or in a selected range of cells on the same worksheet. Random Numbers from Other Distributions Using the Analysis ToolPak -Random Number Generator A new window requiring keyboard input is now opened. Number of variables: represent the number of COLUMNS of data required. Number of Random Numbers: is simply the number of ROWS Distribution: Click on the dropdown menu to select the distribution you want to implement (Uniform, Normal, Bernoulli, Poisson, Patterned or Discrete) The Random Seed is used to set random number generator to generate the same set of values all the time.
Random Numbers from Other Distributions Using the Analysis ToolPak -Random Number Generator Depending on the distribution selected, you may have to type in other parameters. E.g. for normal distribution, the mean and standard deviations are by default 0 and 1 respectively. The following table shows 100 numbers generated from the Excel Random Number Generator under NORMAL distribution.