計算PI -- 采用劉徽的割圓術方法


PI

https://www.mathsisfun.com/numbers/pi.html

 

 

 

Draw a circle with a diameter (all the way across the circle) of 1

Then the circumference (all the way around the circle) is 3.14159265... a number known as Pi

 

Pi (pronounced like "pie") is often written using the greek symbol π

circumference, diameter, radius

The definition of π is:

The Circumference
divided by the Diameter
of a Circle.

The circumference divided by the diameter of a circle is always π, no matter how large or small the circle is!

pi circle diameter

 

To help you remember what π is ... just draw this diagram.

Finding Pi Yourself

Draw a circle, or use something circular like a plate.

Measure around the edge (the circumference):

plate circumference 82
I got 82 cm

Measure across the circle (the diameter):

plate diameter
I got 26 cm

Divide:

82 cm / 26 cm = 3.1538...

That is pretty close to π. Maybe if I measured more accurately?

 

割圓術

https://www.zhihu.com/question/342855331

作者:大的要來了
鏈接:https://www.zhihu.com/question/342855331/answer/2032705657
來源:知乎
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。

圓周率(Pi)是圓的周長與直徑的比值,一般用希臘字母π表示,是一個在數學及物理學中普遍存在的數學常數。

在古代通常是采用割圓術計算π值。

所謂“割圓術”,是用圓內接正多邊形的面積去無限逼近圓面積並以此求取圓周率的方法。“圓,一中同長也”。意思是說:平面內到定點的距離等於定長的點的集合。早在我國先秦時期,《墨經》上就已經給出了圓的這個定義,而公元前11世紀,我國西周時期數學家商高也曾與周公討論過圓與方的關系。認識了圓,人們也就開始了有關於圓的種種計算,特別是計算圓的面積。我國古代數學經典《九章算術》在第一章“方田”章中寫到“半周半徑相乘得積步”,也就是我們現在所熟悉的公式。

 

 

內割法公式推導

 

內割法代碼實現

https://github.com/fanqingsong/code_snippet/blob/master/CPP/calc_pi.cpp

#include <iostream>
#include <cmath>

using namespace std;

double getEdgeLen(int cutnum) {
    int halfCutnum = cutnum / 2;
    double edgeLen = 0;
    double halfEdgeLen = 0;

    if (cutnum == 6) {
        return 1;
    }

    halfEdgeLen = getEdgeLen(halfCutnum);
    edgeLen = sqrt(2 - sqrt(4 - pow(halfEdgeLen, 2)));

    return edgeLen;
}

bool checkCutnum(int cutnum) {
    if (cutnum < 6) {
        cout << "cutnum is a positive integer greater than and equal to 6, please correct." << endl;
        return false;
    }

    if (cutnum % 6 != 0) {
        cout << "cutnum must be times 6, please correct." << endl;
        return false;
    }

    while (true) {
        if (cutnum % 2 == 0) {
            cutnum /= 2;
            continue;
        }

        if (cutnum != 3) {
            cout << "cutnum must be 2 power times 6." << endl;
            return false;
        }
    }

    return true;
}

int main() {
    int cutnum = 0;
    double edgeLen = 0;
    double quasiPerimeter = 0;
    double quasiPI = 0;

    //printf("hello world\r\n");

    cout << "please input cutnum for cutting circle, like 6, 12, 24, 48, ..." << endl;

    cin >> cutnum;

    cout << "cutnum is " << cutnum << endl;

    if (!checkCutnum(cutnum)) {
        return 0;
    }

    edgeLen = getEdgeLen(cutnum);

    quasiPerimeter = cutnum * edgeLen;

    quasiPI = quasiPerimeter / 2;

    cout << "the quasi PI is " << quasiPI << endl;

    return 0;
}

 

 

 

 

開方手動計算方法

https://www.zhihu.com/question/347197295/answer/832181439

作者:曹力科
鏈接:https://www.zhihu.com/question/347197295/answer/832181439
來源:知乎
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。

那么如何在沒有計算器的時候徒手開平方呢?

現代有一種方法的原理是這樣的。

[公式]

以求3的平方根為例子,方法如下:

一時沒看懂沒關系,可以收藏以后慢慢看。

好了,如果你能看到這里,那么恭喜你,你也可以像祖沖之一樣,徒手去算圓周率了。

穿越回到那個時代,別忘了要一個大廣場,再加連起來可以繞地球一圈的算籌。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM