Question: Matlab. (Newtons method) The almost universally used algorithm to compute a, where a... The almost universally used algorithm to compute squareroot a, where a >
Matlab. (Newtons method) The almost universally used algorithm to compute a, where a...

The almost universally used algorithm to compute squareroot a, where a > 0, is the recursion x_n+1 = 1/2(x_n + a/x_n), (2) easily obtained by means of Newton's method for the function f(x) = x^2 - a. One potential problem with this method is that it requires a floating point division, which not all computer support, or which may too expensive for a particular application. For these reasons, it is advantageous to devise a method for computing the squareroot that does not require any floating point divisions, (except division by 2, which can be easily done by shifting the binary representation one bit to the right), but only addition, subtraction and multiplication. The trick for doing this is to use Newton's method to compute 1/squareroot a, and then obtain squareroot a by multiplying by a. Your goal is to write an algorithm for computing the squareroot using this trick above. Division by 2 is allowed, but no other floating point division. Your algorithm should work for any input value a > 0. Write your algorithm as a function so you can call it any starting value. function y = squareroot (x) % Your algorithm goes here end Set the tolerance for the relative error in your solution to T = 10^-12. The relative error can be computed as e_k = |x_k - x_k+1|/x_k. where x_k and x_k+1 are successive iterates in your Newton iteration. Use your function to compute squareroot 35, squareroot 2.3 times 10^-6, and Squareroot17^15. Write out your three solutions to a file squareroot.out. To see where this sort of software assisted acceleration is used in gaming, see the course webpage for a link to the article: Origin of Quake3's Fast InvSqrt()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
