{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

bisect - i if display fprintf step xl xh xr yr Emax n end e...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [xr] = bisect (f, xl, xh, Edes, display) % BISECT Finds a root by performing a bisection search. % Inputs: f = a function of one variable % xl = lower bound of range to be searched % xh = upper bound of range to be searched % **** f(a) and f(b) must have different signs **** % Edes = tolerance in x (function stops when xr is guaranteed to % be within Edes of a root) % display = display option (0 = no output, 1 = output, defaults to 0) % Outputs: xr = estimate of root % if nargin < 5; display = 0; end i yl = f(xl); yh = f(xh); if sign(yl) == sign(yh), error ('no sign change'), end
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i if display fprintf (' step xl xh xr yr Emax\ n'); end e signOfYl = sign(yl); % keep track of sign of function at xl s for k = 1:1000 % 1000 max iterations xr = (xl + xh) /2; yr = f(xr); Emax = (xh - xl) / 2; if display fprintf ('%5d %12.6f %12.6f %12.6f %12.6f %12.6f\n', k, xl, xh, xr, yr, Emax); end if Emax &amp;lt;= Edes || yr == 0 % error acceptably small or direct hit return; end if sign(yr) == signOfYl xl = xr; else xh = xr; end end e error ('Bisection search has not converged'); % essentially impossible e end...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern