One old-time method to estimate the square root of any positive number a is called divide and average: xi+1 = xi + a xi 2 Show that this formula is equivalent to Newton method. Hint: Start by solving f (x) = x 2 − a = 0. Use Matlab code
MATLAB CODE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear all;
a=10; % Write number a whose square root is to be evaluated
f=@(x) x^2-a ; % Function
f1=@(x) 2*x; % Derivative of the function
x(1)=1; % Initial guess
for i=1:1:100
x(i+1)=x(i)-(f(x(i))/f1(x(i)));
err=abs(x(i+1)-x(i));
if ( err <0.0001 )
root=x;
break
end
end
SQroot=x(i+1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
OUTPUT:
SQroot =
3.1623
Get Answers For Free
Most questions answered within 1 hours.