function LinearDifference %Plots solutions to the linear difference equation %x_n=A_1*lambda_1^n+A_2*lambda_2^n as a function of n t=5; %total number of time steps n=[0:1:t]; %sets n=0,1,2,...,t A_1=1; %Value for Coefficient A_1 A_2=1; %Value for Coefficient A_2 %Real Eigenvalues lambda_1=3; %Value for the first eigenvalue lambda_2=2; %Value for the second eigenvalue %Complex Eigenvalues a=1; b=2; r=sqrt(a^2+b^2); phi=atan(b/a); %Linear Difference Equation x_n=A_1*lambda_1.^n+A_2*lambda_2.^n; %Real Eigenvalues %x_n=r.^n.*(A_1.*cos(n.*phi)+A_2.*sin(n.*phi)); %Complex Eigenvalues %Plots solutions plot(n,x_n) xlabel('n') ylabel('x_n') title('Plot of x_n as a function of n')