1228 Integral
Description
An integral is an abstract mathematical concept representing the area underneath the curve of a function. In theory, the concept bases itself on the fact that you can make an approximation of the area underneath the curve by dividing the area under the curve into sections, fitting a rectangle to the space under the curve, and summing the combined area of the simple rectangles. By creating more rectangles of smaller width, one can gain a better approximation of the area. By running the width of the rectangles as close to zero as possible, or taking the limit as the width approaches zero, our result is the exactly under the curve, or the integral. A graphical representation of the area under the function f(x) = x using rectangles of width 1. As the width of the rectangle approaches zero, the combined sum of the area of the rectangles equals 1/2. All mathematically computed integrals have a start value to an end value. If the end value is less than the start value, it is assumed to be negative area (i.e., you subtract the area of the rectangle). Your job in this problem is to compute the integral of the function f(x) = 1/x from 1 to an value from a set of input values from a file. You may safely assume that the value of x in the file is a valid real number where 0 < x (i.e., x is a positive real number).
Input
Your input is a command line argument. You may safely assume that the argument will be an absolute path to a file that has real number entries that are space delimited. For each entry, you must compute the value of the integral of f(x) from 1 to the value.
Output
Your output must match the true value of the integral to the thousandths place (i.e., the third digit after the decimal place) within one thousandth (i.e. 0.0879 will be accepted as correct for 0.088). Remember that any value in the entry list that is less than 1 should be a negative result. Your output should be formatted to only display three digits after the decimal point. Other considerations: There is a trick to this question if you know what the general result to the integral of the function 1/x is. Note: For the final answer, 0.000 is an acceptable result as well.
Sample
Input
3
27.64738
0.0493
0.99954
Output
1.099
3.320
-3.010
-0.000
Comments