Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please solve by using Matlab Edmond Halley (of comet fame) invented a fast algor

ID: 2079159 • Letter: P

Question

Please solve by using Matlab

Edmond Halley (of comet fame) invented a fast algorithm for computing the squareroot of a number. Given a number A greaterthanorequalto 1, Halley's algorithm calculates squareroot A in the following manner: Start with an initial guess for the squareroot , given as x_1 Calculate the intermediate step y_n = 1/A x_n^2, where n is the iteration number Calculate the next iteration approximation x_n + 1 = x_n/8 (15 - y_n(10 - 3y_n)) Repeat from [2] until the convergence criterion [x_n + 1 - x_n| lessthanorequalto epsilon (where epsilon is some small number) is met. Write a Matlab function called Halley_ squareroot .m which takes two inputs (A and e) and returns the approximation of the squareroot of A. Compare your results with the built-in Matlab function squareroot . m. Can you determine which is faster for epsilon = 0.0001 - your function or the built-in function?

Explanation / Answer

Matlab function code:

function sqrtA=Halley_sqrt(A,e)
xu=1;
R=1;
i=1;
while abs(R)>e;
xi=xu;
yi=(1/A)*(xi^2);
xu=(xi/8)*(15-(yi*(10-(3*yi))))
R=xu-xi;
  
end

sqrtA=xu;

it will be faster than sqrt.m function