Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In MATLAB please 3 Another Experiment With Function Handles Write a function xbwbisection (f, a, b, tol) and a function xn=newton (f,x0,tol) which both find
In MATLAB please
3 Another Experiment With Function Handles Write a function xbwbisection (f, a, b, tol) and a function xn=newton (f,x0,tol) which both find a zero of f(x) in the interval [a, b], using the bisection and newton algo rithms, respectively, discussed in class. For the newton function, use the function deriv from problem (2) of this assignment to compute the derivative of the function at each iteration You can find the pseudo-code for both methods below. Then, find the zero of the following functions near the given points: f(x) = cos() + sin(2x) near 1 = 2 g(x) = 1 - 5 In(x) near r=1 Also, display the number of iterations each method takes to find the zero. In writing the driver routine that calls bisection and neuton, you are free to define the functions f(a) and g(a) as anonymous functions or subfunctions (in which case the driver routine will itself be a function). Pseudo-code for bisection method: a = left end point b = right end point N1 # Stop only when max iteration is reached or solution is found c = (a + b)/2 # new midpoint While N TOL N = N + 1 # increment step counter c = (a + b)/2 # new midpoint # Determine new interval If sign (f(c)) == sign (f (a)) then a = c else b = c End If Endwhile Pseudo-code for Newton's method: abs(f(x)) X = some guess N = 0 While I TOL N = N + 1 # Do the Newton iteration x = x - f(x) / f'(x) EndWhile 3 Another Experiment With Function Handles Write a function xbwbisection (f, a, b, tol) and a function xn=newton (f,x0,tol) which both find a zero of f(x) in the interval [a, b], using the bisection and newton algo rithms, respectively, discussed in class. For the newton function, use the function deriv from problem (2) of this assignment to compute the derivative of the function at each iteration You can find the pseudo-code for both methods below. Then, find the zero of the following functions near the given points: f(x) = cos() + sin(2x) near 1 = 2 g(x) = 1 - 5 In(x) near r=1 Also, display the number of iterations each method takes to find the zero. In writing the driver routine that calls bisection and neuton, you are free to define the functions f(a) and g(a) as anonymous functions or subfunctions (in which case the driver routine will itself be a function). Pseudo-code for bisection method: a = left end point b = right end point N1 # Stop only when max iteration is reached or solution is found c = (a + b)/2 # new midpoint While N TOL N = N + 1 # increment step counter c = (a + b)/2 # new midpoint # Determine new interval If sign (f(c)) == sign (f (a)) then a = c else b = c End If Endwhile Pseudo-code for Newton's method: abs(f(x)) X = some guess N = 0 While I TOL N = N + 1 # Do the Newton iteration x = x - f(x) / f'(x) EndWhile Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started