Re: Plotting a function -

• To: mathgroup at smc.vnet.net
• Subject: [mg71691] Re: Plotting a function -
• From: "Ray Koopman" <koopman at sfu.ca>
• Date: Sun, 26 Nov 2006 05:49:31 -0500 (EST)
• References: <ek990u\$k88\$1@smc.vnet.net>

```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?"

If f[x] is supposed to give a numeric indicator of whether or not the
decimal representation of an integer 'x' has a '3' in it, then try

f[x_Integer] := Boole@MemberQ[IntegerDigits@x,3]

If the numerator of g[x] is supposed to be the number of values
in the range 1,...,x for which f gives '1', then you could say

g[x_Integer] := Sum[f[i], {i, x}]/x

There are other ways to get g, some of which may be much faster
but less obvious.

To get the plot you could do

ListPlot[Table[g[x],{x,100}]]

Again, there are other ways to do it, but this is clearest.

```

• Prev by Date: RE: Area of ellipse between major axis and ray through focus, given angle
• Next by Date: Re: Not accepting function as parameter
• Previous by thread: Re: Plotting a function -
• Next by thread: Re: Plotting a function -