Mathematica Code Watch

silent ninja
Badges: 19
Rep:
?
#1
Report Thread starter 10 years ago
#1
How would you write the code for finding n such that the Harmonic Series is greater than 10? i.e  \displaystyle\sum_{k=1}^{n}\frac  {1}{k} >10

I've got 2^17 from fiddling with inequalities, which obviously works, but it's well above 10 at around 12.36 (since I discarded so many fractions).

So any idea? Tried it with 'Solve' but that won't work.
Just curious and I do need to improve my usage of this program!

Thanks

Edit: The answer is n>=12367 on Wolfram.
0
reply
James
Badges: 14
Rep:
?
#2
Report 10 years ago
#2
Try solving with equality (because computer algebra packages use methods which makes that okay).

Not sure about Mathematica, but in Maple you would write:

evalf(solve(sum(1/k, k=1..n)=10, n));

12366.46811

So clearly the solution is n\geq 12367.
0
reply
silent ninja
Badges: 19
Rep:
?
#3
Report Thread starter 10 years ago
#3
(Original post by James)
Try solving with equality (because computer algebra packages use methods which makes that okay).

Not sure about Mathematica, but in Maple you would write:

evalf(solve(sum(1/k, k=1..n)=10, n));

12366.46811

So clearly the solution is n\geq 12367.
Tried it a few different ways on Mathematica (including with the equality), it doesn't seem to work. Ah well, thanks anyway.
0
reply
nota bene
Badges: 13
Rep:
?
#4
Report 10 years ago
#4
Code:
sum = 0;
n = 0;
While[sum < 10, {n = n + 1, sum = sum + 1/n}]
n
sum // N
This should render the answer.
0
reply
silent ninja
Badges: 19
Rep:
?
#5
Report Thread starter 10 years ago
#5
(Original post by nota bene)
Code:
sum = 0;
n = 0;
While[sum < 10, {n = n + 1, sum = sum + 1/n}]
n
sum // N
This should render the answer.
Neat.
I need to learn how to program on mathematica. The 'While' and 'Do' commands were introduced this week, i'm hopeless...
Thanks
0
reply
nota bene
Badges: 13
Rep:
?
#6
Report 10 years ago
#6
(Original post by silent ninja)
I need to learn how to program on mathematica. The 'While' and 'Do' commands were introduced this week, i'm hopeless...
Same here - I had to ask a friend how to do when I had two bodies to run the test on, but apparently it was just to put it in as a table; that's why it took me nearly a week to reply:p:
0
reply
silent ninja
Badges: 19
Rep:
?
#7
Report Thread starter 10 years ago
#7
(Original post by nota bene)
Same here - I had to ask a friend how to do when I had two bodies to run the test on, but apparently it was just to put it in as a table; that's why it took me nearly a week to reply:p:
Glad you remembered to post back then! :p:

Not looking forward to my mathematica project over the holidays :no: I hope you are still around!
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • University of the Arts London
    MA Performance Design and Practice Open Day Postgraduate
    Thu, 24 Jan '19
  • Brunel University London
    Undergraduate Experience Days Undergraduate
    Sat, 26 Jan '19
  • SOAS University of London
    Postgraduate Open Day Postgraduate
    Sat, 26 Jan '19

Are you chained to your phone?

Yes (75)
19.43%
Yes, but I'm trying to cut back (156)
40.41%
Nope, not that interesting (155)
40.16%

Watched Threads

View All