Strange Result Calculating pi.

  • Thread starter quasi426
  • Start date
  • Tags
    Pi Strange
In summary, the conversation discusses the use of MATLAB to numerically calculate pi using a for loop. The speaker mentions that when the interval is too small, they get absurd quantities for pi, and when the interval is too large, they get errors. They speculate that this may be due to running out of machine precision, as MATLAB does not use arbitrary-precision arithmetic by default. The more terms used to increase accuracy, the more calculations are needed and the errors tend to accumulate.
  • #1
quasi426
208
0
I decided to numerically calculated pi using MATLAb and running a for loop. When I make the steps too small I get absurd quantities for pi. Here see for yourself. When I make the interval higher then about 1e10 i get errors, but 1e6 works ok. Why would this be? Thanks

<code>


clc
clear all

interval = 1e11;
pi_calculated = 0;

for i = -1: 2/interval :1
pi_calculated = sqrt(1-i^2)*2/interval + pi_calculated;
end

format long
pi_calculated = 2*pi_calculated


<code>
 
Physics news on Phys.org
  • #2
You may be running out of machine precision. MATLAB doesn't use arbitrary-precision arithmetic.

- Warren
 
  • #3
I'm not certain I know what machine precision is?
 
  • #4
If MATLAB is using, e.g. IEEE standard double-precision floating point numbers, which are 64 bits wide, they cannot contain arbitrarily small nor arbitrarily large numbers. If you try to use a very, very, very small number, it will be rounded off, because the machine (computer) does not have the ability to represent it.

Other systems (like Mathematica) are capable of arbitrary-precision arithmetic by default; MATLAB may or may not support arbitrary-precision arithmetic, but I'm pretty certain it is not enabled by default.

- Warren
 
  • #5
Nothing surprising about it. The more terms you use in order to increase accuracy, the more calculations you need to do and the errors tend to accumulate- especially from round off error.
 

1. What is "Strange Result Calculating pi"?

"Strange Result Calculating pi" is a term used to describe a phenomenon where the calculation of the mathematical constant pi (π) produces unexpected or unusual results.

2. Why does this phenomenon occur?

This phenomenon occurs due to the inherent complexity of pi. Pi is an irrational number, meaning it cannot be expressed as a simple fraction, and its digits continue infinitely without repeating in a pattern. As a result, there may be unexpected patterns or coincidences when calculating pi.

3. Is this phenomenon common?

No, this phenomenon is not common. Pi is a well-studied mathematical constant and most calculations of pi will produce expected results. However, due to its complexity, there may be rare instances where strange results occur.

4. How is pi calculated?

Pi is typically calculated using various mathematical formulas, such as the Leibniz formula or the Chudnovsky algorithm. These formulas involve infinite series or sums that approximate the value of pi to a certain number of digits.

5. What are some examples of "Strange Result Calculating pi"?

Some examples of "Strange Result Calculating pi" include the "Pi is Wrong" phenomenon where the digits of pi seem to align with the digits of the date, and the "Pi Day Problem" where the first 10 digits of pi (3.141592653) appear in the date and time on March 14th at 1:59 PM. These are considered coincidences and do not affect the actual value of pi.

Similar threads

Replies
4
Views
351
Replies
1
Views
937
Replies
5
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
287
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
Replies
14
Views
1K
  • General Math
Replies
1
Views
750
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Calculus
Replies
11
Views
2K
Back
Top