Question: This is in java. Be sure to pass the 3 examples below. No packages can be imported, THANK YOU. // 5.2 public static double getIntersection

This is in java. Be sure to pass the 3 examples below. No packages can be imported, THANK YOU.

This is in java. Be sure to pass the 3 examples below.

No packages can be imported, THANK YOU. // 5.2 public static double

getIntersection (int[] polyl, int[] poly2) Example input and output is provided below:

// 5.2 public static double getIntersection (int[] polyl, int[] poly2) Example input and output is provided below: Input : polyl=[2,130,1], poly2=[6,2,9] Output: 8.0 A brief explanation of the output: f1 (t)= poly1 = 2 + 130t + t, f2 (t)= poly2 = 6 + 2t + 9t? fl' (t) = 130 + 2t, f2' (t)= 2 + 18t fl' (t)= f2' (t) -> (130+2t)= (2+18t) -> (2-18) t= (2-130) -> t = 2-130 = 8.0 -128 2-18 -16 -> this indicates that at t=8, on the 8th day, the two stock price models will intersect and have equal growth rate. The first two lines calculate the derivative of the two models (Use the helper method implemented in 5.1). Since we're acquiring time t when both models have equal growth rate, we'll be solving f1'(t) = f2'(t), resulting in the third and fourth line. Hint: Solving for t might seem complicated. Try observing the individual values in the numerator and denominator in correspondence to the elements in the derivative arrays (f1'(t) and f2' (t)). You'll observe a pattern when solving it. For the simplicity of this problem, you can assume that both poly1 and poly2 will have a maximum power of 2. This way, the derivative of the two functions will yield linear equations, which is more solvable. Yet, there are several situations to consider when solving for the solution Scenario 1: The growth rate of the two models never intersects with each other. You'll be returning negative infinity (Double.NEGATIVE_INFINITY in java) Scenario 2: The growth rate of the two models are always equal. You'll be returning positive infinity (Double.POSITIVE_INFINITY in java) Scenario 3: The solution to the equation yields a negative, invalid t value. You'll be returning -1.0 to symbolize this specific case. Note: While the prompt says that poly1 and poly2 will have max power of 2, you are not guaranteed that it will always be a quadratic formula. Price models such as f(t) = 5t+5 or f(t) = 1 are valid inputs as well. That being said, poly1 and poly2 isn't necessarily going to have length = 3 To make this problem more simple, we'll consider t=0 as a valid timestamp(even though it is the endpoint of a model), and it doesn't necessarily need to be an integer Be careful when you're performing division. Java has different forms of division than Python Additional Examples Example2 Input : polyl=[5,5,4], poly2=[0,3,4] Output: Infinity A brief explanation of the output: 2 fi(t)= poly1 5 + 5t + 4?, f2(t)= poly2 = 0 + 3t + 4t? f1' (t) = 5 + 8t, f2' (t)= 3 + 8t fl' (t)= f2' (t) -> (5+8t)=(3+8t) -> (8-8) t=(3-5) -> 0*t=-2 -> (no solution, therefore returning negative infinity) - 00 Example3 Input : polyl=[1,6,1], poly2=[2,-3,-3] Output: -1.0 A brief explanation of the output: I fi (t) = poly1 = 1 + 6t + t, f2(t)= poly2 = 2 3t 3t t f1' (t) = 6 + 2t, f2' (t)= 3 6t fl' (t)= f2' (t) -> (6+2t)=(-3-4t) ->(2-(-4)) t=(-3-6) -3-6 -9 -> t = 1.5 (invalid t value, therefore return -1) 2-(-4) = = 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!