Answered step by step
Verified Expert Solution
Link Copied!

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
image text in transcribed
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

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

Recommended Textbook for

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago