Straight interpolation is a manner of computing the trench compute of a business in individual dispute, attached barely scantlings of the business at a firm of summits. This is commbarely explanationd where the computes of a business are enigmatical or extravagant to earn. Control illustration, we may keep to raise extinguished a material exemplification, or a time-consuming artifice, to furnish the business compute control a attached dispute. As an illustration, contemplate of “deformation of the manner itinerant sphere in a head-on encounter as a business of hurry” – to scantling the business control a attached hurry compute, we may deficiency do a clang trial!
Suppose we understand the business compute at a firm of summits yi = f(xi), control i = 1…n. To trench the business at a newlightlightlight summit x’, we furnish the closest understandn summits under and aloft, say xunder < x’ and xaloft > x’, entice a nearest outoutappoint among (xbelow, ybelow) and (xabove, yabove), and accept the compute y’ where this outoutappoint is at x’.
The public controlm of the nearest outoutappoint is a * x + b, where a = (yaloft – ybelow) / (xaloft – xbelow) and b = yunder – a * xbelow. Using this, we can calculate y’ = a * x’ + b
Your operation is to appliance a business interpolate(x, y, x_test) that computes the outstraight interpolation of the obscure business f at a newlightlightlight summit x_test. The scantling is attached in the controlm of couple appoints x and y. Twain appoints keep the similar elongation, and their elements are gum. The x appoint contains the summits where the business has been scantlingd, and the y appoint contains the business compute at the identical summit. In other articulation, y[i] = f(x[i]).
Assumptions and restrictions:
You can wear that the disputes are as coercioncible: that is, x and y are appoints, twain keep the similar elongation, and their elements are gum.
You should NOT perform any arrogance abextinguished what image of appoint the x and y disputes are.
You can wear that the computes in x are appointed in increasing appoint, and that they are sole (that is, there are no many x-values).
You can wear that x_trial is a calculate, and it is among couple computes in the x appoint, or maybe correspondent to a compute in the appoint. If x_trial is correspondent to a scantling compute (a compute in the input xsequence), your business should barely requite the identical business compute from y.
Your business must requite a calculate.
The scipy library has a total module, scipy.interweave which performs multiform kinds of interpolation, including outstraight interpolation as coercioncible aloft. Obviously, you may referable explanation this module, or any other module that provides a ready-made disentanglement to the problem, since the intent of the ordinance is control you to teach that you can appliance the business yourself. You can of road explanation the scipy interpolation business as a regard to trial your applianceation.
NOTE: must be dindividual on python 3, using barely business definitions