Unformatted text preview:

MATH2071: LAB 1(b): Selected topics in MatlabIntroduction Exercise 1Adaptive Quadratur e Exercise 2Roundoff e rrors Exercise 3Extra Credit Exercise 4Exercise 5Exercise 6Exercise 7Exercise 8Exercise 9Extra Credit1 IntroductionThis version of the first lab is intended only for students who havealready taken Math 2070.There are two versions of the first lab. This version discusses some spe cial topics and is intended forstudents who took Math 2070. If you have not already taken Math 2070, please see Lab 1(a). That versionof the first lab introduces the Matlab environment and programming languag e, and presents the generalformat of the work you need to hand in. Students who take Lab 1(a) will be in no way disadvantaged inthis course beca use they “miss e d” Lab 1(b).This lab is concerned with several different topics. It covers material that is supplemental for studentsin Math 2071, but new students will not be shortchanged when they miss this material in favor of theintroductory ma terial pr esented in Lab 1(a).The first topic discussed in this lab is a simple approach in a two-dimensional adaptive integration routineusing square mesh elements and an elementary technique for determining which mesh elements need to berefined in order to meet the error requirements.The s econd topic is a demonstratio n of how roundoff error arises in a matrix calculation.The third topic is a brief introduction to ordinary differential equations. This topic is also covered inLab 1(a) and s erves as an introduction to the methods discussed in later labs.If you prefer, you will find a version of this la b in Adobe pdf format here.2 Adaptive QuadratureIn this section you will construct a Matlab function to compute the integral of a given mathematical functionover a square reg ion in the plane. One way to do such a task would be to regard the square to be the Cartesianproduct of two one-dimensional lines and integrate us ing a one-dimensional adaptive quadrature routine suchas adaptquad from last semester. Instead, in this lab you will be looking at the s quare as a region in theplane and you will be dividing it up into many (square) subregions, computing the integral of the givenfunction over each subregion, and adding them up to g et the integral over the given square.The basic outline o f the method used in this lab is the following:1. Start with a list containing a single “subregion”: the square region of integration.2. Us e a Gaußian integration rule to integrate the function over each subregion in the lis t and estimatethe resulting error of integration. The integral over the whole region is the sum of the integrals over thesubregions, and similarly the e stimated error is the sum of the estimated errors over the subregions.13. I f the total estimated error of the integral is small enough, the process is complete. Otherwise , find thesubregion with largest error, replace it with four smaller subregio ns, and return to the previous step.The way the notion of a “ list” is implemented will introduce a data structure (discussed in detail below)that is more versatile than arrays or matrices.2.1 Two-dimensional Gauß quadratureOne simple way of deriving a two-dimensional integration formula over a square is to use iterated integration.In this case, the square has lower left coordinate (x, y) and side length h, so the square is [x, x+h]×[y, y+h].Recall that a one-dimensional Gauß integration rule can be written asZx+hxf(x)dx ≈NXn=1wnf(xn). (1)Here, N is the index of the rule. For the case N = 2, the points xnare x + h/2 ± h/(2√3) and the weightsare w1= w2= h/2. The degree o f pr e cision is 3, and the error is proportional to h5max |f′′′′|. (If you lookup the error in a reference somewhere, you will notice that the error is usually given as proportional to h4,not h5. The extra power of h appearing in (1) comes from the fact that the region of integration is [x, x+h].)Applying (1) twice, once in the x-direction and once in the y-direction givesZx+hxZy+hyf(x, y)dxdy ≈NXn=1MXm=1wnwmf(xn, ym). (2)For the ca se N = M = 2, (2) becomesZx+hxZy+hyf(x, y)dxdy ≈4Xn=1(h2/4)f(xn, yn), (3)where the four points (xn, yn) = (x + h/2 ± h/(2√3), y + h/2 ± h/(2√3)). These are four points based onthe choices of “+” or “−” signs. Numbering the four choices is up to you. The error is O(h6) over his h ×hsquare, and (3) is exact for monomials xnymwith n ≤ 3 and m ≤ 3, and for sums of such monomials. Inthe following exercise, you will implement this method in Matlab.Exercise 1:(a) Write a Matlab function to compute the integral of a function over a single square element using(3) w ith (xn, yn) = (x + h/2 ± h/(2√3), y + h/2 ± h/(2√3)). Name the function m-file q elt.mand have it beginfunction q=q_elt(f,x,y,h)% q=q_elt(f,x,y,h)% INPUT% f=???% x=???% y=???% h=???% OUTPUT% q=???% your name and the date(b) Test qelt on the functions 1, 4xy, 6x2y, 9x2y2, and 16x3y3over the square [0, 1] ×[0, 1] and showthat the result is exact, up to roundoff.(c) Test qelt on the function x4y4to see that it is not exact, thus showing the de gree of precision is3.22.2 Error estimationIn order to do any sort of adaptive quadrature, you need to be able to estimate the error in one element.Remember, this is only an estimate because without the true value of the quadrature, you cannot get thetrue error.Suppose you have a square element with side of length h. If you divide it into four sub-squares with sidesof length h/2, then you can compute the quadrature twice: once on the single square with side of leng th hand once by adding up the four quadratures over the four squares with sides of length h/2. Consider thefollowing figure.hh(x, y)1 234Denote the true integral over this square as q and its approximation over the square with side of length h asqh. Denote the four approximate integrals over the four squares with sides of leng th h/2 as q1h/2, q2h/2, q3h/2,and q4h/2. Assuming that the fourth derivatives of f are roug hly constant over the squares, the followingexpressions can be written.qh= q + Ch6q1h/2+ q2h/2+ q3h/2+ q4h/2= q + 4C(h/2)6= q + (4/64)Ch6. (4)The second of these is assumed to be more accurate than the first, so use it as the approximate integral,qapprox= q1h/2+ q2h/2+ q3h/2+ q4h/2. (5)The system of equations (4 ) can be solved for the error in qapproxaserror in qaprox=464Ch6=115qh− (q1h/2+ q2h/2+ q3h/2+ q4h/2)(6)In the following exercise you will write a Matlab function to


View Full Document

Pitt MATH 2071 - LABORATORY I

Download LABORATORY I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LABORATORY I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LABORATORY I 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?