Question: 1 : Modify the MATLAB code for the bisection method as shown in Figure 12 to implement the false position method (call the function false_pos.m

 1:Modify the MATLAB code for the bisection method as shown in

1:Modify the MATLAB code for the bisection method as shown in Figure 12 to implement the false position method (call the function false_pos.m ) for finding roots.

Calculate the root of the equation shown below using both bisection and false position methods. Use a stopping criterion of 0.5%.

1 4e(-0.5x)= 0

(Note: There is only one root for this equation)

How many iterations are required to calculate the root for each method? Explain this discrepancy.

Compare the root obtained from both methods and compute their percentage relative error using the formula below.

a= Rootbisection Rootfalse positionRootbisection100%

function [root,fx,ea,iter]-bisect(funcxl,xu,es,maxit,yarargin) % bisect: root location zeroes % [root.fx,ea ,iter-bisect(fungxi,xu , es , maxit,p1,p2,. .. ): % uses bisection method to find the root of func % input: % func = name of function % xi, xu = lower and upper guesses %es-desired relative error (default-0.0001%) % maxit-maximum allowable iterations (default-50) p1,p2. -additional parameters used by func % output: % root-real root %tx-function value at root % ea-approximate relative error (%) % iter-number of iterations if nargin 3,error(at least 3 input arguments required'),end test - func(xl,yarargin3)func(xu, yarargins:]); if test 0,error(no sign change'),end if narginc4lisempty(es), es-0.0001;end if nargin 5 l isempty(maxit), maxit-50;end iter 0; xr-xl; ea- 100; while (1) xrold-xr ..r_ (x1 + xu)/2; iter iter1; if xr 0,aabs((xr - xrold)/xp) * 100;end test func(xl,yarargin:3func(xryarargin:) if test = maxit, break,end end root -xr; fx- func(xr, yarargins:3); Figure 12.An M-file to Implement the Bisection Method

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!