Write a MATLAB userdefined function that solves tor a root o

Write a MATLAB user-defined function that solves tor a root of an equation f(x) = 0 using the bisection method. Name the function function [x] = bisection(fun, a, b, maxtol, maxitr) The input argument fun is a name for the function that calculates f (x) for a given x (it is a dummy name for the function that is imported into bisection, a and b are two points that bracket the root, maxtol is the maximum tolerance and maxitr is the maximum number of iterations. The program will stop if either of the following conditions is met: The approximate error (abs (fun (x)) is less than the maximum tolerance (maxtol). The number of iterations exceeds the maximum number of iterations (maxitr) Output the following values at each iteration (k) using fprintf k, a, f (a), b, f (b), x Test your code using the values of maxto 1=0.01 and maxitr=20 to find the second to fifth normalized natural frequencies of the cantilever beam. Test your code to find all the roots of the following polynomial and compare your results to those obtained using roots. f(x) = x^3 - 8x^2 + 16

Solution

Following are the steps to find the approximate solution of given equation using Bisection method:

Let us assume that we have to find out the roots of f(x), whose solution is lies in the range (a,b), which we have to determine. The only condition for bisection method is that f(a) and f(b) should have opposite signs (f(a) negative and f(b) positive). When f(a) and f(b) are of opposite signs at least one real root between ‘a’ and ‘b’ should exist.

For the first approximation we assume that root to be,

x=(a+b)/2

Then we have to find sign of f(x).

If f(x) is negative the root lies between a and x. If f(x) is positive the root lies between x and b.

Now we have new minimized range, in which our root lies.

The next approximation is given by,

x1 = (a+x)/2………….if f(x) is negative.

x1 = (x+b)/2………….if f(x) is positive.

In this taking midpoint of range of approximate roots, finally both values of range converges to a single value, which we can take as a approximate root.

MATLAB Program For Bisection Method:

Ans (c)

// PLEASE ATTACH THE SIGN OF \'AT THE RATE\' AFTER THE EQUAL TO SIGN AFTER f , as while uploading the answer it was showing to close this character , kindly use it for correct output

 Write a MATLAB user-defined function that solves tor a root of an equation f(x) = 0 using the bisection method. Name the function function [x] = bisection(fun,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site