A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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.

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    from 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

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what does n represent and what is it meant to be doing?

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Well, 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.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    while leaving n as a constant

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    actually 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.

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Are you actually adding up ALL the logs? Why does primelogsum keep getting reset to log(2)?

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'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.

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ... and we're approaching 1 on a squiggly line :-)

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    cool!

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the help!

  11. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.