Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2019-09-18 17:36:21

Hannibal lecter
Member
Registered: 2016-02-11
Posts: 392

Calculate pi?

The value of p can be computed according to the following formula: π/4 = 1 - 1/3 + 1/5 -1/7 + 1/9 -
as a photo :-

2019-09-19-083350.jpg
traffic ticket guru


Write an algorithm to compute pi . Because the formula is an infinite series and an algorithm must stop after a finite number of steps, you should stop when you have the result determined to six significant dig its


how to write the algorithm if I don't know how to calculate pi?!
I just learned in collage that pi is = 3.14159265359 and they just told as to save that number in our minds
I didn't learned anything about it
and what does he mean by calculate pi!?
as well as I don't know what is the formula from where did he get these numbers like 1/3 or 1/9 ...

so if I don't know these things I can't write an algorithm to solve the problem

Last edited by Hannibal lecter (2019-09-18 17:37:41)


Wisdom is a tree which grows in the heart and fruits on the tongue

Offline

#2 2019-09-18 20:04:39

Bob
Administrator
Registered: 2010-06-20
Posts: 10,052

Re: Calculate pi?

As you know the digits for pi start 3.141...…

Mathematicians have proved that there is no end to the digits; they go on for ever.  Further they never recur like the digits of 1/7 = o.142857142857...…

There are a number of sequences that will allow you to calculate pi.  As the digits go on for ever, no calculation will ever be complete but, if the calculation gradually leads towards a more and more accurate value, then it can be used and once you have sufficient accuracy you can stop the calculation.

That's the idea here.  Start doing this calculation, checking to see if the next answer is the same as the previous one for the first 6 digits, then stop.

As this sequence calculates pi/4 , you would finally have to multiply the answer by 4 to get pi itself.

Where did the sequence come from?  There is a lot of advanced maths needed to answer that question.  At this stage I think you should just trust that it works.  I seem to remember that it only slowly gives the correct digits so you would need a lot of steps.

The fractions are all like this:  1 /  [an odd number]

So you'll need to keep track of [an odd number] and increase it by 2 for each step.  And terms are first  subtracted then added, then subtracted, then added …. so you'll need to keep track of which sign + or - is needed for the next term.

Keep a record of the answer obtained at a step and also the next answer.  When [next answer] - [answer] < 0.0000001 you are not getting any closer to the 6 digits so you can stop.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#3 2019-09-18 23:11:36

Hannibal lecter
Member
Registered: 2016-02-11
Posts: 392

Re: Calculate pi?

but what is the meaning of that  0.0000001

what is this? I see that number or similar in most books specially books about probability
it called tolerance number or  accuracy number or something like that


this condition  <   0.0000001 is driving me crazy
why smaller than? and why this number with these zeros


Wisdom is a tree which grows in the heart and fruits on the tongue

Offline

#4 2019-09-19 00:43:44

Bob
Administrator
Registered: 2010-06-20
Posts: 10,052

Re: Calculate pi?

I have used Microsoft Excel to create the calculations needed.

0iOh8A3.gif

The formula view on the right shows how it works.

The first column (D) just alternates between -1 and +1 so that I can subtract and then add successive terms.

The second column (E) just counts the number of terms so far.

The third column (F) shows the odd numbers needed for the calculation

The fourth column (G) does the calculation.  The previous total has 1/[an odd number] either subtracted or added.  This is achieved by multiplying by the D column number which is either -1 or +1

Finally, in the fifth column (H) the fourth column number is multiplied by 4 to give the calculated value for pi.

This last column shows just how slow the process is.  Even at the 19th row we only have 3.19....    It takes a lot more rows to make progress.

I have jumped to show rows 262 and 263.  At last we are getting 3.14 but still not very accurate.

If you subtract the row 262 value from the row 263 value you get 0.0076....

The question asks for 6 significant digits.  That means don't stop until we see 3.14159.  If a row shows this, and the next one as well, then subtracting one from the other would give 0.00000.....  I cannot say for certain that all the digits would be zeros because the displayed numbers will have been rounded off.  By testing when this difference is smaller than 0.0000001 we can be certain we have 6 significant figures.

It may be we could have stopped sooner, but the step of multiplying by 4 means any small difference  is multiplied.  Also the figures oscillate either side of the correct value so I 'played safe' by choosing this level of test.

If the test was to stop when the difference is < 0.01 then row 263 would be the moment when the algorithm stops.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

Board footer

Powered by FluxBB