Example: Let us use Mathematica to find the first 10 values of each of x[n], y[n], and z[n] defined by the system of difference equationsx[n+1] = x[n] + 2 y[n], y[n+1] = y[n] - 2 z[n], z[n+1] = y[n] - 3 z[n], having the initial conditions x[0] = y[0] = z[0] = 1.
We can obtain a list of values by means of a Table command just as we did for difference equations involving only one function. First we must input our initial valuesIn[1]:= x[0]:=1;y[0]:=1;z[0]:=1We then input our difference equations as follows:In[2]:= Table[{x[n+1]=x[n]+2*y[n],y[n+1]=y[n]-2*z[n],z[n+1]=y[n]-3*z[n]}, {n,0,9}] Out[2]= {{3, -1, -2}, {1, 3, 5}, {7, -7, -12}, {-7, 17, 29}, {27, -41, -70}, > {-55, 99, 169}, {143, -239, -408}, {-335, 577, 985}, > {819, -1393, -2378}, {-1967, 3363, 5741}}Thus we have the valuesn x[n] y[n] z[n] 0 1 1 1 1 3 -1 -2 2 1 3 5 3 7 -7 -12 4 -7 17 29 5 27 -41 -70 6 -55 99 169 7 143 -239 -408 8 -335 577 985 9 819 -1393 -2378 10 -1967 3363 5741
Example: Consider the following model for the growth of a herd of cattle. The females of a herd are divided into newborns, yearlings, and adults (those cattle that are 2 years of age and older). At the beginning of each year about 30 female calves will be born for every 100 adult females that are alive. Of these newborns, 67% survive to the beginning of the following year, while 72% of the yearlings survive to adulthood. An adult female will survive the year with a probability of 79%. If the herd starts with 100 adult females and 30 female calves, along with an appropriate number of males, then use this information to find the herd structure over the next 10 years.
Let us use x[n], y[n], and z[n] to denote the number of newborn females, yearling females, and adult females, respectively, in the herd at the beginning of year n. Since 30 female calves are born to every 100 adult females that are alive at the beginning of the year, then the number of calves born in year n+1 is given byx[n+1] = .30 z[n+1]. Since 67% of the newborns survive to their first year, we have
y[n+1] = .67 x[n]. The number of adult females alive at the beginning of year n+1 consists of the sum of the number that survive from the previous year, which is .79 z[n], and the number of yearlings from the previous year that survive to adulthood, which is .72 y[n]. Thus
z[n+1] = .79 z[n] + .72 y[n]. Our initial conditions imply that x[0] = 30, y[0] = 0, and z[0] = 100.
We can obtain a list of the values {x[n],y[n],z[n]} for n = 1, 2, ..., 10 by first designating the initial values x[0], y[0], and z[0]:
In[3]:= x[0]=30 Out[3]= 30 In[4]:= y[0]=0 Out[4]= 0 In[5]:= z[0]=100 Out[5]= 100and then by utilizing a Table construction with the commandIn[6]:= Table[{x[n+1]=.30*z[n+1],y[n+1]=.67*x[n],z[n+1]=.79*z[n]+.72*y[n]}, {n,0,14}] Out[6]= {{23.7, 20.1, 79.}, {23.0646, 15.879, 76.882}, > {21.6509, 15.4533, 72.1697}, {20.4421, 14.5061, 68.1404}, > {19.2826, 13.6962, 64.2753}, {18.1916, 12.9193, 60.6388}, > {17.162, 12.1884, 57.2065}, {16.1906, 11.4985, 53.9688}, > {15.2743, 10.8477, 50.9143}, {14.4098, 10.2338, 48.0327}, > {13.5942, 9.65457, 45.3141}, {12.8248, 9.10814, 42.7494}, > {12.099, 8.59264, 40.3299}, {11.4142, 8.10631, 38.0473}, > {10.7682, 7.64751, 35.8939}}Therefore we obtain the following values for the growth of the female cattle of the herd:n x[n] y[n] z[n] 0 30.0 0.0 100.0 1 23.7 20.1 79. 2 23.0646 15.879 76.882 3 21.6509 15.4533 72.1697 4 20.4421 14.5061 68.1404 5 19.2826 13.6962 64.2753 6 18.1916 12.9193 60.6388 7 17.162 12.1884 57.2065 8 16.1906 11.4985 53.9688 9 15.2743 10.8477 50.9143 10 14.4098 10.2338 48.0327 11 13.5942 9.65457 45.3141 12 12.8248 9.10814 42.7494 13 12.099 8.59264 40.3299 14 11.4142 8.10631 38.0473 15 10.7682 7.64751 35.8939Note that the herd appears to be decreasing in size with each year.
If f1=g1, f2=g2, ... is a collection of difference equations (including initial conditions) of the functions a1[n], a2[n], ... in terms of n, then the function RSolve of the package DiscreteMath`RSolve` is designed to attempt to solve this system. We utilize the function RSolve for this purpose in the following manner:
RSolve[{f1==g1,f2==g2,...},{a1[n],a2[n],...},n]
Example: Let us now use Mathematica to try to solve the system of difference equations given byx[n+1] = x[n] + 2 y[n], y[n+1] = y[n] - 2 z[n], z[n+1] = y[n] - 3 z[n], with the initial conditions x[0] = y[0] = z[0] = 1.
We must first load the package DiscreteMath`RSolve`In[7]:= <<DiscreteMath`RSolve`Now we define this system of difference equations in the command RSolve for a solution as follows:In[8]:= RSolve[{x[n+1]==x[n]+2*y[n],y[n+1]==y[n]-2*z[n], z[n+1]==y[n]-3*z[n],x[0]==1,y[0]==1,z[0]==1},{x[n],y[n],z[n]},n] Out[8]= {{x[n] -> n n (-1 - Sqrt[2]) n > 3 - (-1 - Sqrt[2]) + --------------- - (-1 + Sqrt[2]) - Sqrt[2] n n n (-1 + Sqrt[2]) (-1 - Sqrt[2]) + (-1 + Sqrt[2]) > ---------------, y[n] -> ---------------------------------, Sqrt[2] 2 1 + n 1 + n -((-1 - Sqrt[2]) - (-1 + Sqrt[2]) ) > z[n] -> --------------------------------------------}} 2 Sqrt[2]Thus we see that the solution of our system is given byx[n] = 3 - (-1 - √[2])n - (-1 + √[n])n (-1 - &radic[2])n - (-1 + &radic[2])n + ----------------------------------------- , &radic[2] (-1 - &radic[2])n + (-1 + &radic[2])n y[n] = ------------------------------------------, 2 -(-1 - &radic[2]){n+1} + (-1 + &radic[2]){n+1} z[n] = -------------------------------------------------- . 2 &radic[2]
Example: Let us attempt to solve the system of difference equationsx[n+1] = .30 z[n+1], y[n+1] = .67 x[n], z[n+1] = .79 z[n] + .72 y[n]. with the initial conditions x[0] = 30, y[0] = 0, and z[0] = 100, by utilizing the RSolve command of Mathematica.
Assuming that we have already loaded the package DiscreteMath`RSolve`, we now input this system of difference equations as arguments of the RSolve command to solve for each of x[n], y[n], and z[n] in terms of n:In[9]:= RSolve[{x[n]==.30*z[n],y[n+1]==.67*x[n],z[n+1]==.79*z[n]+.72*y[n], x[0]==30,y[0]==0,z[0]==100},{x[n],y[n],z[n]},n]n n Out[9]= {{x[n] -> 4.19589 (-0.153402) + 25.8041 0.943402 ,n > y[n] -> -18.326 (-0.153402) + 18.326 0.943402n n > z[n] -> 13.9863 (-0.153402) + 86.0137 0.943402 }}Thus we see that we obtain the solutionsx[n] = 4.19589 (-0.153402)n + 25.8041 (0.943402)n , y[n] = -18.326 (-0.153402)n + 18.326 (0.943402)n , z[n] = 13.9863 (-0.153402)n + 86.0137 (0.943402)n .