Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Lab Report Week 4
Lydia Nadeau
Partner: Molly Kydland
September 21, 2015We will define a function that will tell us the fraction of integers that are multiples of their units digit.
p[n0_] := Module{n = n0}, T = TableIntegerQn IntegerDigits[k][[-1]], {k, 1, n};
Count[T, True] / n
p[100]
Power::infy : Infinite expression 1
0 encountered.
Power::infy : Infinite expression 1
0 encountered.
Power::infy : Infinite expression 1
0 encountered.
General::stop : Further output of Power::infy will be suppressed during this calculation.
2
5
There is still the problem of dividing by zero, so we will need to fix this. We will try using the Mod
function.
Mod[8, 3]
2
Mod[9, 4]
1
We will try replacing IntegerQ[n/IntegerDigits[n][[-1]]] with Mod[n,IntegerDigits[n][[-1]]].
There is still a problem when the units digit of n is 0, so we will need to find a way to exclude the outputs
of “indeterminate”.
Printed by Wolfram Mathematica Student Edition
n = 100;
T = Table[Mod[k, IntegerDigits[k][[-1]]], {k, 1, n}]
Mod::indet : Indeterminate expression Mod[10, 0] encountered.
Mod::indet : Indeterminate expression Mod[20, 0] encountered.
Mod::indet : Indeterminate expression Mod[30, 0] encountered.
General::stop : Further output of Mod::indet will be suppressed during this calculation.
{0, 0, 0, 0, 0, 0, 0, 0, 0, Indeterminate, 0, 0, 1, 2, 0, 4, 3, 2, 1, Indeterminate, 0,
0, 2, 0, 0, 2, 6, 4, 2, Indeterminate, 0, 0, 0, 2, 0, 0, 2, 6, 3, Indeterminate, 0,
0, 1, 0, 0, 4, 5, 0, 4, Indeterminate, 0, 0, 2, 2, 0, 2, 1, 2, 5, Indeterminate, 0,
0, 0, 0, 0, 0, 4, 4, 6, Indeterminate, 0, 0, 1, 2, 0, 4, 0, 6, 7, Indeterminate, 0,
0, 2, 0, 0, 2, 3, 0, 8, Indeterminate, 0, 0, 0, 2, 0, 0, 6, 2, 0, Indeterminate}
T = Cases[T, i_ /; i != "Indeterminate"]
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 4, 3, 2, 1, 0, 0, 2, 0, 0, 2, 6, 4, 2, 0, 0, 0, 2, 0,
0, 2, 6, 3, 0, 0, 1, 0, 0, 4, 5, 0, 4, 0, 0, 2, 2, 0, 2, 1, 2, 5, 0, 0, 0, 0, 0, 0, 4,
4, 6, 0, 0, 1, 2, 0, 4, 0, 6, 7, 0, 0, 2, 0, 0, 2, 3, 0, 8, 0, 0, 0, 2, 0, 0, 6, 2, 0}
Now we have a table that does not include the “indeterminates”.
Next, we will redefine p.
p[n0_] := Module{n = n0, T}, T = Table[Mod[k, IntegerDigits[k][[-1]]], {k, 1, n}];
T = Cases[T, i_ /; i != "Indeterminate"];
Count[T, 0] n
p[10000]
Mod::indet : Indeterminate expression Mod[10, 0] encountered.
Mod::indet : Indeterminate expression Mod[20, 0] encountered.
Mod::indet : Indeterminate expression Mod[30, 0] encountered.
General::stop : Further output of Mod::indet will be suppressed during this calculation.
4673
10000
This shows us how many numbers out of 10,000 are multiples of their units digit. This method seems to
work even though we still see “indeterminate”.
Here is the table p(n):
2 Week 4 Lab Report.nb
Printed by Wolfram Mathematica Student Edition
t1 = SessionTime[];
S = Table[{n, N[p[n]]}, {n, 1, 8000}];
p1 = ListPlot[S]
Print["This took ", SessionTime[] - t1, "seconds"]
Mod::indet : Indeterminate expression Mod[10, 0] encountered.
Mod::indet : Indeterminate expression Mod[10, 0] encountered.
Mod::indet : Indeterminate expression Mod[10, 0] encountered.
General::stop : Further output of Mod::indet will be suppressed during this calculation.
2000 4000 6000 8000
0.468
0.469
0.470
0.471
0.472
This took 82.1336638seconds
The higher the range, the longer it takes to compute. On the school’s computer, this took about 57
seconds, but here it took about 82 seconds.
Now, we want to average the values of p(n) and turn them into a graph.
fractions = S[[All, 2]];
fractions[[1 ;; 100]]
{1., 1., 1., 1., 1., 1., 1., 1., 1., 0.9, 0.909091, 0.916667, 0.846154, 0.785714,
0.8, 0.75, 0.705882, 0.666667, 0.631579, 0.6, 0.619048, 0.636364, 0.608696,
0.625, 0.64, 0.615385, 0.592593, 0.571429, 0.551724, 0.533333, 0.548387,
0.5625, 0.575758, 0.558824, 0.571429, 0.583333, 0.567568, 0.552632, 0.538462,
0.525, 0.536585, 0.547619, 0.534884, 0.545455, 0.555556, 0.543478, 0.531915,
0.541667, 0.530612, 0.52, 0.529412, 0.538462, 0.528302, 0.518519, 0.527273,
0.517857, 0.508772, 0.5, 0.491525, 0.483333, 0.491803, 0.5, 0.507937, 0.515625,
0.523077, 0.530303, 0.522388, 0.514706, 0.507246, 0.5, 0.507042, 0.513889,
0.506849, 0.5, 0.506667, 0.5, 0.506494, 0.5, 0.493671, 0.4875, 0.493827, 0.5,
0.493976, 0.5, 0.505882, 0.5, 0.494253, 0.5, 0.494382, 0.488889, 0.494505,
0.5, 0.505376, 0.5, 0.505263, 0.510417, 0.505155, 0.5, 0.505051, 0.5}
Week 4 Lab Report.nb 3
Printed by Wolfram Mathematica Student Edition
diningtable = Table[Mean[fractions[[1 ;; k]]], {k, 1, Length[fractions]}];
p2 = ListPlot[diningtable, PlotStyle → Red]
2000 4000 6000 8000
0.475
0.480
0.485
0.490
0.495
0.500
Show[{p1, p2}]
2000 4000 6000 8000
0.468
0.469
0.470
0.471
0.472
This doesn’t look right.
September 23, 2015We need to figure out why the last graph looks the way it does. Let’s try switching some things around.
4 Week 4 Lab Report.nb
Printed by Wolfram Mathematica Student Edition
Show[{p2, p1}]
2000 4000 6000 8000
0.475
0.480
0.485
0.490
0.495
0.500
Show[p1, p2]
2000 4000 6000 8000
0.468
0.469
0.470
0.471
0.472
We attempted to fix the graph by switching the order of p1 and p2, and then we tried taking away the
braces. Neither helped. Our guess is that p2 may be wrong because it has much higher values than p1.
We are assuming that p2 should be running through p1.
The graphs of p1 and p2 look like inverse log functions.
September 25, 2015We would like to find the equations for p1 and p2 and also find the limits of both of them. This all
depends on if the internet starts working in the next ten minutes.
For now, we are going to try and find a limiting function for p1 and p2. All numbers that end in 1, 2, or 5
will be divisible by the respective digit, half of numbers that end in 4 are divisible by 4, 1/3 of numbers
that end in 3 or 6 are divisible by their last digit, 1/4 of numbers ending in 8 are divisible by 8, 1/7 of
numbers ending in 7 are divisible by 7, and 1/9 of digits divisible by 9 are divisible by 9. We are going to
take the average of these values.
Week 4 Lab Report.nb 5
Printed by Wolfram Mathematica Student Edition
3 + .5 + 2 3 + .25 + 1 7 + 1 9 9
0.518959
This does not seem to match up with p1 or p2 which seem to have ranges lower down on the graph,
closer to 4.68.
We are still looking into how to find the equations of the graphs. We will try the fit function later on, we
just need to learn how to use it.
6 Week 4 Lab Report.nb
Printed by Wolfram Mathematica Student Edition