Looking for MATLAB code using for loops that solves the problem.
Looking for MATLAB code using while loops that solves the problem.
-GAN-tNGS-102-a0785/For720Loops7o20Part7o2029o20Homework7oa817629.pdi
100%
Problem 1 - Square Root: Edmond Halley (the astronomer famous for discovering Halley's Comet) invented a fast algorithm for computing the square root of a number. Halley's algorithm approximates √A as follows:
Start with an initial guess xi. The new approximation is then given by
1 yn = 1/4 * (xn + 15/A - yn/(10 - 3yn))
These two calculations are repeated until some convergence criterion (epsilon) is met. (Note: a convergence criterion is some sufficiently small number used to determine if the estimate is changing significantly with each iteration. In this situation, you could use epsilon = 0.00001)
xn+1 = xn
Write a MATLAB program that utilizes a for loop to approximate the square root of a number. The program should have two user-defined inputs: the number to determine the square root of and the initial guess. One way to stop the loop when some condition is satisfied is to use an if statement to test the criteria and the term break, both within the loop, as demonstrated in class. Incorporate this tool in your loop so it stops when the convergence criterion is satisfied. Test your function by approximating the square root of 5 and comparing it to the value calculated with the built-in MATLAB function, sqrt.
Note: yn or xn+1 utilize a notation method analogous to the indicial notation that we use in MATLAB. Therefore, yn could be considered synonymous with y(n). Likewise for xn+1 and x(n+1).
ren Fetchie Chapter 20....pdf
ELEC102Chap2..docx
p2...docx
ELI