Question: Sequence to SQRT(2) (while loop based on convergence, scalar variables) My Solution Consider the sequence 1,23,1217, defined by x1=1,xk=21(xk1+xk12)fork=2,3,4,,N The sequence converges on 2 as

 Sequence to SQRT(2) (while loop based on convergence, scalar variables) My

Sequence to SQRT(2) (while loop based on convergence, scalar variables) My Solution Consider the sequence 1,23,1217, defined by x1=1,xk=21(xk1+xk12)fork=2,3,4,,N The sequence converges on 2 as N increases. The relative error, , between the Nth term in the sequence and 2 is given by the formula: =22xN Note the vertical bars indicate an absolute value. Code has already been provided to define a function named sqrt2approx that accepts a single scalar input variable errorTol. Add commands to use this input value for the error tolerance as the convergence criterion for the sequence. Use a while loop to generate sequence terms until the relative error, , is less than or equal to the value in the input tolerance variable errorTol. Assign values to the two output variables as follows. 1. Assign the value of the the last term generated to the variable lastTerm. 2. Count the number of terms needed to meet the tolerance and assign this value with 8-bit unsigned integer datatype to the variable numTerms. Note the value of the variable errorTol is defined as an input to the function. Do not overwrite this value in your code. Be sure to assign a value to each of the output variables

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!