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

This is a matlab problem Some arithmetic computations are easy to explain on pap

ID: 3818483 • Letter: T

Question

This is a matlab problem

Some arithmetic computations are easy to explain on paper, but require more thought to implement efficiently on a computer Among these is finding the square root of a number. Several algorithms have been developed to compute the square root of a positive real number p; here, we will utilize Halley's method, which is detailed below. Step 1. Begin with an initial guess, x 1, as in Equation [l T1 Step 2. Compute an intermediate value, y n, from the value ofx n, here n is the index of the current tion (Equation 121) ym Step 3. Compute a new approximation, x (n+1), from the values of x n and y n (Equation [3] rn (yn 3) n+1 3yn 1 Repeat Steps 2 and 3 until the difference between subsequent approximations x n and x (n+1) converges within some given precision limit5 (delta), as in Condition 41 n+ 1 Here, we ask you to write a MATLAB function, [X, N, el Ehalleysqrt(p, delta), that approximates the square root of positive real number p within the precision limit delta, and returns this estimate as the scalarvariable X. The function should also return N, the total number of iterations required (including the initial guess x 1) to converge within delta. Additionally, the function should return the error e as the magnitude of the difference between X and the true square root of p (computed using MATLAB's sqrt function). In other words, V

Explanation / Answer

function [x N e] = halleysqrt(p, delta)
    x = p/2;
    error_amount = delta + 1;
    N = 0;
  
    while(error_amount > delta)
        y = x*x/p;
        x_new = x*(y+3) / (3*y+1);
        error_amount = abs(x_new - x);
        x = x_new;
        N = N + 1;
    end
    e = abs(x - sqrt(p));
end

p = 889;
delta = 0.00001;
[x N e] = halleysqrt(p, delta);
fprintf("value of square root is %f ", x);
fprintf("Number of iterations made are %d ", N);
fprintf("error is %f ", e);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote