2017-05-12 2 views
0

을 찾는 제곱근의 증명을 부여?누군가가 C++에서 양수</em>의 제곱근을 찾을 <em>다음 코드의 <strong>수학적 정확성</strong>를 설명 할 수 알고리즘

enter image description here

하고 Wikipedia에서 컨버전스의에 대해 읽을 수 있습니다

#include <iostream> 
#include <cmath> 

using namespace std; 

int main(){ 
    float a; cin>>a; 
    cout<<"Answer by Math library\n"<<sqrt(a)<<"\n"; 

    //the following is the code for finding the square root of a positive double 

    double g=a; 

    while(abs(g*g-a)>1e-8){ 
     g= (g+(a/g))/2; 
    } 

    cout<<"Answer by this algorithm\n"<<g<<"\n"; 

    return 0; 
} 
+0

https://math.stackexchange.com/ – AlexG

+0

에 적합한 문제인 것처럼 보입니다.이 질문은 주로 수학 문제이기 때문에이 질문을 주제로 끝내기로했습니다. [수학 SE] (https://math.stackexchange.com/). – You

+1

이 질문은 C++ 코드에서 주어진 [math.se]에 대해서는 적절하지 않을 수 있습니다. 첫 번째 단계는 언어를 더 모르는 형태로 변환하는 것입니다. – Dukeling

답변

1

이 (뉴턴의 방법에서 유래) 바빌로니아의 방법이라고 제곱근을 계산하는 대략적인 알고리즘입니다.

관련 문제