Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MATLAB uppress intermediate results not requested by using the semicolon line termination. Use only functions, commands r statements discussed in the class lectures, handouts and
MATLAB
uppress intermediate results not requested by using the semicolon line termination. Use only functions, commands r statements discussed in the class lectures, handouts and specifically mentioned in the problem statements. Ine method for calculating square-roots directly is called the Babylonian method, where an equation is run eratively (over and over) until the output converges to the desired result. The iterative equation Babylonian method square-roots is given below: yn=21(yn1+yn1x) where x is the original value to be square-rooted, n and yn1 are the current and previous iteration values of the square-root-estimate, respectively, and n is the iteration number. Write a MATLAB function which accepts two inputs, and generates one output. The first input should be the value to be square-rotted. The second input will be the number of iterations to run with the Babylonian equation above. The output should be the value of the nth iteration. Include comments which provide a detailed response to the "help" command. Before you can process the first iteration, you must set the initial condition of the output value. In other words, the value of y0 must be defined. You can set the initial condition y0 to be half of the input variable x. You can use a loop to iterate the equation, where the iteration number, n, can be your loop counter. Below are some sample outputs: >mySqrt(2,0)ans=1.0000mySqrt(2,1)ans=1.5000mySqrt(2,2)ans=1.4167mySqrt(2,3)ans=1.4142 Note how using more iterations gets us closer to the true value of the square-root of 2 . If we select zero iterations. the result is simply 1/2 of the input valueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started