看板 Fortran 關於我們 聯絡資訊
program Err implicit none integer(4) :: i,j,k,iNum real(4) :: x,rTemp,dx !real(8) :: x,rTemp,dx iNum = 25 x = 1.0 do i=1,iNum rTemp = sqrt(x) x = (tan(atan(exp(log(rTemp*rTemp))))) + 1.0 dx = abs(x - float(iNum + 1)) write(*,*) dx end do ! real(4) , Final dx = 3.8146973E-06 ! real(8) , Final dx = 1.776356839400250E-014 stop end : 以下的 C語言程式設計, : double 就是 fortran 的 real*8, : 經過 25次的 複雜運算,產生的 : 絕對誤差如下 : 謹 提供參考 : #if 0 : dx= 5.684342e-014 : 請按任意鍵繼續 . . . : #endif : // ---------------------------------------------- : #include <stdio.h> : #include <math.h> : #include <process.h> : // ---------------------------------------------- : template <class T> : T sqr(T x) : { : return(x*x); : }// end of sqr() : // ---------------------------------------------- : void main() : { : int no, i; : double x, dx; : no= 25; : x= 1.0; : for (i=1;i<=no;i++) { : x= (tan(atan(exp(log(sqr(sqrt(x))))))) + 1.0; : } : dx= fabs(x - (no + 1)); : printf("\n dx= %.6le\n", dx); : system("pause"); : }// end of main() -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.60.193