@@ -22,9 +22,9 @@ double asr1(double a, double b, double eps, double A,int flag);
2222
2323
2424
25- double pow1 (double a ,int n )//实数的整数次幂,快速幂
25+ double pow1 (double a ,int n )
2626{
27- if (n < 0 ) return 1 /pow1 (a ,- n );//n为负时的处理
27+ if (n < 0 ) return 1 /pow1 (a ,- n );
2828 double res = 1.0 ;
2929 while (n )
3030 {
@@ -36,17 +36,17 @@ double asr1(double a, double b, double eps, double A,int flag);
3636}
3737
3838
39- double F11 (double x )//为了使用定积分计算lnx
39+ double F11 (double x )
4040{
4141 return 1 /x ;
4242}
4343
44- double F21 (double x )//为了使用定积分计算arcsinx
44+ double F21 (double x )
4545{
4646 return 1 /sqrt1 (1 - x * x );
4747}
4848
49- double simpson1 (double a , double b ,int flag )//辛普森积分公式
49+ double simpson1 (double a , double b ,int flag )
5050{
5151 double c = a + (b - a )/2 ;
5252 if (flag == 1 )
@@ -55,15 +55,15 @@ double asr1(double a, double b, double eps, double A,int flag);
5555 return (F21 (a )+ 4 * F21 (c )+ F21 (b ))* (b - a )/6 ;
5656}
5757
58- double asr1 (double a , double b , double eps , double A ,int flag )//辛普森积分公式的自适应过程
58+ double asr1 (double a , double b , double eps , double A ,int flag )
5959{
6060 double c = a + (b - a )/2 ;
6161 double L = simpson1 (a , c ,flag ), R = simpson1 (c , b ,flag );
6262 if (fabs (L + R - A ) <= 15 * eps ) return L + R + (L + R - A )/15.0 ;
6363 return asr1 (a , c , eps /2 , L ,flag ) + asr1 (c , b , eps /2 , R ,flag );
6464}
6565
66- double asr11 (double a , double b , double eps ,int flag )//辛普森积分主体函数
66+ double asr11 (double a , double b , double eps ,int flag )
6767{
6868 return asr1 (a , b , eps , simpson1 (a , b ,flag ),flag );
6969}
@@ -88,9 +88,9 @@ double sin1(double x)
8888 {
8989 x *=-1 ;
9090 fl *=-1 ;
91- }//处理区间
91+ }//处理区间
9292 if (x > PI /4 ) return cos1 (PI /2 - x );
93- else return fl * (x - pow1 (x ,3 )/6 + pow1 (x ,5 )/120 - pow1 (x ,7 )/5040 + pow1 (x ,9 )/362880 );//泰勒公式
93+ else return fl * (x - pow1 (x ,3 )/6 + pow1 (x ,5 )/120 - pow1 (x ,7 )/5040 + pow1 (x ,9 )/362880 );
9494}
9595
9696double cos1 (double x )
@@ -108,49 +108,49 @@ double cos1(double x)
108108 {
109109 x += PI ;
110110 fl *= -1 ;
111- }//处理区间
111+ }
112112 if (x > PI /4 ) return sin1 (PI /2 - x );
113- else return fl * (1 - pow1 (x ,2 )/2 + pow1 (x ,4 )/24 - pow1 (x ,6 )/720 + pow1 (x ,8 )/40320 );//泰勒公式
113+ else return fl * (1 - pow1 (x ,2 )/2 + pow1 (x ,4 )/24 - pow1 (x ,6 )/720 + pow1 (x ,8 )/40320 );
114114}
115115
116116double tan1 (double x )
117117{
118118 if (x > PI || x < - PI ) x -= (int )(x /(PI ))* PI ;
119119 if (x > PI /2 ) x -= PI ;
120- if (x < - PI /2 ) x += PI ;//处理区间
121- return x + pow1 (x ,3 )/3 + pow1 (x ,5 )* 2 /15 + pow1 (x ,7 )* 17 /315 + pow1 (x ,9 )* 62 /2835 ;//泰勒公式
120+ if (x < - PI /2 ) x += PI ;
121+ return x + pow1 (x ,3 )/3 + pow1 (x ,5 )* 2 /15 + pow1 (x ,7 )* 17 /315 + pow1 (x ,9 )* 62 /2835 ;
122122}
123123
124124double asin1 (double x )
125125{
126126 if (fabs (x )> 1 ) return -1 ;
127127 double fl = 1.0 ;
128128 if (x < 0 ) {fl *=-1 ;x *=-1 ;}
129- if (fabs (x - 1 )< 1e-7 ) return PI /2 ;//x为正负1时特判
130- return (fl * asr11 (0 ,x ,1e-8 ,2 ));//主体积分过程
129+ if (fabs (x - 1 )< 1e-7 ) return PI /2 ;
130+ return (fl * asr11 (0 ,x ,1e-8 ,2 ));
131131 //return x + pow(x,3)/6 + pow(x,5)*3/40 +pow(x,7)*5/112 + pow(x,9)*35/1152 + pow(x,11)*315/1408;
132132}
133133
134134double acos1 (double x )
135135{
136136 if (fabs (x )> 1 ) return -1 ;
137- return PI /2 - asin1 (x );//简单公式的应用
137+ return PI /2 - asin1 (x );
138138}
139139
140140double atan1 (double x )
141141{
142142 if (x < 0 ) return - atan1 (- x );
143143 if (x > 1 ) return PI /2 - atan1 (1 /x );
144- if (x > 1e-3 ) return 2 * atan1 ((sqrt1 (1 + x * x )- 1 )/x );//递推地缩小自变量,使之接近0,保证泰勒公式的精度
145- return x - pow1 (x ,3 )/3 + pow1 (x ,5 )/5 - pow1 (x ,7 )/7 + pow1 (x ,9 )/9 ;//泰勒公式
144+ if (x > 1e-3 ) return 2 * atan1 ((sqrt1 (1 + x * x )- 1 )/x );
145+ return x - pow1 (x ,3 )/3 + pow1 (x ,5 )/5 - pow1 (x ,7 )/7 + pow1 (x ,9 )/9 ;
146146}
147147
148148
149149double sqrt1 (double x )
150150{
151- if (x > 100 ) return 10.0 * sqrt1 (x /100 );//缩小自变量值
152- double t = x /8 + 0.5 + 2 * x /(4 + x );//迭代两次之后的结果
153- int c = 10 ;//迭代十次
151+ if (x > 100 ) return 10.0 * sqrt1 (x /100 );
152+ double t = x /8 + 0.5 + 2 * x /(4 + x );
153+ int c = 10 ;
154154 while (c -- )
155155 {
156156 t = (t + x /t )/2 ;
0 commit comments