Question: function [ lastTerm , numTerms ] = sqrt 2 approx ( errorTol ) % [ lastTerm , numTerms ] = sqrt 2 approx ( ErrorTol

function [lastTerm, numTerms]= sqrt2approx(errorTol)
%[lastTerm, numTerms]= sqrt2approx(ErrorTol)
%
% This function calculates terms of the sequence
%
% x(1)=1, x(k)=(x(k-1)+2/x(k-1))/2
%
% until the relative error between the Nth term and sqrt(2) 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 =100;
numTerms = uint8(1);
lastTerm = ;
while ea >
lastTerm =(+2/lastTerm)/2;
ea = abs((sqrt(2)-)/sqrt(2));
numTerms=numTerms+ ;
end

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!