근의공식 에 해당하는 글1 개
2008.11.21   근의 공식에서 100000(10만)이상의 숫자에 대해서 오차 줄이기


근의 공식에서 100000(10만)이상의 숫자에 대해서 오차 줄이기
日新又日新 | 2008. 11. 21. 20:54

귀찮구나. 그냥 카피앤페이스트.

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
   
IDLE 1.2.2     
>>> (pow(10,5)+2)*(pow(10,5)-2)
9999999996L
>>> pow(10,10)-4
9999999996L #인수분해한 식과 전개한 식의 값은 같음을 확인.
>>> import math
>>> math.sqrt(pow(10,10)-4)
99999.999979999993
>>> math.sqrt((pow(10,5)+2))*math.sqrt((pow(10,5)-2))
99999.999979999993  #루트를 씌운 상태에서도 마찬가지임을 확인
>>> math.sqrt((pow(10,5)+2))
316.23092827868686
>>> math.sqrt((pow(10,5)-2))
316.22460372336622
>>> t = pow(10,10)-4
>>> t
9999999996L
>>> roott = math.sqrt(t)
>>> roott
99999.999979999993
>>> (pow(10,5)-roott)/2 #대상 수식은 x^{2} - 10^{5}x+1 = 0 이었음.
1.0000003385357559e-005 #실제 작은 값의 근은 0.00001, 0.0000003385357559 의 양의 오차가 있다.
>>> (pow(10,5)+roott)/2
99999.999989999997 #실제 답은 99999.9998, 큰 값의 근에 대해서 0.000009999997 의 양의 오차가 있다.
>>> (pow(10,5)*roott - t)/(2*roott)  #root(b^2-4ac) 부분을 분모분자에 곱해준다.
1.0000000002000001e-005  #오차가 줄어든 것을 확인할 수 있다. 작은 값의 근에 대해서 0.0000000002000001 로 줄어들었다. 0.0000003383357558 만큼이 줄어들었다.
>>> (pow(10,5)*roott + t)/(2*roott)
99999.999990000011 #두 근 중 큰 값에 대해서도 오차가 0.000000000011 로 줄어들었다. 0.000009999986 만큼의 오차를 줄인 셈이다.
>>>


 
 
 
트랙백 | 댓글



위치로그 : 태그 : 방명록 : 관리자
이우성's Blog is powered by Daum / Designed by SSen
관리자  |  글쓰기
BLOG main image
전, 이우성입니다. ( I am Woosung, Lee. ) ""
 Category
 Media
 TAGS
 Recent Entries
 Recent Comments
 Calendar
 Archive
 Link Site
 Visitor Statistics
+ Total :
+ Today :
+ Yesterday :
카피
rss