Example: barber

MATLAB for M152B - Texas A&M University

MATLAB for M152Bc 2009 Peter HowardSpring 20091 MATLAB for M152BP. HowardSpring 2009 Contents1 Numerical Methods for Integration, Part Riemann Sums with Right Endpoints .. Riemann Sums with Midpoints (The Midpoint Rule) .. Assignments .. 72 Numerical Methods for Integration, Part The Trapezoidal Rule .. Simpson s Rule .. Assignments .. 113 Taylor Series in Taylor Series .. Partial Sums in MATLAB .. Assignments .. 174 Solving ODE Symbolically in First Order Equations .. Second and Higher Order Equations .. First Order Systems .. Assignments .. 225 Numerical Methods for Solving Euler s Method.

1 Numerical Methods for Integration, Part 1 In the previous section we used MATLAB’s built-in function quad to approximate definite integrals that could not be evaluated by the Fundamental Theorem of Calculus.

Tags:

  Matlab, 512mb, Matlab for m152b

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of MATLAB for M152B - Texas A&M University

1 MATLAB for M152Bc 2009 Peter HowardSpring 20091 MATLAB for M152BP. HowardSpring 2009 Contents1 Numerical Methods for Integration, Part Riemann Sums with Right Endpoints .. Riemann Sums with Midpoints (The Midpoint Rule) .. Assignments .. 72 Numerical Methods for Integration, Part The Trapezoidal Rule .. Simpson s Rule .. Assignments .. 113 Taylor Series in Taylor Series .. Partial Sums in MATLAB .. Assignments .. 174 Solving ODE Symbolically in First Order Equations .. Second and Higher Order Equations .. First Order Systems .. Assignments .. 225 Numerical Methods for Solving Euler s Method.

2 Higher order Taylor Methods .. Assignments .. 296 Linear Algebra in Defining and Referring to a Matrix .. Matrix Operations and Arithmetic .. Solving Systems of Linear Equations .. Assignments .. 3727 Solving ODE Numerically in First Order Equations .. Systems of ODE .. Higher Order Equations .. Assignments .. 448 Graphing Functions of Two Surface Plots .. Geometric Interpretation of Partial Derivatives .. Assignments .. 529 Least Squares Data Fitting in MATLAB .. Polynomial Regression .. Regression with more general functions .. Multivariate Regression.

3 Assignments .. 6410 Estimating Parameters in Discrete Time Assignments ..6811 Parameter Estimation Directly from ODE, Part Derivative Approximation Method .. Assignments ..7212 Parameter Estimation Directly from ODE, Part The Direct Method .. Assignments ..7613 Direction Plotting Tangent Vectors .. Assignments ..8114 Eigenvalues and Definitions .. Linearization and the Jacobian Matrix .. The Implementation .. Assignments ..9131 Numerical Methods for Integration, Part 1In the previous section we used MATLAB s built-in functionquadto approximate definiteintegrals that could not be evaluated by the Fundamental Theorem of Calculus.

4 In order tounderstand the type of calculation carried out byquad, we will develop a variety of algorithmsfor approximating values of definite integrals. In this section we will introduce the RightEndpoint Method and the Midpoint Method, and in the next section we will develop theTrapezoidal Rule and Simpson s Rule. Whenever numerical methods are used to make anapproximation it s important to have some measure of the size of the error that can occur,and for each of these methods we give upper bounds on the Riemann Sums with Right EndpointsIn our section on the numerical evaluation of Riemann sums, we saw that a Riemann sumwithnpoints is an approximation of the definite integral of a function.

5 For example, if wetake the partitionP= [x0, x1, .. , xn], and we evaluate our function at right endpoints, thenZbaf(x)dx nXk=1f(xk) xk,where the largernis the better this approximation is. If we are going to employthisapproximation in applications, we need to have a more quantitative idea of how close it isto the exact value of the integral. That is, we need an estimate on the error. We define theerror for this approximation byER:=|Zbaf(x)dx nXk=1f(xk) xk|.In order to derive a bound on this error, we will assume (for reasons that will becomeapparent during the calculation) that the derivative offis bounded. That is, we assumethere is some constantMso that|f (x)| Mfor allx [a, b].

