{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E7_Lab09_Solutions_Fall_2010

# E7_Lab09_Solutions_Fall_2010 - Contents problem problem...

This preview shows pages 1–3. Sign up to view the full content.

Contents problem 1 problem 2 problem 3 problem 4 problem 5 problem 6 problem 7 problem 1 type my_bisection.m fh1 = @ (x) x^2+4*x-4; [r,rh,iter,err]=my_bisection(fh1,0,3,1e-6,1000); r fh2 = @ (x) sin(x); [r,rh,iter,err]=my_bisection(fh2,-1,1,1e-6,1000); r fh3 = @ (x) log(x); [r,rh,iter,err]=my_bisection(fh3,-1,1,1e-6,1000); r function [root,root_history,iter,error_value]=my_bisection(. .. fh,lower,upper,tol,max_iter) root = []; root_history = []; iter = 0; error_value = Inf; if fh(lower)*fh(upper) > 0 error('f(lower) and f(upper) are of the same sign.'); elseif fh(lower)*fh(upper) == 0 if fh(lower) == 0 root_history = lower; error_value = []; else root_history = upper; error_value = [];

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
end else lower_new = lower; upper_new = upper; iter = iter +1; middle = (lower_new+upper_new)/2; root_history = [root_history middle]; if fh(lower_new)*fh(middle) > 0 lower_new = middle; elseif fh(lower_new)*fh(middle) < 0 upper_new = middle; end error_value = err_fcn(root_history,fh,lower);
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

E7_Lab09_Solutions_Fall_2010 - Contents problem problem...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online