100% Guaranteed Results


18-330 – Exercise 1: Finite differences via interpolation Solved
$ 29.99
Category:

Description

5/5 – (1 vote)

Consider the simplest forward finite-difference approximation for ๐‘“โ€ฒ(๐‘ฅ):
๐‘“(๐‘ฅ + โ„Ž) โˆ’ ๐‘“(๐‘ฅ)
๐‘”(โ„Ž) โˆถ=
โ„Ž
When we calculate this numerically, there are two sources of error: truncation error, coming from approximating the exact Taylor expansion with a finite piece of it, and floating-point roundoff error.
1. Suppose that we perturb the input, โ„Ž, by ฮ”โ„Ž. Calculate (analytically) an approximation to the (absolute) error ฮ”๐‘” on the output to first order in ฮ”โ„Ž; you should find that it grows like โ„Žโˆ’1.
2. Suppose that the input perturbation size is ๐œ–mach; the error from [1] is then the roundoff error. Find an estimate for the value of โ„Ž at which the truncation error balances with the roundoff error, and find the size of the error there. Compare this with the plot that we did in class. 3. Consider an interval [๐‘Ž,๐‘] and let ๐‘š be the midpoint of the interval. Use Lagrange interpolation to find an analytical expression for the unique quadratic function that passes through (๐‘Ž,๐‘“(๐‘Ž)), (๐‘š,๐‘“(๐‘š)) and
(๐‘,๐‘“(๐‘)).
4. Use your result from [3] to derive the centered difference approximation for the derivative ๐‘“โ€ฒ(๐‘ก๐‘˜) in terms of equally-spaced points ๐‘ก๐‘˜ separated by a distance โ„Ž.
5. What approximation does it give for the second derivative ๐‘“โ€ณ(๐‘ก๐‘˜)?
6. Use [3] to find a backward difference expression for ๐‘“โ€ฒ(๐‘ก๐‘˜) using information at nodes ๐‘ก๐‘˜โˆ’2 and ๐‘ก๐‘˜โˆ’1.
7. Find numerically the rate of convergence of the results from [3] and [4] for equally-spaced points separated by a distance โ„Ž for the function sin(2๐‘ฅ) at ๐‘ฅ = ๐œ‹/4, for values of โ„Ž between 10โˆ’6 and 10โˆ’1.
Exercise 2: Integration using Simpsonโ€™s rule
In this problem we will derive the second-order Newtonโ€“Cotes quadrature rule,
๐‘
known as Simpsonโ€™s rule, for calculating โˆซ ๐‘“(๐‘ฅ)๐‘‘๐‘ฅ.
๐‘Ž
Suppose you are given an ๐‘-point quadrature rule with nodes (๐‘ก๐‘˜)๐‘˜=0๐‘ and weights (๐‘ค๐‘˜)๐‘๐‘˜=0 for integrating over the interval $[-1, 1]. That is, the ๐‘ก๐‘˜ are ๐‘ + 1 points with โˆ’1 โ‰ค ๐‘ก๐‘˜ โ‰ค 1, and the ๐‘ค๐‘˜ are given to you such that
๐‘ค๐‘˜ ๐‘“(๐‘ก๐‘˜)
1. Construct a new quadrature rule for integrating over a general interval
[๐‘ข,๐‘ฃ]. I.e., find ๐‘กโ€ฒ๐‘˜ and ๐‘ค๐‘˜โ€ฒ such that
๐‘ฃ ๐‘
โˆซ ๐‘“(๐‘ฅ)๐‘‘๐‘ฅ โ‰ƒ โˆ‘๐‘ค๐‘˜โ€ฒ๐‘“(๐‘กโ€ฒ๐‘˜)
๐‘ข ๐‘˜=0
Derive the basic second-order Newtonโ€“Cotes quadrature rule for ๐‘“(๐‘ฅ)๐‘‘๐‘ฅ, as follows:
2. Use your results from [Exercise 1] to find the degree-2 polynomial ๐‘2 that agrees with ๐‘“ at the three points ๐‘ฅ = โˆ’1,0,1. (Leave your result in terms of the values ๐‘“(โˆ’1), ๐‘“(0) and ๐‘“(1).)
3. Integrate ๐‘2 interval [โˆ’1,1] to approximate โˆซ๐‘“ in terms of ๐‘“(โˆ’1, ๐‘“(0) and ๐‘“(1). Express this result as a quadrature rule.
4. Combine your answers to [2] and [3] to write down the basic (not composite) Simpsonโ€™s rule for integrating f over [๐‘ข,๐‘ฃ].
5. Given an interval [๐‘Ž,๐‘], subdivide it into ๐‘ equal-width subintervals, apply the basic Simpsonโ€™s rule to integrate ๐‘“ over each subinterval, and sum the results to obtain the composite Simpson rule for integrating ๐‘“ over [๐‘Ž,๐‘]. How many samples of f does this rule require? (Be careful not to overcount).
Exercise 3: Using Newtonโ€“Cotes methods
1. Implement the composite 0th (rectangle), 1st (trapezoid), and 2nd-order (Simpson) Newtonโ€“Cotes quadrature rules for integrating an arbitrary function over an arbitrary interval with ๐‘ + 1 points. Each should be a single function like rectangle(f, a, b, N).
Note that in the case of Simpsonโ€™s rule, we are using a total of ๐‘ + 1 points; how many intervals does this correspond to?
2. Calculate (2๐‘ฅ)๐‘‘๐‘ฅ using each method. Plot the relative error
๐ผapprox(๐‘) โˆ’ ๐ผexact
๐ธ(๐‘) โˆถ=
๐ผexact
as a function of ๐‘ for ๐‘ in the range [10,106] (or use a higher or lower upper bound depending on the computing power you have available).
Do these errors correspond with the expectations from the arguments in lectures?
3. Do the same for )๐‘‘๐‘ฅ. Use the erf function from the SpecialFunctions.jl package to calculate the โ€œexactโ€ result. [Hint: Check carefully the help for that function to make sure of the definition used.]
4. We showed that the trapezium rule has error at most ๐’ช(โ„Ž2). Consider the following integral of a smooth, periodic function:
2๐œ‹
๐ผ = โˆซ exp(cos(๐œƒ))๐‘‘๐œƒ
0
Plot the error in the trapezium rule in this case. How fast does it decay with ๐‘? [This will be important later in the course.]
Note that this integral can be calculated exactly as 2๐œ‹๐ผ0(1), where ๐ผ0 is a modified Bessel function, which can be evaluated at 1 using the SpecialFunctions.jl package as besseli(0, 1).
Exercise 4: Euler method for ODEs
1. Implement the Euler method in a function euler(f, x0, ฮดt, t_final), assuming that ๐‘ก0 = 0. Your code should work equally well if you put vectors in, to solve the equation xฬ‡ = f(x).
2. Use your code to integrate the differential equation ๐‘ฅฬ‡ = 2๐‘ฅ from ๐‘ก = 0 to ๐‘ก = 5 with initial condition ๐‘ฅ0 = 0.5. Plot the exact solution and the numerical solution for values of ๐›ฟ๐‘ก = 0.01,0.05,0.1,0.5. On a different plot show the relative error as a function of time, compared to the analytical solution.
3. Do the same for ๐‘ฅฬ‡ = โˆ’2๐‘ฅ with initial condition ๐‘ฅ0 = 3.
4. For the above two cases, calculate the error at ๐‘ก = 5 when the time interval is split into ๐‘ pieces for ๐‘๐‘๐‘’๐‘ก๐‘ค๐‘’๐‘’๐‘›10๐‘Ž๐‘›๐‘‘1000. Plot the error as a function of ๐‘. What is the rate of convergence as โ„Ž โ†’ 0?
A pendulum satisfies the ODE ๐œƒ +ฬˆ sin(๐œƒ) = 0, where ๐œƒ is the angle with the vertical.
5. Show analytically that the quantity (โ€œenergyโ€) ๐ธ(๐œƒ, ฬ‡ ฬ‡
is conserved along a trajectory, i.e. that ๐‘‘๐‘ก๐‘‘ [๐ธ(๐œƒ(๐‘ก),๐œƒ(๐‘ก)) = 0]ฬ‡ , so that ๐ธ(๐œƒ(๐‘ก),๐œƒ(๐‘ก)) = ๐ธ(๐œƒ(๐‘กฬ‡ 0),๐œƒ(๐‘กฬ‡ 0)).
6. Solve this equation using the Euler method for initial conditions (0,1) to show that the energy is not conserved.
7. Draw the phase plane. Explain graphically what is happening in terms of what each step does.
8. Plot ๐ธ as a function of time for different values of ๐›ฟ๐‘ก. How fast does it grow? Explain this in terms of what happens at each step.

Reviews

There are no reviews yet.

Be the first to review “18-330 – Exercise 1: Finite differences via interpolation Solved”

Your email address will not be published. Required fields are marked *

Related products