TASK: Write a script that estimates the square root of 2017 using averaging.
COMMENT: One way to approximate the square root of a number x starts with any positive guess "r" and then repeatedly replaces r by a new estimate:
r = ( r + x/r) / 2
INSTRUCTIONS:
Use MATLAB's sqrt() function to set the variable "s" to the exact value of the square root of 2017. s = ?; Use the name "r" for the variable that stores your estimate. Give r an initial value of 1, and have r printed out. r = 1 Your estimation error "e" is | r - s |. Compute "e" using MATLAB's abs() function, and have e printed out. e = abs ( ? ) Replace r by the average of r and 2017/r, and have it printed out. Recompute e, because r has changed, and have it printed out. r = ? Carry out the "replace and recompute" steps 6 times. (Use "cut and paste" in your editor to repeat the steps.)If your script is correct, then except for the very first step, you should see the size of the error e decreasing each time. After 6 steps, the error should be less than 10.
SUBMIT: Your work should be stored in a script file called "hw001.m". Your script file should begin with at least three comment lines:
% hw001.m % YOUR NAME % This script (describe what it does) % Add any comments here that you care to make.If this problem is part of an assignment, then submit it to Canvas.