Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The \"root\" of an equation, y = f(x), is a value of x for which y has a value o

ID: 3815294 • Letter: T

Question

The "root" of an equation, y = f(x), is a value of x for which y has a value of zero and it is often "the answer" for a practical engineering problem. The Bisection method is one of the simplest and most robust numerical methods for computing an approximate value for a root of a function. An explanation of the Bisection method is presented on the following page. Craft a UDF that performs the following tasks. 1. Accepts as an input argument a 4-element vector containing: the lower bound for the search interval the upper bound for the search interval a value of f(x) close enough to zero to accept x as an approximate value for a root the maximum number of iterations before termination of execution. 2. Calls another UDF, myFunction, saved in a different m-file, to compute values of the independent variable from values of the dependent variable. No credit will be earned for this assignment if you do not use the specified function name. 3. Reports to the CW one of the two possible outcomes. a) If a root is found, the approximate value of the root and the corresponding value of the function, b) That an approximate value for a root has not been found after iterations where the hyphens are the number of iterations conducted. The file you submit to the dropbox should have only the UDF that performs the bisection.

Explanation / Answer

findroot.m

function root = findroot(v)
a = v(1);
b = v(2);
c = a;
EPSILON = v(3);
iter = 1;
while ((b-a) >= EPSILON)
if(iter > v(4))
fprintf('can not find root in %d iterations ',v(4));
break ;
end
c = (a+b)/2;
if ((myfunction(c)) == 0.0)
break;
elseif ((myfunction(c))*(myfunction(a)) < 0)
b = (a+b)/2;
else
a = (a+b)/2;
end
iter = iter + 1;
end
root=c;
end

myfunction.m

function val = myfunction(x)
val = x^2 - 4;
end

Sample run:

root = findroot([1,8,0.001,20])

>>root = 2.00061035156250

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote