Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Math 128A, Spring 2016 Programming Project 01 For the following two problems, write and debug MATLAB codes and make sure they run with the test

Math 128A, Spring 2016 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 nd 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 = 2k chosen so that (x0 ) < 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 Schrder 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!). Dene = min(|f (b) f (a)|/8, |f (p)||b a|2 ) Apply the Schrder 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 oating point numbers, whichever comes rst. Return the nal 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 les findbracket.m and schroderbisection.m and any supporting les to bCourses for your GSI to grade. 2 Math 128A, Spring 2016 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 nd 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 = 2k chosen so that (x0 ) < 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 Schrder 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!). Dene = min(|f (b) f (a)|/8, |f (p)||b a|2 ) Apply the Schrder 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 oating point numbers, whichever comes rst. Return the nal 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 les findbracket.m and schroderbisection.m and any supporting les to bCourses for your GSI to grade. 2 % Case 1. a = 1 b = 5 f1 = @(x) (x - 3.14).^3; f1p = @(x) 3* ( x - 3.14 ).^2 ; f1pp = @(x) 6 * ( x - 3.14 ) ; tol = 1.0e-3 [r, h] = schroderbisection3(a, b, f1, f1p, f1pp, tol ); r h assert( abs( r - 3.14 ) < tol )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Algebra Math 1st Grade Workbook

Authors: Jerome Heuze

1st Edition

979-8534507850

More Books

Students also viewed these Mathematics questions