Re: Plotting a function -

*To*: mathgroup at smc.vnet.net*Subject*: [mg71661] Re: Plotting a function -*From*: "dimitris" <dimmechan at yahoo.com>*Date*: Sun, 26 Nov 2006 03:48:42 -0500 (EST)*References*: <ek990u$k88$1@smc.vnet.net>

Although I am not quite sure that I understand your question, here is one attempt. However note that my solution is not very quick; I am sure someone else will provide you with a better solution. Clear["Global`*"] Here is a function that checks if an integer contains 3 in base-10; if so it returns 10, otherwise it returns 0. f[x_Integer] := If[DigitCount[x, 10, 3] > 0, 1, 0] E.g. f /@ Range[100] {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0} Timing[f /@ Range[100000]][[1]] 5.984*Second Here is your desired function (I believe!) g[x_Integer] := Plus @@ N[f /@ Range[x]]/x Here is your visualization Timing[lst = g /@ Range[1000]][[1]] 32.09400000000001*Second ListPlot[lst, PlotStyle -> {Blue, AbsolutePointSize[3]}, ImageSize -> 400, Axes -> False, Frame -> {True, True, False, False}, FrameTicks -> {Range[0, 1000, 100], Range[0, 0.5, 0.1]}, PlotRange -> {{-0.001, 1030}, {-0.001, 0.41}}, Epilog -> Rectangle[{400, 0.1}, {800, 0.3}, ListPlot[Take[lst, 30], PlotStyle -> {Blue, AbsolutePointSize[4]}, DisplayFunction -> Identity]]] Regards Dimitris Craig Reed wrote: > Hi - > > I'm trying to get Mathematica 5.2 to graph a function which is the ratio of > integers which have a '3' in them. Done in Exce3l, the graph of the first > 32,000 data points has a fractal look to it, especially when done with a > log scale. > > What I've tried is the following > > > f[x_] := Boole[DigitCount[x, 10, 3]] > g[x_] := Sum[f, {i, x}]/x > Plot[g, {x, 1, 100}] > > > I get 3 errors of "g is not a michine-size real number at" followed by 3 > real numbers: > 1.000004125 > 5.016125..... > 9.39607..... > > What am I doing wrong? or perhaps what I should ask is, "Is there a better > way?"