Download presentation
Presentation is loading. Please wait.
Published byPercival Dean Modified over 8 years ago
1
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F123 – Zürich E-Mail: michael.sokolov@chem.ethz.ch http://www.morbidelli-group.ethz.ch/education/index
2
2Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Quadrature methods Single Step Trapezoidal Rule Composite Trapezoidal Rule
3
Composite Midpoint Rule 3Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature ax1x1 x2x2 x n-1 b Constant function for each step
4
Composite Trapezoidal rule 4Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature ax1x1 x2x2 x n-1 b Linear function for each step
5
Composite Simpson rule 5Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature The interval is split up and the areas are integrals of quadratic functions ax1x1 x2x2 x n-1 b Parabola through f(a), f(x1), f(x2)
6
Gauss Quadrature 6Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Depending on the polynomial order n nodes x j and weights w j are used To approximate the area under a function. n = 3
7
Degree of exactness Trapezoids are areas under linear functions Linear functions are approximated exactly; q = 1 Simpson uses the area under quadratic functions Polynomials up to order three are approximated exactly! q = 3 Even degree interpolation polynomials get one degree of exactness for free Example 7Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
8
Degree of exactness vs. order of accuracy When a non-exact result is obtained, the error is proportional to the step size to a certain power s, the order of accuracy It can be shown that s = q + 1 for sufficiently smooth f 8Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
9
Solution of Nonlinear Functions 9Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F123 – Zürich E-Mail: michael.sokolov@chem.ethz.ch http://www.morbidelli-group.ethz.ch/education/index
10
Zero of a Nonlinear Function Problem definition: Find the solution of the equation f(x) = 0 for scalar valued f and x; Look for the solution either in An interval, generally – ∞ < x < ∞ In the uncertainty interval [a, b], where f(a)f(b) < 0 Types of algorithms available: 1.Bisection method 2.Substitution methods 3.Methods based on function approximation Assumptions: In the defined intervals, at least one solution exists We are looking for one solution, not all of them 10Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
11
Bisection Method 1.Define starting interval [a,b] (check that f(a)*f(b) < 0) 2.Compute x = mean([a, b]) 3.Redefine the interval Set either a = x or b = x so that f(a)*f(b) < 0 is still fulfilled 4.Iterate 2 and 3 until the requested precision is reached Advantages After n iterations, the interval is reduced by 2 n Final precision can be predicted a priori Disadvantages Function characteristics are not used to speed up the algorithm 11Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature a b x a
12
Newton Method The Newton method is based on Taylor expansion Advantages Theoretically fastest convergence Disadvantages Convergence is not guaranteed even if the uncertainty interval is known If the derivative must be calculated numerically, the secant method is more convenient 12Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature x0x0 x1x1
13
Secant Method The Secant is based on the same principles as the Newton method, but it approximates the derivative numerically Advantages Does not require the analytical first order derivative Disadvantages Convergence is not assured even if the uncertainty interval is known Convergence is slower 13Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature x 0 = 1.8 x 1 = 1.7 SecantNewton
14
How does Matlab do it? Nonlinear Functions fzero fzero finds the zero of a scalar valued function; It uses a combination of bisection, secant, and inverse quadratic interpolation methods roots roots finds all the roots of a polynomial function; It computes the eigenvalues of the companion matrix, which correspond to the roots of the polynomial A = diag(ones(n-1,1),-1); A(1,:) = -c(2:n+1)./c(1); eig(A); Where c is the vector of the polynomial coefficients 14Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
15
Matlab Syntax Hints x = fzero(fun, x0); fun is a function taking as input a scalar x, returning as output the scalar function value f(x) x0 is either an initial guess (if it has length 1) or an uncertainty interval (if it has length 2, then f(x0(1))*f(x0(2)) < 0 must be fulfilled) x = roots(c); c is a vector containing the polynomial coefficients in the order 15Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
16
Assignment 1: Quadrature method comparison Consider the function and its integral in the range [-2,2] Using a discretization x k = a + hk with h = (b-a)/(N-1) and k = 0,1,…,N, the quadratures are given by The Gaussian quadrature is defined for the polynomial order n as: 16Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Midpoint Trapezoidal Simpson (1)(2) (3) (4) (5) (6)
17
Assignment 1: Quadrature method comparison gauss_int(f,N,a0,b0) 1.Define a new function of the form gauss_int(f,N,a0,b0) where you discretize x and evaluate the overall area as a sum of subareas evaluated with the Gaussian quadrature above. Note that for n = 3 and. logspace(1, 5, 100) 2.In your main file, vary N between 10 and 10 5 using logspace(1, 5, 100), and calculate the relative absolute error of the four approximations compared to the analytical solution of (2) for each h. loglog 3.Plot h vs. the relative errors using loglog for the four methods. polyfit 4.The order of accuracy can be determined as the slope of the double- logarithmic plot. Use polyfit to obtain the corresponding slope for each of the methods. a.In the case of non-linear behavior reduce the fitting to the linear area. Why can the non-linear behavior at very small relative errors be neglected? b.Compare your results with the rules from the lecture. fprintf 5.Provide the output in an appropriate format using fprintf. 6.Think of an alternative way to implement the Gaussian quadrature for a given number of approximation points N. 17Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
18
Exercise: CSTR Multiple Steady States Consider a CSTR where a reaction takes place We assume the following V = const., i.e. Q in = Q out = const. Perfect coolant behavior, i.e. T C,in = T C,out = const. Constant density and heat capacity of the reaction mixture Constant reaction enthalpy Constant feed, i.e. c A,in = const., T in = const. 18Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
19
CSTR Mass and Energy Balances The mass and energy balances read With the T-dependent reaction rate constant 19Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
20
Dimensionless Mass and Energy Balances If we define We get a dimensionless form 20Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
21
CSTR Temperature Equilibrium The steady state concentration of A reads The temperature in steady state is therefore given by 21Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
22
Assignment 2 1.Plot the total heat flow from and to the reactor vs. the dimensionless reactor temperature Use α = 49.46; κ 0 = 2.17e20; K C = 0.83; η = 0.33 and θ C = 0.9. 2.Implement and use the secant method to find the three steady state temperature of the CSTR. function [x,xvec] = secantRoot(f,x0) Use a function of the form function [x,xvec] = secantRoot(f,x0) xvec Also return the x-values calculated as a vector xvec. The calculation steps of the secant method can be found on slide 7 The secant method uses two starting guesses; from x0, calculate x1 = (1+ε)*x0. Suggest a value for ε (not too small). abs(x k – x k-1 ) > 1e-8 f(x k ) > 1e-6 n 1e-8 and f(x k ) > 1e-6 and n < 1e5 You will have to store two x-values at any given iteration, that is x k and x k-1 22Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
23
Assignment 2 (continued) 3.In what range of x0 can you converge to the intermediate solution? What feature of the function determines which solution is found? 23Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.