воскресенье, 20 марта 2016 г.

Math 128A Programming Project 01


For the following two problems, write and debug MATLAB codes and make sure they run
with the test autograder from the course web page. Test them thoroughly on test cases
of your own design including simple roots, multiple roots with sign change, and closely
separated roots. When you are convinced they work, submit your codes together with
• brief discussion of any design decisions
• brief comparison of test results with theory
Part 1 Implement a MATLAB function findbracket.m of the form
function [a, b] = findbracket(f, x0)
% f: function handle f(x) to find a zero for
% x0: starting point / center of interval containing a zero
to try to find an initial interval [a, b] containing the input x0 and bracketing a zero of f (x),
i.e. with sgn f (a) = sgn f (b).
Your function should begin with a = b = x0 and a step size δ = 2−k chosen so that
fl (x0 − δ) < fl x0 −

δ
2

= x0

(i.e. the unit of least precision for x0 ). While sgn f (a) = sgn f (b), decrease a by δ, increase
b by δ, evaluate f (a) and f (b). and double δ.
Part 2 Implement a MATLAB function schroderbisection.m of the form
function [r, h] = schroderbisection(a, b, f, fp, fpp, t)
% a: Beginning of interval [a, b]
% b: End of interval [a, b]
% f: function handle f(x) to find a zero for
% fp: function handle f’(x)
% fpp: function handle f’’(x)
% t: User-provided tolerance for interval width
which combines the fast convergence of the Schr¨der iteration for multiple roots
o
g(x) = x −

1
f (x)
f (x)f
f (x) 1 −

(x)
f (x)2

=x−

f (x)f (x)
f (x)2 − f (x)f (x)

with the bracketing guarantee of bisection. At each step j = 1 to n, carefully choose p as in
geometric mean bisection (watch out for zeroes!). Define
= min(|f (b) − f (a)|/8, |f (p)||b − a|2 )
Apply the Schr¨der iteration function g(x) to two equations f± (x) = f (x) ± = 0, yielding
o
two candidates x = q± = g± (p). Replace [a, b] by the smallest interval with endpoints
1

Math 128A, Spring 2016

Programming Project 01

chosen from a, p, q+ , q− and b which keeps the root bracketed. Repeat until a f value exactly
vanishes, b − a ≤ t, or b and a are adjacent floating point numbers, whichever comes first.
Return the final approximation to the root r = (a + b)/2 and a 6 × n history matrix
h[1:6,1:n] with column h[1:6,j] = (a, p, q− , q+ , b, f (p)) recorded at step j.

Code Submission: Upload the MATLAB files findbracket.m and schroderbisection.m
and any supporting files to bCourses for your GSI to grade.

Комментариев нет:

Отправить комментарий