interPL

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 2.4, Creation date: 2015-06-15, Last change: 2025-09-14

returns a value as linear interpolation using a PL

Description

Returns a linear interpolation value y using a Point list (nx2) consisting of x and y values. If the input parameter is outside of the defined interval the function return NaN. At a later stage it makes sense to introduce a third parameter for different interpolation functions (splines etc.).
ATTENTION: The point list has to be sorted using PL=sortrows(PL,1) before calling the function.

Example Illustration

 missing image of interPL(PL,x)

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

Output

Algorithm Steps

  1. Check if the input x is outside the range of the x-values in PL. If so, return NaN.
  2. Find the first index a in PL where the x-value is greater than or equal to the input x.
  3. If the x-value at index a is equal to the input x, return the corresponding y-value from PL.
  4. 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