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

Consider the causal non-linear discrete-time system characterized by the followi

ID: 2081941 • Letter: C

Question

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

Explanation / Answer

Copy the following code to a new script in MATLAB.

clear all; close all; clc;
x = [16 4 5 3];
N = length(x);
for j=1:N
y = 0.5; % initial value of y[n], i.e, y[-1]
y(2) = 0.5*(y(1) + x(j)./y(1)); % y[0]
i = 2;
% if the previous two values of y[n] are not equal, then compute next
% value of y[n]
while(y(i-1)~=y(i))
y(i+1) = 0.5*(y(i) + x(j)./y(i));
i = i+1;
end
y = y(2:end); % removing y[-1] from the original array
n = length(y);
figure; stem(0:n-1,y);ylim([0 max(y)]);
title(['Plot of y[n] for A = ',num2str(x(j))]);
xlabel('n');ylabel('y[n]');
  
fprintf('A = %d ',x(j));
fprintf('Value of y[n] after each iteration : ')
% The last element of y[n] has been repeated to show that saturation
% has been attained.
for i=1:n
fprintf('y[%d] = %.16f ',i-1,y(i));
end
fprintf('Number of iterations = %d ',n-1);
end