3 Given the difference equation Write a MATLAB function file
3. Given the difference equation Write a MATLAB function file that implements the above difference equation. The function takes an input the two (nonzero) initial values r(1) and r(2) and produces the first 10 values as output in a column vector.
Solution
** MATLAB function to implement the difference equation given in the question taking two non-zero initial values **
**Save this function file as DifferenceEquationSolution.m in the MATLAB directory **
function [y]=DifferenceEquationSolution(a,b)
x(1,1)=a; % First initial value
x(2,1)=b; % Second initial value
num=x(2,1); % numerator
deno=x(1,1); %denominator
for i=3:1:12 % values needed from x(3) to x(12) i.e. first 10 OUTPUTS
x(i,1) = num/deno;
num=x(i,1);
deno=x(i-1,1);
end
i=3:12;
y(:,1)=x(i,1); %OUTPUT COLUMN VECTOR WITH FIRST 10 OUTPUT VALUES
end
