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

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. Lambda expressions So far in this course we have mostly defined functions using det statements. These take the general form: def function_namelparans): #Sone calculation return some_value_we_computed Python provides an alternative way to define simple functions that directly return a value easily computed from their parameters: lambda expressions. A lambda expression and don't be put off by the unfortunate name, which is of historical significance only) is an expression that evaluates to yield a function. A lambda expression takes the form Lambda parans: return_value_expression where parans is a comma separated list of parameters and return_value_expression is an expression that computes the return value from the parameters The following table should make this clearer. The left hand column shows a standard de statement to define a function. The right hand column shows how to achieve the same etfect using a lambda expression; the expression on the right-hand-side of the assignment statement yields a function and that function is assigned to a variable, thereby giving it a name. Using a dof statement Using a lambda expression det square square Labda xl xx return def plusia, b) returna. plus anda bi del quada, , , return a DXC dlanoda, b, c, x2 + + As we will see shortly, lambda expressions can be convenient as a way to pass very simple functions as parameters to functions like nesto root, oder to avoid the overhead of multiline det statements. Please see the lecture notes for an example using lambda expressions as the key argument when sorting lists Assuming the existence of a function nevtor_root_finder if, t_prite, xo, tolerance), fill in the two missing arguments to the function so that the code prints the square root of 2. Answer: (penalty regime: 0, 10, 20, ... %) 1 Use the (htdden) newton_root_finder function to 2 compute and print the square root of 2 3 root newton root finder 4 6 1.0, 1.8e-8) 7 Iprint(" [root :0.8f}") Precheck Check

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Solve 3x+6= 34. O-2 04 6

Answered: 1 week ago