Say I am given data as follows:
x = [1, 2.5, 3.4, 5.8, 6] y = [2, 4, 5.8, 4.3, 4]
I want to design a function that will interpolate linearly between 1
and 2.5
, 2.5
to 3.4
, and so on using Python.
I have tried looking through this Python tutorial, but I am still unable to get my head around it.
1: Find the value of y at x = 4 given some set of values (2, 4), (6, 7). Based on this chart, calculate the estimated height of the plant on the fourth day. Solution: This is an example of linear growth and hence the linear interpolation formula is very much suitable here.
This G code provides for straight line (linear) motion from point to point. Motion can occur in 1 or more axes. You can command a G01 with 3 or more axes All axes will start and finish motion at the same time.
Know the formula for the linear interpolation process. The formula is y = y1 + ((x - x1) / (x2 - x1)) * (y2 - y1), where x is the known value, y is the unknown value, x1 and y1 are the coordinates that are below the known x value, and x2 and y2 are the coordinates that are above the x value.
import scipy.interpolate y_interp = scipy.interpolate.interp1d(x, y) print y_interp(5.0)
scipy.interpolate.interp1d
does linear interpolation by and can be customized to handle error conditions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With