# Test different parameter values in DiscretePlot

I have a discrete dynamic model with two variables $x$ and $y$ as:

$x_t =ax_{t-1}+by_{t-1}$

$y_t =cx_{t-1}+dy_{t-1}$

where $a, b, c, d$ are parameters.

I would like to plot how the movement of x[t] changes when a model parameter changes using DiscretePlot. Is there any way I can see the result in one diagram. For instance, I would like to see the movement of $x_t$ when $a=0.1$ and that when $a=0.2$ in one diagram so that the difference can be more explicit. I would like to do the same for $y_t$ as well.

My code so far is:

x[t_] := x[t] = a*x[t - 1] + b*y[t - 1]
y[t_] := y[t] = c*x[t - 1] + c*y[t - 1]


with initial values as:

x[0] = 1;
y[0] = 1;


and parameter values as:

a = 0.1
b = 0.2
c = 0.3
d = 0.4


My code for plot is simply this:

Plot1 = Show[GraphicsRow[{DiscretePlot[{x[t]}, {t, 0, 10}, PlotLabel -> "x",
BaseStyle -> {FontSize -> 10}, Filling -> None, Joined -> True],
DiscretePlot[{y[t]}, {t, 0, 10}, PlotLabel -> "y",
BaseStyle -> {FontSize -> 10}, Filling -> None,
Joined -> True]}], ImageSize -> Full]
Export["Plot1.pdf", Plot1]

-
It might be more expedient for you to reformulate this as repeated multiplication of a matrix with a vector: MatrixPower[{{a, b}, {c, d}}, t, {1, 1}]. – J. M. Feb 21 at 2:39

Clear[a, b, c, x, y, sol, sol2]


Use RSolve for recursive equations.

Using the equations in the code blocks,

sol[a_, b_, c_] =
RSolve[{x[t] == a*x[t - 1] + b*y[t - 1],
y[t] == c*x[t - 1] + c*y[t - 1],
x[0] == 1, y[0] == 1}, {x[t], y[t]}, t][[1]];

Manipulate[
DiscretePlot[
Evaluate[{x[t], y[t]} /. sol[a, b, c]],
{t, 0, 10},
AxesLabel -> {"t", None},
BaseStyle -> {FontSize -> 10},
Filling -> None,
Joined -> True,
PlotLegends -> {"x[t]", "y[t]"}],
{{a, .1}, .1, .5, .025, Appearance -> "Labeled"},
{{b, .2}, .125, .5, .025, Appearance -> "Labeled"},
{{c, .3}, .1, .5, .025, Appearance -> "Labeled"}]


Using the original equations

sol2[a_, b_, c_, d_] =
RSolve[{x[t] == a*x[t - 1] + b*y[t - 1], y[t] == c*x[t - 1] + d*y[t - 1],
x[0] == 1, y[0] == 1}, {x[t], y[t]}, t][[1]];

Manipulate[
DiscretePlot[
Evaluate[{x[t], y[t]} /. sol2[a, b, c, d]],
{t, 0, 10},
AxesLabel -> {"t", None},
BaseStyle -> {FontSize -> 10},
Filling -> None,
Joined -> True,
PlotLegends -> {"x[t]", "y[t]"}],
{{a, .1}, .1, .5, .025, Appearance -> "Labeled"},
{{b, .2}, .125, .5, .025, Appearance -> "Labeled"},
{{c, .3}, .1, .5, .025, Appearance -> "Labeled"},
{{d, .4}, .1, .5, .025, Appearance -> "Labeled"}]


EDIT: Looking only at x[t] for various values of a

DiscretePlot[
Evaluate[Table[x[t] /. sol2[a, .2, .3, .4], {a, {.1, .2}}]],
{t, 0, 10},
AxesLabel -> {"t", "x[t]"},
BaseStyle -> {FontSize -> 10},
Filling -> None,
Joined -> True,
PlotLegends -> {"a = 0.1", "a = 0.2"}]


-
thanks so much! In fact, what I would like to see is two different evolutions of x[t] appearing in one diagram; one for, say, a being 0.1 and the other for a being 0.2. Let us forget about the other variable, y[t]. Can I do this without using Manipulate? – ppp Feb 21 at 3:29
@ppp - see last edit. – Bob Hanlon Feb 21 at 3:37
Great! Thanks so much! – ppp Feb 21 at 3:46