2 shunfurh shunfurh 于 2017.01.14 22:39 提问

Numerical Integration

Description

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?

Input

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:

Token Meaning Example Example in Mathematical Form

  • addition, positive x+1, +x x + 1, +x
  • subtraction, negative x-1, -x x − 1, −x
  • multiplication x*x x · x / division x/2 x⁄2 ^ power x^-x x−x ( left parenthesis (x+1)*x (x + 1) x ) right parenthesis -(x+1) −(x + 1) sin sine sin(x) sin x cos cosine cos(x) cos x tan tangent tan(x) tan x log natural logarithm log(x) ln x exp exponential exp(x) ex asin inverse sine asin(x) arcsin x acos inverse cosine acos(x) arccos x atan inverse tangent atan(x) arctan x abs absolute value abs(x) |x| x variable x x constant C floating-point constants without suffixes 0, 1.5 0, 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.

Output

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

Sample Input

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
Sample Output

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个回答

dabocaiqq
dabocaiqq   2017.01.21 22:56
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Numerical Integration
word 文档,包含常用的各种数值积分,以及相关的参考文献。可以作为快速学习的资料
最全的Matlab工具箱免费分享
最全的Matlab工具箱免费分享(2009-09-24 15:35:08)标签:资源下载   Gerald Recktenwald 《Numerical Methods with MATLAB》(NMM1.5数值分析工具箱) http://www.matlabsky.com/thread-325-1-1.htmlDahua L
AMD Cubemapgen for physically based rendering
JUNE 10, 2012 57 COMMENTS Version : 1.67 – Living blog – First version was 4 September 2011 AMD Cubemapgen is a useful tool which allow cubemap filtering and mipchain generation. Sadly, AMD
Numerical Analysis - Integration - Basics
Numerical Integration 数值积分的代数精度
Numerical Recipe中文版
Numerical Recipe是关于数值计算的经典之作。这是它的中文版,供有志于此的同道参考。
Numerical Computing with MATLAB.PDF
matlab数值计算的经典书籍.带有源码的.下次上传
Numerical Analysis - 9th - (Burden & Faires)
Numerical Analysis - 9th - (Burden & Faires)
数值优化(Numerical Optimization)学习系列-目录
概述 数值优化对于最优化问题提供了一种迭代算法思路,通过迭代逐渐接近最优解,分别对无约束最优化问题和带约束最优化问题进行求解。 该系列教程可以参考的资料有 1. 《Numerical Optimization 2nd》–Jorge Nocedal Stephen J. Wright 2. 《凸优化》–Stephen Boyd 3. 《非线性最优化基础》–Masao Fukushima
Numerical recipes in Fortran 77 & 90
numerical recipes in Fortran 经典图书源代码. 虽然Eigen之类的库横空出世之后, Numerical recipes in C++变得不再那么抢手,不过Fortran版的类似内容还是这个经典.
numerical analysis 9th edition
numerical analysis 9 th edition !