University of California Polynomial Interpolants Questions Response

User Generated

qnynbjnat

Mathematics

University of California Davis

Description

please provide some basic explanation about the answer of each question and also details are required. For programming question, please use matlab. Appreciate,

Unformatted Attachment Preview

Homework 1 Math 128A Due Friday, 10/11/19, 11:59 PM 1. Consider the function 1 − cos(x) . x2 f (x) = (a) Evaluate limx→0 f (x) = L. (b) As x → 0, at what rate does f (x) → L? (c) Compute f (x) as written on a computer for values of x = 10−1 , 10−2 , . . . , 10−10 . Comment on your results. (d) Suppose that we are able to represent floating point numbers with N decimal digits of accuracy. Around what value of r will the evaluation of f (x) produce very large relative errors when |x| < r? (e) Rearrange the expression for f (x) to a mathematically equivalent expression so that the this new function evaluates accurately for very small values of x. Verify the success of your rearrangement computationally. Are there values of x where you expect accuracy problems with your rearrangement? 2. The Taylor series about x = 0 for the arctangent function converges for −1 < x ≤ 1 and is given by ∞ X (−1)n x2n+1 −1 tan (x) = . 2n + 1 n=0 Write a computer program to evaluate tan−1 (x) by truncating the series to N + 1 terms. (a) Use your program to approximate π by evaluating tan−1 (1) for different values of N . Give the approximations and errors in a table. To compute the errors, use that π ≈ 3.141592653589793. (b) Repeat part (a) using x = 3−1/2 . (c) Plot the errors in the approximations from parts (a) and (b) vs. the number of terms in the truncated sum on a log-log graph and a semilog (log-linear) graph (MATLAB commands are loglog and semilogy, respectively). What do these graphs indicate about the rate of convergence? (d) Analytically derive bounds for the errors in using the truncated series to approximate π using the series from parts (a) and (b). 3. Suppose we want to approximate the function f (x) = ex on the interval [0, 1] using a second degree polynomial. (a) Let q2 denote the second degree Taylor polynomial of f about x = 0. Derive an upper bound for the magnitude of error in using q2 to approximate f on [0, 1], i.e. bound the maximum of |q2 (x) − ex |. 1 (b) Find the second degree polynomial, p2 , that interpolates f at the points x = 0, x = 1/2, and x = 1. (c) Derive an upper bound for the magnitude of error in using p2 to approximate f on [0, 1]. (d) Plot f , q2 , and p2 for x ∈ [0, 1] on the same figure. (e) Plot |q2 (x) − ex | and |p2 (x) − ex | on the same figure using a log scale for error (in MATLAB use command semilogy). Verify by inspection that the error bounds you derived hold, and comment on the quality of the two different approximations over [0, 1]. 4. The Taylor series for the function f (x) = ex converges for all x. This idea can be used to approximate ex using only addition, multiplication, and division. Below is an example of such a code. % myexp.m -- function for computing y=exp(x) using a Taylor series % function [y,Nterms]=myexp(x); oldsum = 0; newsum = 1; term = 1; n = 0; while newsum~=oldsum n = n+1; term = term*x/n; oldsum = newsum; newsum = newsum + term; end Nterms = n + 1; y = newsum; (a) Assess the accuracy of the algorithm by using it to approximate y = ex on the interval x ∈ [−20, 20] by comparing with the built-in library function for the exponential. Compute the absolute and relative errors as a function of x and plot the results (use log scale for the error; i.e. in MATLAB use command semilogy for plotting). (b) For what values of x do you see poor performance from the algorithm? Explain the reason for the poor performance. (c) Based on your answer from the previous part, modify the algorithm to eliminate the poor performance. Discuss the changes and demonstrate the performance of the modified code by plotting the errors as a function of x. 5. Given a set of distinct points xk for k = 0 . . . n, the j th Lagrange interpolating polynomial is the unique degree n polynomial which satisfies ( 1 if i = j, Lj (xi ) = 0 otherwise. Write a program to evaluate Lj . 2 (a) Let xk = −1 + 2k/n for some integer n for k = 0 . . . n; these are n + 1 equally spaced points on [−1, 1]. For n = 5 plot all six Lagrange interpolating polynomials on the same figure. Repeat for n = 10 and n = 15. (b) Repeat the previous part for the Chebyshev points:   2k + 1 xk = cos π , k = 0 . . . n. 2(n + 1) (c) Discuss the difference in the plots from part (a) and part (b). In particular, note that high degree polynomial interpolants are known to exhibit large oscillations even for non oscillatory data unless one is careful about points are used for interpolation. Do your plots give some insight into this phenomenon? Which set of point locations is more likely to result in oscillatory interpolants? 3
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Hey there 😀 , the answers are in the attachments. doc ad pdf files are the written answers and the matlab files are in zip file.Don't forget that the function files (tanTaylor.m, myexo.m, myexp2.m, and lagrangePoly.m) need to be in a folder defined in Home -> Set Path for the other files to work.Let me know if you have problems opening any of the files.

1.
a)
For this case, we have an indeterminate form of the type 0/0, so we can use L’Hospital’s
rule to find the limit:
(1 − cos 𝑥)′
1 − cos 𝑥
sin 𝑥
=
lim
= lim
2
2
𝑥→0
𝑥→0
𝑥→0 2𝑥
𝑥
(𝑥 )′
lim

