Consider the causal non-linear discrete-time system characterized by the followi
ID: 2082127 • 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[-1] = 0.5?Explanation / Answer
Matlab Scirpt:
function [sqrtA num_iter] = sqrtA1(A,y_1)
yprev = y_1;%y[-1]
num_iter = 1;
while 1==1
ynext = 0.5*((yprev)+(A/yprev));
if abs(yprev-ynext)<10^-4%taking error difference upto 10^-4
sqrtA = ynext;
break;
else
yprev = ynext;
num_iter = num_iter+1;
end
end
end
command window log:
>> clear all
>> sqrtA1(16,1)
ans =
4.0000
>> sqrtA1(4,1)
ans =
2.0000
>> sqrtA1(5,1)
ans =
2.2361
>> sqrtA1(3,1)
ans =
1.7321
>> [sqrtA, num_iter] = sqrtA1(3,0.5)
sqrtA =
1.7321
num_iter =
6
>>