I understand that you want to obtain a piecewise function using shape-preserved interpolation (specifically PCHIP - Piecewise Cubic Hermite Interpolation), you can follow these steps in MATLAB:
- Import the data from Excel into MATLAB. Assuming you have the data stored in two separate arrays x and y, where x represents the independent variable and y represents the dependent variable.
- Use the “pchip” function in MATLAB to perform shape-preserving interpolation and obtain the piecewise function. Here's an example code snippet:
x_vals = linspace(min(x), max(x), 100);
y_vals = ppval(pp, x_vals);
The pp variable will store the piecewise function obtained using PCHIP interpolation. You can then evaluate this function at any desired points using the “ppval” function.
Note: Ensure that the data points are sorted in ascending order based on the independent variable (x) before performing the interpolation.
By executing the above code, you should be able to obtain a piecewise function (PCHIP) and visualize it using a plot. Feel free to adjust the number of points (100 in the example) or customize the plot as per your requirements.
Find attached documentation of “pchip”, “linspace” and “ppval” functions.