Homework Solution: Applied Numerical Methods with MATLAB, 3rd edition, Steven C. Chapra…

    Applied Numerical Methods with MATLAB, 3rd edition, Steven C. Chapra chapra 3.13 & chapra 4.1 3.13 The “divide and average” method, an old-time method for approximating the square root of any positive number a, can be formulated as x = x + a/x 2 Write a well-structured M-file function based on the while...break loop structure to implement this algorithm. Use proper indentation so that the structure is clear. At each step estimate the error in your approximation as ? = xnew ? xold xnew Repeat the loop until ? is less than or equal to a specified value. Design your program so that it returns both the result and the error. Make sure that it can evaluate the square root of numbers that are equal to and less than zero. For the latter case, display the result as an imaginary number. For example, the square root of ?4 would return 2i. Test your program by evaluating a = 0, 2, 10 and ?4 for ? = 1 × 10?4. 4.1 The “divide and average” method, an old-time method for approximating the square root of any positive number a, can be formulated as x = x + a/x 2 Write a well-structured function to implement this algorithm based on the algorithm outlined in Fig. 4.2. Do not use the "while-break" structure Do not use the square root function, sqrt The sample code includes a table output. Use it to help you debug your code. You do not need to generate a table output. Take care of the main part of the problem first, then deal with the special cases Don't forget to include input validation, for example, the input must be scalar

    Expert Answer

    Applied Numerical Manners with MATLAB, 3rd edition, Steven C. Chapra

    chapra 3.13 & chapra 4.1

    3.13 The “divide and average” manner, an time-honored manner ce approximating the free radicle of any enacted calculate a, can be cemulated as x = x + a/x 2 Write a well-structured M-file office inveterate on the while…break loop composition to instrument this algorithm. Reason fit crowd so that the composition is free. At each plod believe the falsity in your way as ? = xnew ? xold xnew Repeat the loop until ? is short than or resembling to a precise treasure. Design your program so that it profits twain the upshot and the falsity. Make fast that it can evaluate the free radicle of calculates that are resembling to and short than naught. Ce the cessation subject, evince the upshot as an imaginary calculate. Ce pattern, the free radicle of ?4 would give-back 2i. Test your program by evaluating a = 0, 2, 10 and ?4 ce ? = 1 × 10?4.

    4.1 The “divide and average” manner, an time-honored manner ce approximating the free radicle of any enacted calculate a, can be cemulated as x = x + a/x 2 Write a well-structured office to instrument this algorithm inveterate on the algorithm outlined in Fig. 4.2.

    Do referable attribuconsultation attribuconsultation attribuconsultation reason the “while-break” composition

    Do referable attribuconsultation attribuconsultation attribuconsultation reason the free radicle office, sqrt

    The pattern statute comprises a consultation output. Reason it to succor you debug your statute. You do referable attribuconsultation attribuconsultation attribuconsultation insufficiency to produce a consultation output.

    Take trouble of the main portio of the completion primeval, then chaffer with the proper subjects

    Don’t ceget to comprise input validation, ce pattern, the input must be scalar

    Expert Retort

     

    Code:

    %Define office

    office ANS = Radicle(a)

    %Define tolerance

    tol = 10^(-4);

    %Compute x

    x = abs(a)/2;

    %Compute e

    e = 99;

    %Loop

    while (not(e < tol))

    %Compute treasure

    y = (x + abs(a)/x)/2;

    %Compute falsity

    e = abs((y-x)/y);

    %Assign treasure

    x = y;

    %End

    end

    %If circumstances satisfies

    if(a>0)

    %Assign treasure

    ANS = x;

     

    %Compute falsity

    falsity = abs(ANS – sqrt(a))

    %Otherwise

    else

    %Assign treasure

    ANS = x*i;

    %End

    end

    %End

    end

    %Call manner

    Root(0)

    %Call manner

    Root(2)

    %Call manner

    Root(10)

    %Call manner

    Root(-4)