The \"root\" of an equation, y-f(x), is a value of x for which y has a value of
ID: 3705697 • 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 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 .Calls another UDF, myFunction, saved in a different m-file, to compute a value of the dependent variable from a value of the independent variable. For example, myFunction accepts a value forx, computes a value of y from yex2, and returns the value of y. No credit will be earned for this assignment if you do not use the specified function name .Generates a plot of the function over the specified range of values to provide an idea of how many roots exist on that interval Executes the bisection algorithm to search for a root of the function on the specified interval and 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, That an approximate value for a root has not been found after-iterations where the hyphens are the number of iterations conducted b)Explanation / Answer
As per the equation :
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
function val = myfunction(x)
val = x^2 - 4;
end
For example :
root = findroot([1,8,0.001,20])
>>root = 2.00061035156250
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.