Question: THIS PROGRAM MUST BE WRITTEN IN THE C LANGUAGE AND USE THAT EXACT PROTOTYPE You'll write your own square-root function that corresponds to the following

THIS PROGRAM MUST BE WRITTEN IN THE C LANGUAGE AND USE THAT EXACT PROTOTYPE

THIS PROGRAM MUST BE WRITTEN IN THE C LANGUAGE AND USE THAT

You'll write your own square-root function that corresponds to the following prototype: double mySqrt (double x); (for x greaterthanorequalto 0) Now, computers can only perform: +, -, *, /, and do some comparisons. So for any mathematical function (e.g. tan, sin, square-root, log, .....) to be programable on a computer, you need to find a way to calculate the answer that only uses: +, -, *, /, and some comparisons. For a square-root function you can use the Newton-Raphsonmethod. The Newton-Raphson method is a general method that will find the value of xthat makes a function f(x) = 0. (under the constraint that the function f(x) isdifferentiable). In our case, we are trying to determine x for the equation: x = squareroot a Which can be rearranged to: x^2 = a and finally in standard polynomial form: x^2 - a = 0 So our function f(x) = 0, can be written as: f(x) = x^2 - a = 0 The Newton-Raphson equation for iteratively solving an equation f(x) = 0 is: x_k + 1 = x_k - f(x_k)/f'(x_k) Where for our case: f(x_k) = x_k^2 - a f'(x_k) = 2 middot x_k (i.e. the derivative of f(x)) After substituting f(x) and f'(x) into the Newton-Raphson equation and simplifying, we have: x_k + 1 = 0.5.(x_k + a/x_k) So to use the above equation to find the squareroot a you must pick an initial value for x_k at k = 0 (i.e. the beginning of the first iteration) A reasonable initial guess for the square-root of "a" is always: a/2 So let x_0 = a/2 So plug the initial value.x_0 into the equation above and find x_1, then plug x_1 into the equation and find x_2. Continue to iterate the equation until x_k and x_k + 1 are nearlythe same (i.e. the iteration has converged to an answer). So what does x_kand x_k + 1 are nearly the same mean ? It means you must iterate the equation until thedifference between them is less than some relative error. So let the relative error be: |x_k + 1 - x_k/x_k + 1|

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!