Question: function [ lastTerm , numTerms ] = sqrt 2 approx ( errorTol ) % [ lastTerm , numTerms ] = sqrt 2 approx ( ErrorTol
function lastTerm numTerms sqrtapproxerrorTol
lastTerm numTerms sqrtapproxErrorTol
This function calculates terms of the sequence
x xkxkxk
until the relative error between the Nth term and sqrt falls below
a given tolerance.
Input:
errorTol The tolerance used as the convergence criterion
Output:
lastTerm The last term in the sequence that meets the tolerance
numTerms The number of terms required to meet the tolerance
ea ;
numTerms uint;
lastTerm ;
while ea
lastTerm lastTerm;
ea abssqrtsqrt;
numTermsnumTerms ;
end
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
