Difference Equations

In this lab we will use simulation to study various difference equations.ccollins@math.utk.edu1. Linear HomogeneousSolvex(n+1) = a x(n)for various values ofa. Copy the following MATLAB code into a m-file and save it. % script file to simulate the difference equation x(n+1) = a x(n) a = input('Enter the value for a:'); x(1) = input('Enter the initial value (x(0)):'); for n = 1:100 x(n+1) = a*x(n); end plot(x) title(['Difference Equation with a = ',num2str(a)]) % end of script Run it witha= 0.2, 0.5, 0.9, 0.95, 1, 1.05, 1.1, -1, -0.5 (You can use any value you want for x(0))2. Linear Non-Homogeneous ISolvex(n+1) = a x(n) + wfor various values ofaandw. I put a copy of a MATLAB script below, but you might try to see if you can figure out how to modify the previous script to solve this problem. Note: you should have the user input a value forw. This difference equation has an equilibrium solution ofx(n) = w/(1-a). Run the script with(a,w)= (1.1,-10), (0.9,10), (1.5,-100), (0.5,100) For each pair, use initial values near the equilibrium value, for example ifa= 1.2 andw= -20, then the equilibrium value is -20/(1-1.2) = 100, so tryx(0) = 105andx(0) = 95.3. NonlinearSolvex(n+1) = a x(n)(1- x(n))for various values ofaandx(0). Again, there is code below, but you might want to try to modify the previous script first. This has 2 equilibrium solutionsx(n) = 0andx(n) = (a-1)/aRun the script witha= 1.2, 2.5, 3.3, 3.8. For each value ofa, try various values ofx(0)(between 0 and 1).4. Linear Non-Homogeneous II (Challenge)Solvex(n+1) = a x(n) + w(n)for various values ofaand different expressions forw(n). The challenge is how to specifyw(n). I'll post my solution tomorrow.Other Scripts% script file to simulate the difference equation x(n+1) = a x(n) + w a = input('Enter the value for a:'); w = input('Enter the value for w:'); x(1) = input('Enter the initial value (x(0)):'); for n = 1:100 x(n+1) = a*x(n) + w; end plot(x) title(['Difference Equation with a = ',num2str(a),' and w = ',num2str(w)]) % end of script % script file to simulate the difference equation x(n+1) = a x(n)(1-x(n)) a = input('Enter the value for a:'); x(1) = input('Enter the initial value (x(0)):'); for n = 1:100 x(n+1) = a*x(n)*(1-x(n)); end plot(x) title(['Difference Equation with a = ',num2str(a),' and x(0) = ',num2str(x(1))]) % end of script