Which is another indeterminate form of the 0/0 type, so we can apply L’Hospital’s rule
again:
lim

𝑥→0

sin 𝑥
(sin 𝑥)′
cos 𝑥 1
= lim
= lim
=
𝑥→0
𝑥→0
2𝑥
(2𝑥)′
2
2
lim

𝑥→0

1 − cos 𝑥 1
=
𝑥2
2

b)
For a sequence converging to L,
|𝑥𝑘+1 − 𝐿|
=𝜇
𝑘→∞ |𝑥𝑘 − 𝐿|
lim

If 0 < 𝜇 < 1, the sequence converges linearly.
We can verify that for a sequence of 𝑥𝑘 = 10−𝑘 with = 1,2, … :
|𝑓(𝑥𝑘+1 ) − 𝐿|
1
=
𝑘→∞ |𝑓(𝑥𝑘 ) − 𝐿|
100
lim

1

Since 0 < 𝜇 < 1, 𝑓(𝑥𝑘 ) converges to 𝐿 = 2 linearly.

c)
The following table displays the value of 𝑓(𝑥) for the given values of x, calculated with
MATLAB:
𝒙
𝟏𝟎−𝟏
𝟏𝟎−𝟐
𝟏𝟎−𝟑
𝟏𝟎−𝟒
𝟏𝟎−𝟓
𝟏𝟎−𝟔
𝟏𝟎−𝟕
𝟏𝟎−𝟖
𝟏𝟎−𝟗
𝟏𝟎−𝟏𝟎

𝒇(𝒙)
0.499583472197429
0.499995833347366
0.499999958325503
0.499999996961265
0.500000041370186
0.500044450291171
0.499600361081321
0
0
0

We can see that the result gets increasingly close to 0.5 until 𝑥 = 10−5, from then, it
diverges until at 𝑥 = 10−8 the calculation returns zero.

d)
From item c, around 𝑟 = 10−8 relative errors close to 100% are experienced calculating
𝑓(𝑥) when |𝑥| < 𝑟.

e)
Multiplying both the numerator and denominator by (1 + cos 𝑥):
(1 − cos 𝑥) (1 + cos 𝑥)
1 − cos 2 𝑥
sin2 𝑥
=
=
𝑥2
(1 + cos 𝑥) 𝑥 2 (1 + cos 𝑥) 𝑥 2 (1 + cos 𝑥)
sin 𝑥 2
( 𝑥 )
𝑓(𝑥) =
(1 + cos 𝑥)
Evaluating this function for 𝑥𝑘 = 10−𝑘 with 𝑘 = 1,2, … in MATLAB:
𝒙
𝟏𝟎−𝟏
𝟏𝟎−𝟐
𝟏𝟎−𝟑
𝟏𝟎−𝟒
𝟏𝟎−𝟓
𝟏𝟎−𝟔
𝟏𝟎−𝟕
𝟏𝟎−𝟖
𝟏𝟎−𝟗
𝟏𝟎−𝟏𝟎

𝒇(𝒙)
0.499583472197423
0.499995833347222
0.499999958333335
0.499999999583333
0.499999999995833
0.499999999999958
0.500000000000000
0.500000000000000
0.500000000000000
0.500000000000000

We can see that this rearrangement solved the problem, making the value converge to the
limit and therefore we should not expect accuracy problems with smaller values of x.

2...


Anonymous
Really helped me to better understand my coursework. Super recommended.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Related Tags