In the previous problem we
learned how to approximate the tangent line slope to a function at some point x0
using some resolution factor of d. We also observed that as d decreased, the
accuracy of the approximation inscreased. At first we may be motivated to set
d = 0, but at that case our approximated slope becomes 0 / 0, which is not a
useful result.
But is there some way to directly calculate the result without setting d to
some infinitesimally small value? The answer lies in the function's Derivative.
The Derivative of a function is another function which returns the tangent slope
of the original function. A function's derivative is usually denoted by a prime
mark ′ next to the name of the function. For example, the derivative of f(x)
would be written as f′(x). The process of transforming a given function
into its derivative is known as differentiation.
There exist a number of rules describing how to transform a given function into its derivative, and in this problem we will focus on the first 3 rules, which will tell us everything we need to know in order to differentiate any polynomial function. Those rules are:
0.
f(x) = 5 then f′(x) = 0.f(x) = c * x ^ b has a derivative of
f′(x) = c * b * x ^ (b - 1), for all cases where b != 0.
f(x) = 4 * x ^ 3 then f′(x) = 12 * x ^ 2.f(x) = g(x) + h(x) has a derivative equal to the sum of the
derivatives of the sub-functions, f′(x) = g′(x) + h′(x). Note that his applies
to differences as well as sums.
f(x) = 4 * x ^ 3 + 7 * x + 8 then f′(x) = 12 * x ^ 2 + 7.And now to find the exact tangent slope m0 of f(x) at some point x = x0, we
only need to evaluate the function f′(x0) to find our exact answer.
The curve f(x) = -0.5 * x^3 + 2 and the tangent slope at x0 = 1.
The purple tangent line has slope equal to f′(x0) = -1.5.
As an aside, it is useful to understand the applications of the derivative beyond
a graphical tangent. When the variable in question is time, then the derivative
refers to the instantaneous rate of change of that function's value at that
exact moment. A common application of this is in Physics, to calculate information
about an object's velocity given data about its position, or to calculate information
about an object's acceleration given its velocity.
You will be given some function f(x) and a value x0, and you must return the
exact slope m_0 per the method described above.
f(x) will be a polynomial with 4 terms in the form
f(x) = (c3 * x ^ b3) + (c2 * x ^ b2) + (c1 * x ^ b1) + (c0 * x ^ b0).
Input Data
First line will be Q, the quantity of testcases.
Q lines will then follow, each with nine space-separated values in the format
c3 b3 c2 b2 c1 b1 c0 b0 x0, describing f(x) and a point at x = x0.
Answer
Should consist of Q space-separated values, corresponding to the value of f′(x0) in each testcase.
Error should be less than 1e-6.
Example
input data:
3
0.1 0 0.2 0 0.3 0 0.4 0 0.51
0.1 3 0.2 2 0.3 1 0.4 0 0.52
-0.9 -3 0.8 -2 -0.7 -1 0.6 0.5 0.53
answer:
0 0.589120 26.375391