Please use the following code to answer the questions: function [sqr, er] = Babylonian_part(p,maxitr) %% Babylonain
Question:
Please use the following code to answer the questions:
function [sqr, er] = Babylonian_part(p,maxitr)
%% Babylonain Method for Finding the square root of p
% This function calculates the square root of a real number using the Babylonian
% method (an iterative algorithm) with an user-defined maximum number of
% iterations, and plots the relative error versus the number of iterations
% Inputs/Outputs:
% p = The number whose square root is to be evaluated
% maxitr = Maximum number of iterations allowed
% er = Vector of approximate relative errors
% sqr = Estimated value of the square root of p
%% Initializations
er = ; % Initializate the approximate error vector er
sqr = ; % Initializate sqr by p
%% Execute the Alogrithm
for k = 1:maxitr
% Store old estimate
% Calculate new estimate
% Calculate percent error
end
%% Plot the error versus iteration number
figure;
plot((1:k),er(1:k), 'ko','markersize',6,'markerfacecolor','r'); grid on;
xlabel('Iteration Number');
ylabel('Relative Error (%)');
ylim([-5 100]);
set(gca,'Fontsize',12,'LineWidth',1);
end
Intermediate Accounting
ISBN: 978-0470161012
9th Canadian Edition, Volume 2
Authors: Donald E. Kieso, Jerry J. Weygandt, Terry D. Warfield.