请求解下面的积分并输出答案:
∫ a b s i n x x d x \int _a^b \frac{sinx}{x}dx ∫abxsinxdx
输入
多组输入。
每一个样例包含两个正整数 a,b (0<a<=b<=10)
输出
每一个样例输出一个整形,即积分的答案乘以10000。(精度为 1e-5 ,每次取左端点)
样例输入
1 1
1 2
2 8
样例输出
0
6593
-312
解题思路:
由于
∫
a
b
s
i
n
x
x
d
x
\int _a^b \frac{sinx}{x}dx
∫abxsinxdx的不定积分无法用初等函数求出。
于是我们可以想到泰勒公式
s
i
n
x
=
x
−
x
3
3
!
+
x
5
5
!
+
(
−
1
)
n
x
2
n
+
1
(
2
n
+
1
)
!
+
o
(
x
2
n
+
1
)
sinx=x-\frac {x^3}{3!}+\frac{x^5}{5!}+(-1)^{n}\frac{x^{2n+1}}{(2n+1)!}+o(x^{2n+1})
sinx=x−3!x3+5!x5+(−1)n(2n+1)!x2n+1+o(x2n+1)
从而得到
s
i
n
x
x
=
1
−
x
2
3
!
+
x
4
5
!
+
(
−
1
)
n
x
2
n
(
2
n
+
1
)
!
+
o
(
x
2
n
)
\frac{sinx}{x}=1-\frac {x^2}{3!}+\frac{x^4}{5!}+(-1)^{n}\frac{x^{2n}}{(2n+1)!}+o(x^{2n})
xsinx=1−3!x2+5!x4+(−1)n(2n+1)!x2n+o(x2n)
对其积分
∫
s
i
n
x
x
d
x
=
x
−
x
3
3
!
×
3
+
x
5
5
!
×
5
+
(
−
1
)
n
x
2
n
+
1
(
2
n
+
1
)
!
×
5
+
o
(
x
2
n
+
1
)
\int \frac{sinx}{x}dx=x-\frac {x^3}{3!\times3}+\frac{x^5}{5!\times5}+(-1)^{n}\frac{x^{2n+1}}{(2n+1)!\times5}+o(x^{2n+1})
∫xsinxdx=x−3!×3x3+5!×5x5+(−1)n(2n+1)!×5x2n+1+o(x2n+1)
于是我们便可在
1
e
−
5
1e^{-5}
1e−5的精度要求下求出定积分
∫
a
b
s
i
n
x
x
d
x
\int_{a}^{b} \frac{sinx}{x}dx
∫abxsinxdx
代码实现:
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-5;
double fun(double x){
double t=x,ans=x;
int n=1;
while(fabs(t)>=eps){ //精度要求
t=(-t*x*x)/((n+1)*(n+2));
ans+=t/(n+2);
n+=2;
}
return ans;
}
int main(){
double a,b;
while(~scanf("%lf%lf",&a,&b)){
double r1=fun(a),r2=fun(b); //F(b)-F(a)
printf("%d\n",(int)((r2-r1)*10000));
}
return 0;
}