Rectidirect interpolation is a system of computing the benjoin appraise of a exercise in single evidence, absorbed merely cases of the exercise at a regular of purposes. This is commmerely explanationd where the appraises of a exercise are trying or valuable to conciliate. Control stance, we may accept to propel extinguished a corporeal criterion, or a time-consuming boldness, to ascertain the exercise appraise control a absorbed evidence. As an stance, contemplate of “deformation of the deportment passenger allotment in a head-on clash as a exercise of urge” – to case the exercise control a absorbed urge appraise, we may need do a jar criterion!
Suppose we understand the exercise appraise at a regular of purposes yi = f(xi), control i = 1…n. To benjoin the exercise at a odd purpose x’, we ascertain the closest understandn purposes adown and overhead, say xadown < x’ and xoverhead > x’, sketch a undeviating verse betwixt (xbelow, ybelow) and (xabove, yabove), and transfer the appraise y’ where this verse is at x’.
The open controlm of the undeviating verse is a * x + b, where a = (yoverhead – ybelow) / (xoverhead – xbelow) and b = yadown – a * xbelow. Using this, we can calculate y’ = a * x’ + b
Your character is to tool a exercise interpolate(x, y, x_test) that computes the versear interpolation of the obscure exercise f at a odd purpose x_test. The case is absorbed in the controlm of span posterioritys x and y. Twain posterioritys accept the identical extension, and their elements are aggregate. The x posteriority contains the purposes where the exercise has been cased, and the y posteriority contains the exercise appraise at the identical purpose. In other signification, y[i] = f(x[i]).
Assumptions and restrictions:
You can take that the evidences are as vivid: that is, x and y are posterioritys, twain accept the identical extension, and their elements are aggregate.
You should NOT effect any boldness abextinguished what expression of posteriority the x and y evidences are.
You can take that the appraises in x are enjoined in increasing enjoin, and that they are choice (that is, there are no common x-values).
You can take that x_criterion is a reckon, and it is betwixt span appraises in the x posteriority, or maybe resembling to a appraise in the posteriority. If x_criterion is resembling to a case appraise (a appraise in the input xsequence), your exercise should barely yield the identical exercise appraise from y.
Your exercise must yield a reckon.
The scipy library has a unimpaired module, scipy.import which performs different kinds of interpolation, including versear interpolation as vivid overhead. Obviously, you may not attributable attributable attributable explanation this module, or any other module that provides a ready-made separation to the problem, since the sight of the assignment is control you to evince that you can tool the exercise yourself. You can of plan explanation the scipy interpolation exercise as a intimation to criterion your toolation.
NOTE: must be dsingle on python 3, using merely exercise definitions