没有合适的资源?快使用搜索试试~ 我知道了~
lab01b.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 45 浏览量
2023-06-18
13:13:34
上传
评论
收藏 175KB PDF 举报
温馨提示
试读
14页
lab01b.pdf
资源推荐
资源详情
资源评论
MATH2071: LAB 1(b): Selected topics in Matlab
Introduction Exercise 1
Adaptive Quadratur e Exercise 2
Roundoff e rrors Exercise 3
Extra Credit Exercise 4
Exercise 5
Exercise 6
Exercise 7
Exercise 8
Exercise 9
Extra Credit
1 Introduction
This version of the first lab is intended only for students who have
already taken Math 2070.
There are two versions of the first lab. This version discusses some spe cial topics and is intended for
students who took Math 2070. If you have not already taken Math 2070, please see Lab 1(a). That version
of the first lab introduces the Matlab environment and programming languag e, and presents the general
format of the work you need to hand in. Students who take Lab 1(a) will be in no way disadvantaged in
this course beca use they “miss e d” Lab 1(b).
Grading policy for this semes ter has changed. Please refer to the grading section in Lab 1a for details.
This lab is concerned with several different topics. It covers material that is supplemental for students
in Math 2071, but new students will not be shortchanged when they miss this material in favor of the
introductory 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 routine
using square mesh elements and an elementary technique for determining which mesh elements need to be
refined 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 in
Lab 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 Quadrature
In this section you will construct a Matlab function to compute the integral of a given mathematical function
over a square reg ion in the plane. One way to do such a task would be to regard the square to be the Cartesian
product of two one-dimensional lines and integrate us ing a one-dimensional adaptive quadrature routine such
as adaptquad from last semester. Instead, in this lab you will be looking at the s quare as a region in the
plane and you will be dividing it up into many (square) subregions, computing the integral of the given
function 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.
1
2. Us e a Gaußian integration rule to integrate the function over each subregion in the lis t and estimate
the resulting error of integration. The integral over the whole region is the sum of the integrals over the
subregions, and similarly the e stimated error is the sum of the estimated errors over the subregions.
3. I f the total estimated error of the integral is small enough, the process is complete. Otherwise , find the
subregion 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.
Adaptive qua drature is build on quadrature and error estimation on a single (square) element. The
discussion starts there.
2.1 Two-dimensional Gauß quadrature
One 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 as
Z
x+h
x
f(x)dx ≈
N
X
n=1
w
n
f(x
n
). (1)
Here, N is the index of the rule. For the case N = 2, the points x
n
are x + h/2 ± h/(2
√
3) and the weights
are w
1
= w
2
= h/2. The degree o f pr e cision is 3, and the error is proportional to h
5
max |f
′′′′
|. (If you look
up the error in a reference somewhere, you will notice that the error is usually given as proportional to h
4
,
not h
5
. 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 gives
Z
x+h
x
Z
y+h
y
f(x, y)dxdy ≈
N
X
n=1
M
X
m=1
w
n
w
m
f(x
n
, y
m
). (2)
For the ca se N = M = 2, (2) becomes
Z
x+h
x
Z
y+h
y
f(x, y)dxdy ≈
4
X
n=1
(h
2
/4)f(x
n
, y
n
), (3)
where the four points (x
n
, y
n
) = (x + h/2 ± h/(2
√
3), y + h/2 ± h/(2
√
3)). These are four points based on
the choices of “+” or “−” signs. Numbering the four choices is up to you. The error is O(h
6
) over his h ×h
square, and (3) is exact for monomials x
n
y
m
with n ≤ 3 and m ≤ 3, and for sums of such monomials. In
the 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 (x
n
, y
n
) = (x + h/2 ± h/(2
√
3), y + h/2 ± h/(2
√
3)). Name the function m-file q elt.m
and have it begin
function q=q_elt(f,x,y,h)
% q=q_elt(f,x,y,h)
% INPUT
% f=???
% x=???
% y=???
2
% h=???
% OUTPUT
% q=???
% your name and the date
(b) Test qelt on the functions 1, 4xy, 6x
2
y, 9x
2
y
2
, and 16x
3
y
3
over the square [0, 1] ×[0, 1] and show
that the result is exact, up to roundoff.
(c) Test qelt on the function 25x
4
y
4
to see that it is not exact, thus showing the degree of precis ion
is 3.
2.2 Error estimation
In 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 the
true error.
Suppose you have a square element with side of length h. If you divide it into four sub-squares with sides
of length h/2, then you can compute the quadrature twice: once on the single square with side of leng th h
and once by adding up the four quadratures over the four squares with sides of length h/2. Consider the
following figure.
h
h
(x, y)
1 2
34
Denote the true integral over this square as q and its approximation over the square with side of length h as
q
h
. Denote the four approximate integrals over the four squares with sides of leng th h/2 as q
1
h/2
, q
2
h/2
, q
3
h/2
,
and q
4
h/2
. Assuming that the fourth derivatives of f are roug hly constant over the squares, the following
expressions can be written.
q
h
= q + Ch
6
q
1
h/2
+ q
2
h/2
+ q
3
h/2
+ q
4
h/2
= q + 4C(h/2)
6
= q + (4/64)Ch
6
. (4)
The second of these is assumed to be more accurate than the first, so use it as the approximate integral,
q
approx
= q
1
h/2
+ q
2
h/2
+ q
3
h/2
+ q
4
h/2
. (5)
The system of equations (4 ) can be solved for the error in q
approx
as
error in q
aprox
=
4
64
Ch
6
=
1
15
q
h
− (q
1
h/2
+ q
2
h/2
+ q
3
h/2
+ q
4
h/2
)
(6)
3
剩余13页未读,继续阅读
资源评论
卷积神经网络
- 粉丝: 338
- 资源: 8460
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功