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

Problem 1: (5 Points) Write a function with the header: function [xNew, count] m

ID: 2086298 • Letter: P

Question

Problem 1: (5 Points) Write a function with the header: function [xNew, count] myFalsePos (f, xLeft, xRight, tol) which takes as input f: a function handle xLeft: the initial left bracket around a root xRight: the initial right bracket around a root tol: a tolerance above which the algorithm will keep iterating And uses the False Position method to return the root (xNew). Tips: * Be sure to include an iteration counter which will stop the while-loop if the number of iterations get greater than 1000. . It is not necessary to print out a convergence table within the while loop. (l.e., there should be no fprintf statements in your code) Test Case >> format longg >>f-C (x) 2 (1-cos (x)) +4 (1-sqrt (1- (0.5*sin (x)) .*2)) - 1.2; >> [S, count] -myFalsePos (f, 0, 2, .00000000001) 0.958192178746198 count - >> [S, count] - myFalsePos(f, -.2, 3, .00000000001) 0.958192178746191 count -

Explanation / Answer

function [xNew,i]=myFalsePos(f,xLeft,xRight,tol)

%f is the function whose root is to be found

%xLeft is the lower limit of range of solution and xRight is upper limit

xNew=100;

i=0;

while(abs(f(xNew))>=tol)&&i<1000

xNew=(xLeft*f(xRight)-xRight*f(xLeft))/(f(xRight)-f(xLeft));%new solution calculated by false position formula

if f(xLeft)*f(xNew)<0

xRight=xNew;

else

xLeft=xNew;

end

i=i+1;

end

>> f=@(x)2*(1-cos (x) +4*(1-sqrt (1- (.5*sin(X) ) . *2) ) -1.2;

>> [s, count]= myFalsepos (f,0,2, .00000000001)

s =

0.958192178746198

count =

6

>> [s, count]= myFalsePos(f,-.2,3, .00000000001)

s =

0.958192178746191

count =

9