Difference Equations: Single and Systems

In this lab we will use simulation to study various difference equations. There are 4 questions that you should answer before you leave the lab today.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 as "diff1.m" % 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 by typing diff1. It will prompt you for a value foraand an initial valuex(0). Try 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 forx(0).Question 1For what range of values foradoes the solution tend toward 0? For what range of values does it tend toward infinity?2. Linear Non-HomogeneousSolvex(n+1) = a x(n) + bfor various values ofaandb. 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 forb. Call this file "diff2.m". You run it by typing diff2 It will prompt you for the values ofa,bandx(0). This difference equation has an equilibrium solution ofx(n) = b/(1-a). Run the script with(a,b)= (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 andb= -20, then the equilibrium value is -20/(1-1.2) = 100, so tryx(0) = 105andx(0) = 95.Question 2For what range of values foradoes the solution tend toward the equilibrium value?3. Linear Predator-PreyLetx(n)be the number of rabbits andy(n)be the number of foxes afternweeks. The model for their interaction is:x(n+1) = x(n) + 0.1 x(n) - 0.25 y(n) y(n+1) = y(n) - 0.2 y(n) + 0.15 x(n)On their own rabbits would grow in number, foxes would decrease. Write a MATLAB script (or use the one below) to simulate this system for 100 weeks. Plot the number of foxes vs. the number of rabbits, i.e. y vs. x.Question 3Try starting with 20 rabbits and 4 foxes. Do both species survive? Try increasing the starting rabbit population. Is there any value which lets both species survive?4. Nonlinear Predator-PreyLetx(n)andy(n)be as in 1. Now we are going to model the interaction between the rabbits and the foxes by amixingterm:x(n)y(n). The model is thenx(n+1) = x(n) + 0.1 x(n) - 0.02 x(n)y(n) y(n+1) = y(n) - 0.2 y(n) + 0.01 x(n)y(n)On their own rabbits would grow in number, foxes would decrease. When the number of rabbits is low, it is harder for the foxes to find them. Write a MATLAB script (or use the one below) to simulate this system for 100 weeks. Plot the number of foxes vs. the number of rabbits, i.e. y vs. x.Question 4Try starting with 20 rabbits and 4 foxes. Do both species survive? What do you think would happen if you extended the simulation? Try different starting values. Is there anequilibriumvalue, i.e. are there starting values so that the populations never change?5. Other Interactions (Extra)Here are some other types of interactions you can study:Arms Racex(n+1) = 100 + 0.5 y(n) y(n+1) = 75 + 0.8 x(n)Competeting Speciesx(n+1) = x(n) + 0.1 x(n) - 0.25 y(n) y(n+1) = y(n) + 0.05 y(n) - 0.15 x(n)On their own, each would grow in number, and each are hurt by the existence of the other. Nonlinear version:x(n+1) = x(n) + 0.1 x(n) - 0.02 x(n)y(n) y(n+1) = y(n) + 0.05 y(n) - 0.01 x(n)y(n)Symbiotic Relationshipx(n+1) = x(n) - 0.1 x(n) + 0.25 y(n) y(n+1) = y(n) - 0.05 y(n) + 0.15 x(n)On their own, each would die, but together they survive.

Sample Scriptsdiff2.m% script file to simulate the difference equation x(n+1) = a x(n) + b a = input('Enter the value for a:'); b = input('Enter the value for b:'); x(1) = input('Enter the initial value (x(0)):'); for n = 1:100 x(n+1) = a*x(n) + b; end plot(x) title(['Difference Equation with a = ',num2str(a),' and b = ',num2str(b)]) % end of scriptpredprey.m% script file to simulate the linear predator-prey model x(1) = input('Enter the initial number of rabbits:'); y(1) = input('Enter the initial number of foxes:'); for n = 1:100 x(n+1) = x(n) + 0.1*x(n) - 0.25*y(n); y(n+1) = y(n) - 0.2*y(n) + 0.15*x(n); end plot(x,y), xlabel('Rabbits'), ylabel('Foxes') % end of scriptpredprey2.m% script file to simulate the nonlinear predator-prey model x(1) = input('Enter the initial number of rabbits:'); y(1) = input('Enter the initial number of foxes:'); for n = 1:100 x(n+1) = x(n) + 0.1*x(n) - 0.02*x(n)*y(n); y(n+1) = y(n) - 0.2*y(n) + 0.01*x(n)*y(n); end plot(x,y), xlabel('Rabbits'), ylabel('Foxes') % end of script