Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python coding question a The Newton-Raphson Method Be sure to watch the video introducing the Newton-Raphson method before proceeding We begin our exploration of numerical

Python coding question
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
a The Newton-Raphson Method Be sure to watch the video introducing the Newton-Raphson method before proceeding We begin our exploration of numerical methods with a cool algorithm for finding the roots (zeros) of a function: the Newton-Raphson method, sometimes simply called Newton's method. Between 1665 and 1666, Isaac Newton (1642 - 1727) spent his days under lockdown in his countryside home at Woolsthorpe, England while the Great Plague was ravaging London. During these so-called "plague years" Newton was free to think, observe, and create. His many discoveries from this productive period of his life include the development of calculus, the laws of classical mechanics, the theory of gravitation, and the workings of optics. Among these massive achievements was a little algorithmic gem that we will now discuss. The algorithm The algorithm in question - which later became known simply as "Newton's Method" or the "Newton-Raphson Method" after Joseph Raphson (c. 1648 - c. 1715) who elaborated on the algorithm - could be used to find the roots of an arbitrary function. Finding a root of a function f() just means finding a value of such that t) = 0. Newton's method involves computing a series of increasing accurate estimates of the root as follows: 1. Choose an initial value for the root, 7, and call it to 2. Compute an improved estimate x142 11 - where f[?[?][?](x) is the derivative of f(x). 3. Go back to step 2 The above generates an intinite sequence of t; In practice we stop as soon as we have a sufficiently good" estimate of the actual root, as will be explained in the information panels and questions that follow. Please watch the videos interlude on function objects and Newton-Raphson revisited before answering this question Write a function called newton_root_Finderit, fuprime, xo, tolerance that takes as parameters: A function 70x), the root of which is required. A function _prime(x), which is the derivative of f(x). An estimate xa of the value of the root. The maximum acceptable absolute value of f(x) for x to be considered a valid root. The function should apply the same algorithm as used for the square root exercises and return the first value in the sequence 1..... that satisties the required tolerance. For example: Test Result # This first test uses the general 1.2247452 # root finder to deternine the square # root of 1.5. This test is exactly # equivalent to one used in an earlier # question. def my_func(x): return xx-1.5 def derivative(x): return 2*X ans = newton_root_inder (ny_func, derivative, 10, 1.8e-06) print("{ans:0.71)") # A trivial solution of a straight line equation 10.eeeeeee def func(x): return X - 10 def deriv(x): return 1 ans - newton_root_finderi func, deriv, 10000, 0.01) print("ans:0.71") Answer: (penalty regime: 0, 10, 20, ... %) So far we have been using the Newton-Raphson equation solver just to find square roots by solving equations of the form f(*) - r- a = 0 However, as explained in the lecture notes and videos, this is just one very specific application of the Newton-Raphson algorithm. It can be used to find the roots of any function (r) provided we have an equation for the derivative f'(*) and have a reasonable estimate of the position of the root we're after. if you've read the lecture notes and watched the videos, the next question should involve only a relatively trivial change to your answer to the previous question Please watch the videos interlude on function objects and Newton-Raphson revisited before answering this question. Write a function called newton_root_finder(f, f_prime, xo, tolerance) that takes as parameters: A function f(x), the root of which is required. A function f_prime(x), which is the derivative of f(x). An estimate x of the value of the root. The maximum acceptable absolute value of f(x) for x to be considered a valid root. The function should apply the same algorithm as used for the square root exercises and return the first value in the sequence 10.-11.... that satisfies the required tolerance. For example: Test Result 1.2247452 # This first test uses the general # root finder to determine the square # root of 1.5. This test is exactly # equivalent to one used in an earlier # question. def my_func(x): return x * X - 1.5 def derivative(x): return 2 * x ans = newton_root_finder(my_func, derivative, 10, 1.02-06) print(f"{ans:0.7f}") 10.0000000 # A trivial solution of a straight line equation def func(x): return x - 10 def deriv(x): return 1 ans = newton_root_finder(func, deriv, 10000, 0.01) print("{ans:0.7f}") So far we have been using the Newton-Raphson equation solver just to find square roots by solving equations of the form f(1) = x2 - 0 = 0 However, as explained in the lecture notes and videos, this is just one very specific application of the Newton-Raphson algorithm. It can be used to find the roots of any function for provided we have an equation for the derivative f'(7) and have a reasonable estimate of the position of the root we're after. If you've read the lecture notes and watched the videos, the next question should involve only a relatively trivial change to your answer to the previous question. The Newton-Raphson Method Be sure to watch the video introducing the Newton-Raphson method before proceeding We begin our exploration of numerical methods with a cool algorithm for finding the roots (zeros) of a function: the Newton-Raphson method, sometimes simply called Newton's method. Between 1665 and 1666, Isaac Newton (1642 - 1727) spent his days under lockdown in his countryside home at Woolsthorpe, England while the Great Plague was ravaging London. During these so-called "plague years" Newton was free to think, observe, and create. His many discoveries from this productive period of his life include the development of calculus, the laws of classical mechanics, the theory of gravitation, and the workings of optics. Among these massive achievements was a little algorithmic gem that we will now discuss. The algorithm The algorithm in question - which later became known simply as "Newton's Method," or the "Newton-Raphson Method" after Joseph Raphson (c. 1648 - c. 1715) who elaborated on the algorithm - could be used to find the roots of an arbitrary function. Finding a root of a function f(7) just means finding a value of such that f(1) = 0. Newton's method involves computing a series of increasing accurate estimates of the root as follows: 1. Choose an initial value for the root, r, and call it Io. 2. Compute an improved estimate Ii+1 = 1; - where f[?][?][?](x ) is the derivative of f(x). 3. Go back to step 2. The above generates an infinite sequence of 1;; in practice we stop as soon as we have a "sufficiently good" estimate of the actual root, as will be explained in the information panels and questions that follow

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

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions

Question

2. Ask questions, listen rather than attempt to persuade.

Answered: 1 week ago