Question: It's MATLAB Part 2: bisection method create a function with the headerline root = findroots(x, y, tol) that will output all of the roots of

It's MATLAB

Part 2: bisection method

create a function with the headerline root = findroots(x, y, tol) that will output all of the roots of a function (along the interval of x) using the bisection method.

This function uses the inputs

x which is a vector that has the starting and ending point over which you are looking for roots (x = starting:interval:ending)

y which is an inline function (see examples below)

tol which is the tolerance used to find the roots (see examples below)

Note: y is a function NOT an array

Output the roots in the array root.

Rules: you cannot use the functions roots, fzero or feval

Test your function

>> y = inline('cos(x)-x', 'x');

>> R = findroots(0:0.1:2, y, 0.0001)

R =

0.7391

>> y = inline('cos(x)', 'x');

>> R = findroots(0:0.1:10, y, 0.0001)

R =

1.5707 4.7123 7.8539

>> y = inline('sin(x)', 'x');

>> R = findroots(0:0.1:20, y, 0.0001)

R =

3.1416 6.2832 9.4248 12.5664 15.7080 18.8496

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!