The Bakhshali manuscript is a mathematical manuscript written on birch bark whic
ID: 3602493 • Letter: T
Question
The Bakhshali manuscript is a mathematical manuscript written on birch bark which was found near the village of Bakhshali in, what is now, Pakistan in 1881. The scripts are dated around 400 AD. The manuscript gives various algorithms and techniques for variety of mathematical problems, such as computing the square roots. According to Bakhshali manuscript, the square root of a number s can be approximated as where A=x + P and D=s- 2 A where x1 is an approximate root. Write a MTLAB function function M file to calculate the square root of a positive real number using the Bakshali method. The first line of your code must read function sqrts = my sqrtB(s, sigfig) where sqrtS is the square root of s, and sigfig is the accuracy in terms of significant digits. Display the iteration number, the iterative error (%), and the actual true error (not % error) at each iteration using an fprintf statement with a reasonable format. Use MATLAB's built-in function sqrt () to calculate the true value which needs to be calculated prior to the while · Using your function determine the square root of 19781.9876 with an accuracy of 14 significant digits >mysqrtB (565127.81273, 14); Relative Iterative Error % Iteration Actual Error number 299.9858444914370352 299.7736672496993720 296.4179950691633962 251.1677827254335966 67.4093329061293218 0.8641532087222429 0.0000000685146374 0.0000000000000000 2 3 69891.7267432197404560 16919.1180507205281174 3705.8853149821111401 517.6249117986966439 6.4962708304982471 0.0000005150586730 0.0000000000000000 0.0000000000000000 The square root of 565127.81273 is 751.7498338742749 Hints: Since A depends on P, and P depends on D, update D first, then P, and then A.Explanation / Answer
Program:--
function sqrtS = mysqrtB(s, sigfig) %matlab function
fprintf(' Iteration Relative Actual Number Iterative Error Error '); %print head of the table
fprintf('=================================================================== ');
x1=1; %initial value of root
D=s-x1^2; %calculation
P=D/(2*x1);
A=x1+P;
aprox= A-(P^2/(2*A));
actual=sqrt(s);
old=digits(14);
i=0;
while (vpa(actual)~=vpa(aprox)) %checking 14 significant digits of numbers ( actual and approximation )
true_error=actual-aprox; %calculating true error
relative_error=abs(true_error)/actual; % calculating relative error
i=i+1; %iteration
fprintf('%d %.14f %.14f ',i,relative_error,true_error); %printing calculated values
D=s-x1^2; %repeating the above calculations
P=D/(2*x1);
A=x1+P;
aprox= A-(P^2/(2*A));
x1=aprox;
end
fprintf('the square root of %f is %.14f ',s,aprox); %printing the final calculated root
end
output:--
>> mysqrtB(565127.81273,14)
Iteration Relative Actual
Number Iterative Error Error
===================================================================
1 186.93912125341308 -140531.45334685623000
2 186.93912125341308 -140531.45334685623000
3 45.99143125266161 -34574.05080382850400
4 10.77444877481613 -8099.69007655490710
5 2.04916606132857 -1540.46024618455700
6 0.14039103939969 -105.53894054615751
7 0.00003701886465 -0.02782892535288
the square root of 565127.812730 is 751.74983387427494
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.