Syntax
y=interPL(PL,x)
Input Parameter
PL : | | Point list (nx2) using x and y values |
x : | | input value within the interval of xmin and xmax of PL |
Output Parameter
y : | | interpolated value for y or NaN outside of xmin and xmax of PL |
Examples
find interpolation values for a simple point list for x=13
interPL([10 10; 12 2; 14 12],13)
Copyright 2015-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, interPL
, performs linear interpolation using a given point list (PL) and an input value (x). The function is designed to return an interpolated y-value based on the x-value provided, using the points in the list.
Input Parameters
- PL: A point list, which is an nx2 matrix containing x and y values. The list must be sorted by the x-values in ascending order before calling the function.
- x: The input x-value for which the corresponding y-value is to be interpolated. It must lie within the range of the x-values in the point list.
Output
- y: The interpolated y-value corresponding to the input x-value. If x is outside the range of the x-values in PL, the function returns NaN.
Algorithm Steps
- Check if the input x is outside the range of the x-values in PL. If so, return NaN.
- Find the first index
a
in PL where the x-value is greater than or equal to the input x.
- If the x-value at index
a
is equal to the input x, return the corresponding y-value from PL.
- If not, perform linear interpolation using the formula:
y = PL(a-1,2) + ((PL(a,2) - PL(a-1,2)) / (PL(a,1) - PL(a-1,1))) * (x - PL(a-1,1))
The function assumes that the point list is pre-sorted by x-values. If the input x is exactly one of the x-values in the list, the corresponding y-value is returned directly. Otherwise, the function calculates the y-value using linear interpolation between the two nearest points.
Algorithm explaination created using ChatGPT on 2025-08-19 00:48. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21