A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
I'm struggling with the sum of the logs problem in Problem Set 1. My ratio seems to approach 0, and very slowly. I'm not getting the output I expected from reading the problem.
anonymous
 5 years ago
I'm struggling with the sum of the logs problem in Problem Set 1. My ratio seems to approach 0, and very slowly. I'm not getting the output I expected from reading the problem.

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0from math import * n = 10 oddinteger = 3 checkdigit = 2 primecount = 1 primelogsum = log(2) while n < 10000: while primecount < n: if oddinteger%checkdigit == 0: oddinteger += 2 checkdigit = 2 elif oddinteger%checkdigit != 0 and checkdigit*2 < oddinteger: checkdigit += 1 else: primecount += 1 primelogsum += log(oddinteger) oddinteger += 2 checkdigit = 2 print "Sum of the logs of the primes: " + str(primelogsum) print "n: " + str(n) print "Ratio of sum of the logs of the primes to the value n: " + str(float(primelogsum)/float(n)) print "" primelogsum = log(2) n += 10

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0what does n represent and what is it meant to be doing?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Well, I'm a moron. I was operating under the assumption that: as n increases  primelogsum approaches 1. when it now seems that I need to keep taking the sum of the logs each time I get a new prime number, and that ratio will approach 1.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0while leaving n as a constant

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0actually now that I read it again, I think I was right  n is supposed to increase with each iteration. I set it to some value, then add up all the logs of prime numbers up to n, divide that result by n, and then increase n and have another iteration.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Are you actually adding up ALL the logs? Why does primelogsum keep getting reset to log(2)?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I'm doing that each time the while primecount < n condition becomes false, which begs the question, why do I care whether my primecount is < n? I should be checking my oddinteger that is being tested for primeness against n.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0... and we're approaching 1 on a squiggly line :)
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.