当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3161:Numerical Integration

题目描述

In his freshman year, flymouse studied integral. Symbolic integration frustrated him a lot. He was often confused by those subtle techniques: alternately trying integration by substitution and integration by parts until the integrand appears in a tabulated form then employing integration by quadrature to have the work finally done. In contrast, numerical integration intrigued him much. By following some fixed procedures such as Newton-Cotes formulas, he could easily find the approximation to some definite integrals without too much effort. Given the exercises flymouse did, can your program do as nice a job as flymouse did?

输入解释

The input contains several test cases. Each test case consists of one line containing a univariate function f(x) and two real numbers a and b meaning the approximate value of is to be found. f(x) is expressed as a C-expression-like string. Allowed tokens are summarized in the following table:

TokenMeaningExampleExample in Mathematical Form
+addition, positivex+1, +xx + 1, +x
-subtraction, negativex-1, -xx − 1, −x
*multiplicationx*xx · x
/divisionx/2x2
^powerx^-xx−x
(left parenthesis(x+1)*x(x + 1) x
)right parenthesis-(x+1)−(x + 1)
sinsinesin(x)sin x
coscosinecos(x)cos x
tantangenttan(x)tan x
lognatural logarithmlog(x)ln x
expexponentialexp(x)ex
asininverse sineasin(x)arcsin x
acosinverse cosineacos(x)arccos x
ataninverse tangentatan(x)arctan x
absabsolute valueabs(x)|x|
xvariablexx
constantC floating-point constants without suffixes0, 1.50, 1.5

And the syntax is given below:

S::=+S | -S | S+S | S-S | S*S | S/S | S^S | F(S) | (S) | x | constant
F::=sin | cos | tan | log | exp | asin | acos | atan

Operator precedence and associativity are almost the same as those in C except that ‘^’ takes higher precedence than ‘*’ and ‘/’ and has right associativity.

f(x) is not necessarily continuous. It can have singularities which are always isolated if exist. It can be oscillatory, but it will never be oscillatory in the neighborhood of singularities where it blows up. The integral is guaranteed to converge.

Length of the interval over which f(x) is integrated is not longer than 10.

Process to end of file.

输出解释

For each test case, output one line with only the approximate value of the integral rounded to exactly four digits past the decimal point.

输入样例
x+1 0 1
+x 0 1
x-1 0 1
-x 0 1
x*x 0 1
x/2 0 1
x^-x 0 1
(x+1)*x 0 1
-(x+1) 0 1
sin(x) 0 1
cos(x) 0 1
tan(x) 0 1
log(x) 1 2
exp(x) 0 1
asin(x) 0 1
acos(x) 0 1
atan(x) 0 1
abs(x) 0 1
x 0 1
1 0 1
sin(x)/x 0 1
输出样例
1.5000
0.5000
-0.5000
-0.5000
0.3333
0.2500
1.2913
0.8333
-1.5000
0.4597
0.8415
0.6156
0.3863
1.7183
0.5708
1.0000
0.4388
0.5000
0.5000
1.0000
0.9461
提示
  1. Be cautious about outputting ‘-0.0000’.
  2. Make your integration module as robust as possible.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3161

最后修改于 2020-10-29T06:54:35+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 131072