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

Having trouble turning from pseudocode into MATlab. The sum of student ID is 38

ID: 2266727 • Letter: H

Question

Having trouble turning from pseudocode into MATlab. The sum of student ID is 38

The "divide and average" method, an old-time method for approximating the square root of any positive number a can be formulates as Moreover, implemented with the following flowchart SquareRoot- 0 x-a/2 x -y err tol SquareRoot -x (40 pts.) Write a MATLAB program that will accept an arbitrary positive number value and calculate the square root. Test your program by calculating the square root of the sum of all numbers of your student's ID number. You must submit a print out of your M-File with your result and upload the M-File to ecourses.

Explanation / Answer

Matlab Script:

a = input('enter a positive number');
if a>0
tol = 10e-8;
x = a/2;
while 1==1 %infine loop only ends when err<tol
y = (x+a/x)/2;
err = ((y-x)/y);
x=y;
if abs(err)<tol %checking the error
SquareRoot = x;
break; %breaking the loop
end
end
  
else % if user entered value is less than zero
SquareRoot = 0;
end
disp(SquareRoot);

Command window output:

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