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?

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]

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site