###### GS 2000/Math - Collins
Lab 3
Difference Equations

```In this lab we will use simulation to study various difference
equations.

1. Linear Homogeneous

Solve x(n+1) = a x(n) for various values of a.

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 with a = 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 I

Solve x(n+1) = a x(n) + w  for various values of a and w.

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 for w.

This difference equation has an equilibrium solution of x(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
if a = 1.2 and w = -20, then the equilibrium value is
-20/(1-1.2) = 100, so try x(0) = 105 and x(0) = 95.

3. Nonlinear

Solve x(n+1) = a x(n)(1- x(n)) for various values of a and x(0).

Again, there is code below, but you might want to try to modify the previous
script first.

This has 2 equilibrium solutions x(n) = 0 and x(n) = (a-1)/a

Run the script with a = 1.2, 2.5, 3.3, 3.8.  For each value of
a, try various values of x(0) (between 0 and 1).

4. Linear Non-Homogeneous II (Challenge)

Solve x(n+1) = a x(n) + w(n)  for various values of a and
different expressions for w(n).

The challenge is how to specify w(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

```
ccollins@math.utk.edu