Lab9 - Engineering 7: Introduction to Programming for...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Engineering 7: Prof. Alexandre Bayen Introduction to Programming for Engineers Spring 2011 Lab 9: Root Finding Date Assigned: 5:00pm, Friday – April 8 Date Due: 5:00pm, Friday – April 15. Problem 1: Write a function with header [R, E] = myBisection(f, a, b, tol) where f is a function handle, a and b are scalars such that a < b , and tol is a strictly positive scalar value. The function should return an array, R , where R(i) is the estimation of the root of f defined by (a + b)/2 for the i th iteration of the bisection method. Remember to include the initial estimate. The function should also return an array, E , where E(i) is the value of |f(R(i))| for the ith iteration of the bisection method. The function should terminate when E(i) < tol . You may assume that sign(f(a)) ~= sign(f(b)) . Clarification : The input a and b constitute the first iteration of bisection, and therefore, R and E should never be empty. Test Cases: >> f = @(x) x.^2 - 2; >> [R, E] = myBisection(f, 0, 2, 1e-1) R = 1.0000 1.5000 1.2500 1.3750 1.4375 E = 1.0000 0.2500 0.4375 0.1094 0.0664 >> f = @(x) sin(x) - cos(x); >> [R, E] = myBisection(f, 0, 2, 1e-2) R = 1.0000 0.5000 0.7500 0.8750 0.8125 0.7813 E = 0.3012 0.3982 0.0501 0.1265 0.0383 0.0059
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/07/2011 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at University of California, Berkeley.

Page1 / 5

Lab9 - Engineering 7: Introduction to Programming for...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online