6 We now begin computingER:=|Zbaf(x)dx nXk=1f(xk) xk|=|nXk=1 Zxkxk 1f(x)dx nXk=1f(xk) xk|,where we have used the relationZbaf(x)dx=Zx1x0f(x)dx+Zx2x1f(x) + +Zxnxn 1f(x)dx=nXk=1 Zxkxk 1f(x)dx,which follows from a repeated application of the integration propertyZbaf(x)dx=Zcaf(x)dx+Zdcf(x) also thatZxkxk 1dx= (xk xk 1) = xk,we see thatER=|nXk=1 Zxkxk 1(f(x) f(xk))dx|=|nXk=1 Zxkxk 1f (ck(x))(x xk)dx|,where in this step we have used the Mean Value Theorem to writef(x) f(xk) =f (ck(x))(x xk),whereck [x, xk] and so clearly depends on the changing value ofx. One of our propertiesof sums and integrations is that if we bring the absolute value inside we get a larger value.

7 (This type of inequality is typically called atriangleinequality.) In this case, we haveER nXk=1 Zxkxk 1|f (ck(x))(x xk)|dx nXk=1 Zxkxk 1M(xk x)dx=MnXk=1h (xk x)22 xkxk 1i=MnXk=1(xk xk 1)22=M2nXk=1 x2k=M2nXk=1(b a)2n2=M2(b a)2n2nXk=11 =M(b a) is, the error for this approximation isER=M(b a) estimate for Riemann sums with right (x) is continuouslydifferentiable on the interval [a, b] and that|f (x)| Mon [a, b] for some finite the maximum error allowed by Riemann sums with evaluation at right endpoints isER=M(b a) order to understand what this tells us, we recall that we have previously used approximate the integralZ20e x2dx,which to four decimal places is.

8 8821. When we tookn= 4, our approximation was .6352,with an error .6352 =. evaluatingER, we must find a bound on|f (x)|on the interval [0,2], wheref (x) = 2xe can accomplish this with our methods of maximization and minimization from firstsemester; that is, by computing the derivative off (x) and setting this to 0 etc. Keeping inmind that we are trying to maximize/minimizef (x) (rather thanf(x)), we computef (x) = 2e x2+ 4x2e x2=e x2( 2 + 4x2) = 0,which has solutionsx= 1 possible extremal points forx [0,2] are 0,1 2, and 2, and we havef (0) = 0f (1 2) = 2e 12= .8578f (2) = 4e 4= . maximum value of|f (x)|over this interval isM=.

9 8578. Our error estimate guaranteesthat our error forn= 4 will be less than or equal (2)28=. observe that the actual error (.2458) is much less than themaximum error (.4289),which isn t particularly surprising since the maximum error essentially assumes thatf (x)will always be the largest it can be. Finally, suppose we would like to ensure that ourapproximation to this integral has an error smaller than .0001. We need only findnso thatM(b a)22n< . is, we requiren >M(b a)22(.0001).For this example,n >.8578(4).0002= 17, can easily verify that this is sufficient with the followingMATLAB >>f=inline( exp(-x 2) );>>rsum1(f,0,2,17157)ans = Riemann Sums with Midpoints (The Midpoint Rule)In our section on the numerical evaluation of Riemann sums, we saw in the homework thatone fairly accurate way in which to approximate the value of adefinite integral was to use aRiemann sum with equally spaced subintervals and to evaluate the function at the midpointof each interval.

10 This method is called the midpoint rule. Since writing an algorithm for themidpoint rule is a homework assignment, we won t give it here, but we do provide an estimate for the Midpoint (x) is twice continuously differentiableon the interval [a, b] and that|f (x)| Mfor some finite valueM. Then the maximumerror allowed by the midpoint rule isEM=M(b a) proof of this result is similar to the one given above for evaluation at right endpoints,except that it requires a generalization of the Mean Value Theorem; namely Taylor approxi-mation with remainder. Since Taylor approximation is covered later in the course, we won tgive a proof of this estimate Assignments1.


Related search queries