Problem Statement
In this problem, you are to write a method that models the signal strength of a connection, given the distance between two wireless components and a function that models the signal strength. The function given to you will be the sum of a number of terms of the form coeff*distexp. Each of these terms will be represented by an element of coeffs and a corresponding element of exp with the same index. Thus, the function 4*dist-1 + 3*dist2 would be represented by coeff = {4,3} and exp = {-1,2}. Your task is to evaluate the function represented by coeff and exp for the given dist and return the result.
Definition
- Class:
- Connection
- Method:
- signalStrength
- Parameters:
- int[], int[], int
- Returns:
- double
- Method signature:
- double signalStrength(int[] coeff, int[] exp, int dist)
- (be sure your method is public)
Constraints
- coeff and exp will each contain between 1 and 50 elements, inclusive.
- coeff and exp will contain the same number of elements.
- Each element of coeff will be between -100 and 100, inclusive.
- Each element of exp will be between -10 and 10, inclusive.
- dist will be between 1 and 1,000,000, inclusive.
- Each element of exp will be distinct.
Examples
{5,4}{-1,0}10
Returns: 4.5
Here, the signal strength is evaluated as: 5 * 10-1 + 4 * 100 = 5 * 0.1 + 4 * 1 = 4.5{100}{-2}13
Returns: 0.591715976331361
This is fairly realistic model of a wireless signal in empty space. The surface area of a sphere is proportional to the radius of the sphere squared. Thus, if the strength of a signal at a given distance is evenly distributed over the surface of a sphere, the strength at any one point is proportional to one over the radius squared.{-1,20}{1,0}25
Returns: -5.0
This example shows that some inputs lead to bogus results such as negative signal strength.{-7,40,-10,1}{-4,-2,-1,0}160
Returns: 0.9390624893188476