Imagine you are riding in a car on a road which leads over rolling hills. As
you climb up a slope your car will point upwards, and while you roll down a slope
your car will point downwards. If the height of the road at some distance x
can be described by a function f(x), then could we calculate the slope at any
given position x?
For a straight line between two points A = (x_A, y_A) and B = (x_B, y_B), the
slope m is given by the total difference in y divided by the total difference
in x (often called the "rise-over-run" method).
$$ \Large m = \frac{y_{B} - y_{A}}{x_{B} - x_{A}} $$
Now let's take some function f(x) = -0.5 * x^3 + 2 and we want to know the slope of this
function. Since it is a curve the slope is constantly changing, and so we will
narrow our question to ask for the slope m0 at some specific point on the curve
where x = x0. This is equivalent to drawing the "tangent line" to the curve
at that point.
But how do we obtain the exact value? Using our formula above for the slope of a
straight line, we could imagine evaluating f(x) at two points close to x0,
then drawing a straight line between them to approximate the slope at that point.
As the gap d between those points decreases, then the slope should become
more and more accurate.
For example, let's take that function f(x) = -0.5 * x^3 + 2, and try to approximate
the slope at the point x0 = 1. We'll using a gap between our points of d = 0.5, then
we could observe that the slope between the points at A = (0.75, f(0.75)) and
B = (1.25, f(1.25)) yields m0 = -1.531250. Decreasing our gap to d = 0.25
then our approximation yields m0 = -1.507813, and as we keep decreasing d then
our approximation of m0 will become more accurate to the actual value of -1.5.
The curve f(x) = -0.5 * x^3 + 2, and the slope approximation at x0 = 1 using gap d = 0.5.
You will be given some function f(x), a value x0, and a gap value d, and you
must return the approximation m0 per the method described above.
f(x) will be a polynomial of order 3 in the form
f(x) = (c3 * x ^ 3) + (c2 * x ^ 2) + (c1 * x ^ 1) + c0.
Input Data
The first line will be Q, the quantity of testcases.
Q lines will then follow, each with two space-separated values in the format
c3 c2 c1 c0 x0 d.
Answer
Should consist of Q space-separated values corresponding to the approximation
of m0 in each testcase.
Error should be less than 1e-6.
Example
input data:
2
0.1 0.2 0.3 0.4 0.5 0.6
-0.9 0.8 -0.7 0.6 -0.5 0.4
answer:
0.584 -2.211