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 of

ID: 3704789 • 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 for x, 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, 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. NOTE: Although this method is considered slow compared to other numerical methods for finding the root of a function, after only 20 iterations the length of the search interval will be less than 1 millionth of its starting length!

Explanation / Answer

%% calling code;

============

clc;

close all;

clear all;

tol=1.0e-5;

x=[ -1 3]

root=myfun(x,tol)

%% my fun.m

function fn: my fun(x,tol)

fun=@(x)x,*3-2*x-10

fn=mybisect(fun,x,2,tol);

return;

end

%%mybisect .m

function r=mybisect(fun,xb,xtol,ftol)

a=xb(1):

b=xb(2);

fa=feval(fun,a);fb=feval(fun,b);

error(sprintf(roots are not breaked for[(%f,%f)a,b)];

end

k=0:max it=100;

while k<maxit

k=k+1;

dx=b-a;

xm=a+0.5*dx;

fm=feval(fun,xm);

if(abs(fm)<(ftol)/((abs(dx))<xtol)

r=xm;

return

end

if sign(fm)==sign(fa)

a=xm;

fa=fm;

end

if k<3

sprintf(%d%2.2f %2.2f52.2f%2.2f%2.2f%2.2f%;k,xm,fm,a,fa,b,fb)

end

end

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