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

-Write a MATLAB code that implements the above recursion to compute the square r

ID: 2291641 • Letter: #

Question

-Write a MATLAB code that implements the above recursion to compute the square root of 81, 49, 16, 3.

-How many iterations does it take to converge to the true start at y[-1]=0.2

Consider the causal non-linear discrete-time system characterized by the following difference equation: If we use as input x[n] to this system (algorithm) a step function of amplitude A (i.e. x[n] A u[n), then y n] will converge after several iterations to the square root of A. Write a MATLAB program that implements the above recursion to compute the square root of 81, 49, 16 and 3 . How many iterations does it take to converge to the true value starting at y[-1]-0.2?

Explanation / Answer

Matlab Script:

A = input('Enter A');
xn = 1*A;% A u[n]
yn_prev = 0.2; %y[-1]
n=1; %number of iteration
while 1==1
yn_next = 0.5*(yn_prev+(xn/yn_prev));
if abs(yn_next-yn_prev)<1e-4
break;
else
yn_prev = yn_next;
n = n+1;
end
end

fprintf('Square root of %d is %d number of iterations are %d ',A,yn_next,n);