Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given this code, I want you guys to create a flowchart by hand, show the correct if and for loops. draw lines where it the

Given this code, I want you guys to create a flowchart by hand, show the correct if and for loops. draw lines where it the loops should repeat etc...

a = -5; b = 0.5; tolerance = 1E-07; f = @(x) 3*x + sin(x) - exp(x); Xs = BrentMethod(f,a,b); function b = BrentMethod(fun,xl,xr) % a = start of the bracket , % b = end of the bracket %fun = input function in the format @(x) (equation) % tolerance = global tolerance to stop iterations a = xl; b = xr; f = fun; Fa = f(a); Fb = f(b); c = a; Fc = f(c); d = b - a; e = d; while(1) if Fb ==0 break end if sign(Fa) == sign(Fb) % if needed , rearrage points a = c; Fa = Fc; d = b - c; e = d; end if abs(Fa) < abs(Fb) c = b; b = a; a = c; Fc = Fb; Fb = Fa; Fa = Fc; end m = (a-b)/2; % tolerance in each domain for bisection %if nargin < 3 tolerance = 2 * eps * max(abs(b), 1); % if tolerance is not provided by user % use this values as a tolerance, esp = lowers number MATLAB can % compute %end if abs(m) <= tolerance | Fb == 0 break % stop iteration when tolerance is reached end % choose open methods or bisection if abs(e) >= tolerance & abs(Fc) > abs(Fb) s = Fb/Fc; if a ==c % Secant Method p = 2*m*s; q = 1-s; else % inverse quadratic interpolation q = Fc/Fa; r = Fb/Fa; p = s*(2*m*q*(q-r)-(b-c)*(r-1)); q = (q -1)*(r-1)*(s-1); end if p > 0 q = -q; else p = -p; end if 2*p < 3*m*q - abs(tolerance*q) & p < abs(0.5*e*q) e = d; d = p/q; else d = m; e = m; end else % Bisection Method d = m; e = m; end

c = b ; Fc = Fb; if abs(d) > tolerance b = b + d; else b = b - sign (b-a) * tolerance ; fprintf('Solution is Xs = %f ' , b ) end Fb = f(b); end end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions