CSC336F-无代写-Assignment 1
时间:2023-10-02
CSC336F Assignment 1 Due Wednesday, October 4, 2023, 6PM
Please write your family and given names and underline your family name on the front page of your paper.
Answers should be highly preferably typed (and preferably in latex), and compiled to a single pdf. If an assignment is very
cleanly handwritten and scanned on a proper scanner as a single pdf file, and not photographed, then it is also acceptable.
Code and output should be embedded in latex/pdf. Use fixed width fonts (e.g. Courier) for code and output. Never use dark
background, for anything, not even part of submission. Use font size 12 or larger.
Submit the single pdf file 00A1.pdf (with embedded code, output and plots), as well as your code. Thus, the code will be
available within latex/pdf, as well as separately. Do not submit zip and similar files. Only pdf and code (.m, etc) are accept-
ed.
See course website for example of latex, embedding plots, code, using fixed width fonts, etc. See also how to present tables,
plots, etc.
Some points will be given for the quality of presentation.
1.
(a) [10 points] Find the condition number of f (x) = 1 − cos(x)
x
, and study for what values (approximate ranges) of x the
function f (x) is ill-conditioned.
(b) [10 points] Consider the (numerical) stability of the computation of the expression 1 − cos(x)
x
(as it is given) for some
x close to 0. Explain what problems the computation of the expression
1 − cos(x)
x
may give rise to. Propose a mathe-
matically equivalent expression that is likely to be more stable for x close to 0, and explain.
(c) [5 points] Is the expression you proposed in (b) stable for some x close to pi ? Explain. If not, propose yet another
mathematically equivalent expression that is likely to be more stable for x close to pi (as well as for x close to 0), and
explain.
(d) [5 points] Write a matlab script that, for i = −5, −6, . . . , −12, δ = 10i and x = δ , computes f (x) of (a) as you proposed
in (b). Comment on the results.
The script should look like the following:
fprintf(’ x (1-cos(x))/x alt 2\n’);
for i = -5:-1:-12
d = 10ˆi; x = d;
fprintf(’%12.4e %12.4e %12.4e\n’, x, (1-cos(x))/x, ... );
end
Do not alter the output format. Always include a brief header.
(e) [5 points] Write a matlab script that, for i = −5, −6, . . . , −12, δ = 10i and x = pi + δ , computes f (x) of (a) as you pro-
posed in (c). Comment on the results.
The script should look like the following:
fprintf(’ x (1-cos(x))/x alt 3\n’);
for i = -5:-1:-12
d = 10ˆi; x = pi+d;
fprintf(’%12.10f %12.10f %12.10f\n’, x, (1-cos(x))/x, ... );
end
Do not alter the output format. Always include a brief header.
Note:
In (b) and (c), we are interested in the stability of an expression that computes f (x) and not in the conditioning of f (x).
2. [15 points] Consider the expression 1 − √ 1 − x2, for some non-zero x with |x| small (close to 0), and a computer system
with four-decimal-digits precision floating-point arithmetic. What sign should the value of the expression have?
In the above computer system, what is the value of the expression for x = 10−2 and what for x = 10−3?
If any of the two values computed seems clearly wrong, propose an alternative (but mathematically equivalent) expres-
sion that would give more accurate value.
Note: The values do not need to be exact, but reasonably accurate within the limitations of the computer system.
CSC336 Assignment 1 C. Christara
- 2 -
3. Some history background: In about 250 BC, the Greek mathematician Archimedes gav e an estimate of the number pi,
by bounding the circumference of a circle of diameter 1 (hence circumference pi) below and above by the perimeters of
appropriate inscribed and circumscribed polygons, respectively. For example, an inscribed square has perimeter 2√2,
and thus 2√2 < pi . Using a 96-sided inscribed and circumscribed polygon, he was able to show 223 / 71 < pi < 22/7.
Today we know that, if pn is the perimeter of an inscribed polygon with 2n sides, starting with p2 = 2√2, and proceed-
ing with
pn+1 = 2n√ 2(1 − √ 1 − ( pn /2n)2), n ≥ 2 (1)
we have pn → pi , as n → ∞. You do not need to prove this. You take is as granted.
Your work is to investigate how well or badly this formula converges to pi computationally, and, if it does not converge
satisfactorily, propose an alternative formula that converges to pi satisfactorily. More specifically,
(a) [10 points] Assuming that pn of (1) converges to pi mathematically, explain what numerical stability problems may
arise in (1) that would eventually make pn a poor approximation to pi.
(b) [10 points] Propose an alternative formula that converges to pi satisfactorily within the limitations of our computer sys-
tem (assuming the system uses double-precision IEEE floating-point arithmetic).
Hint: Consider the expression 1 − √ 1 − x2, for some small non-zero |x|.
(c) [20 points] Write a matlab script that, for n = 2, 3, . . . , 31, computes both approximations to pi and the respective errors
(taking as "exact" the predefined value of pi in matlab) and outputs the results in the form of a table. Comment on the
results, especially on how they evolve with n, and how the two formulae compare. You can add any other interesting
comment relating concepts of the course with the results.
Your script should look like the following:
n = 31;
fprintf(’i+1 p(i+1) error q(i+1) error\n’);
i = 1; p(i+1) = 2*sqrt(2); q(i+1) = 2*sqrt(2);
fprintf(’%3d %20.16f %12.4e %20.16f %12.4e\n’, i+1, p(i+1), pi-p(i+1), ...
q(i+1), pi-q(i+1));
for i = 2:n
p(i+1) = 2ˆi * sqrt(2*(1-sqrt(1-(p(i)/2ˆi)ˆ2)));
q(i+1) = % fill-in the alternative expression
fprintf(’%3d %20.16f %12.4e %20.16f %12.4e\n’, i+1, p(i+1), pi-p(i+1), ...
q(i+1), pi-q(i+1));
end
Do not alter the output format. Include header.
4. [10 points] Prove or disprove the statement: The product of strictly (row) diagonally dominant matrices is a strictly
(row) diagonally dominant matrix.
If you prove it, your proof must be general for any pair of strictly diagonally dominant matrices of general n × n size.
If you disprove it, then use an example, which involves matrices of at least 4 × 4 size.
CSC336 Assignment 1 C. Christara


essay、essay代写