Consider the causal nonlinear discretetime system characteri
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[n] = 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[-1] =0.5?![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] 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]](/WebImages/4/consider-the-causal-nonlinear-discretetime-system-characteri-977829-1761501722-0.webp)
Solution
MATLAB Code:
function [yn,iter] = squareroot2(A)
yminus1 = 0.5;
yn=0.5*((yminus1)+A/yminus1);%running the first iteration outside the loop
yminus1 = yn;%taking the initial value for next iteration
iter=1;
while yn~=sqrt(A)%loop stops when square root found
yn=0.5*((yminus1)+A/yminus1);
yminus1 = yn;
iter=iter+1;
end
end
Output:
>> [sqrt2,iterations]=squareroot2(16)
sqrt2 =
4
iterations =
8
>> [sqrt2,iterations]=squareroot2(4)
sqrt2 =
2
iterations =
7
>> [sqrt2,iterations]=squareroot2(5)
sqrt2 =
2.2361
iterations =
7
>> [sqrt2,iterations]=squareroot2(3)
sqrt2 =
1.7321
iterations =
7
![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] 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]](/WebImages/4/consider-the-causal-nonlinear-discretetime-system-characteri-977829-1761501722-0.webp)
![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] 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]](/WebImages/4/consider-the-causal-nonlinear-discretetime-system-characteri-977829-1761501722-1.webp)