Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Description chapra 3.13 & chapra 4.1 Do not use the \"while-break\" stru

ID: 3882655 • Letter: P

Question

Problem Description chapra 3.13 & chapra 4.1 Do not use the "while-break" structure Do not use the squareroot function, squareroot The sample code includes a table output. Use it to help you debug your code. You do not need to generate a table output. Take care of the main part of the problem first, then deal with the special cases Don't forget to include input validation, for example, the input must be scalar Solution function [x, ea] = mySqrt(a, es) %calculates squareroot by divide and average (chapra 3.13 & chapra 4.1) % % [x, ea] = mySqrt(a) % INPUT a: a scalar real number % es: error stopping criterion, % % OUTPUT x: squareroot of a % ea: the final error, % x = a: % replace this line with your code to solve for the squareroot of x end

Explanation / Answer

function [x, ea] = mySqrt(a, es)
fa = a/2;
sa = a/fa;
x = mean([fa sa]);

% Repeat until you obtain a good enough root
for i = 1:100
fa = x;
sa = a/fa;
x = mean([fa sa])
ea = abs(a-x^2);
if (ea <= es)
i = 100;
break;
else
i = 1;
end
end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote