Question: Q 1 ) In this question, you asked to write a MATLAB code for the following algorithm. This algorithm describes an iterative method called the

Q1) In this question, you asked to write a MATLAB code for the following algorithm. This algorithm
describes an iterative method called the Babylonian method for finding the square root of a given
positive number S.
Algorithm 1 The Babylonian square-root algorithm
Require: Initial positive guess x0, a prespecified tolerance S, maximum number of iterations.
Set i=0
xi+1=xi+Sxi2
Calculate |a|=|xi+1-xixi+1|100%
if The stopping criterion is satisfied or the maximum number of iterations is reached then
Stop
else
i=i+1
Go back to Step 2.
end if
Output: x**=xi+1~~S2
DO the following tasks:
a) Write a MATLAB code for the Algorithm 1 using the FOR-END loop command. Use the ta-
ble command to print the results. Remember: you need to use the break command to stop the
algorithm when |a|S.
b) Write a MATLAB code for the Algorithm 1 using the WHILE-END loop command. Use the
table command to print the results.
 Q1) In this question, you asked to write a MATLAB code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!