# Can't plot recursive function

I am new to Mathematica and now I could use some help.

Trying to plot any of these functions generates a $RecursionLimit exception and I am wondering why. G[y_] := 0.7 G[y - 1] G[0] = 100; J[y_] := 0.1*G[y - 1] + 0.6 J[y - 1] H[y_] := 0.2*J[y] + 0.8*H[y - 1] H[0] = 0 Plot[ G[x], {x, 0, 10}] $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>

Evaluating any of G[2], H[4], J[3] works fine.

Any ideas would be much appreciated :)

-
Use DiscretePlot[G[x], {x, 0, 10}] . You are trying to plot for all x (Reals) between 0 and 10. – Dr. belisarius May 5 '14 at 14:56
@belisarius You reply or Community Wiki or something? :) – Öskå May 5 '14 at 15:59
The problem is that the implicit assumption is that recursion stops when the input reaches zero. This only works when the starting input in the call of G is a positive integer, which generally won't be the case in a Plot. You could use DiscretePlot as belisarius suggests or define the second part of the function as G[y_/;y<=0]=100. – Sjoerd C. de Vries May 5 '14 at 16:21
@belisarius so am I :D But when I answer in comments sometimes someone answers the same in a proper answer :) So I did ask what was your plans :) – Öskå May 5 '14 at 17:07

• Use DiscretePlot[G[x], {x, 0, 10}] . You are trying to plot for all x (Reals) between 0 and 10

• The problem is that the implicit assumption is that recursion stops when the input reaches zero. This only works when the starting input in the call of G is a positive integer, which generally won't be the case in a Plot. You could add G[y_]/;y <= 0] = 100 to the definition of G.

Thus, by combining each of them you have:

G[y_] := 0.7 G[y - 1]
G[y_] /; y <= 0 = 100
G[0] = 100;

J[y_] := 0.1*G[y - 1] + 0.6 J[y - 1]

H[y_] := 0.2*J[y] + 0.8*H[y - 1]
H[0] = 0;

Show[{DiscretePlot[G @ x, {x, 0, 10}, PlotStyle -> Red], Plot[G @ x, {x, 0, 10}]}]


-