Hi! I imported data set from excel and then used curve-fitting tool. Now, I need assistance in getting a piecewise function (PCHIP) from a shape preserved interpolation.

11 vues (au cours des 30 derniers jours)
2.0243e+03 13067000
2.0250e+03 14074400
2.0257e+03 15081800
2.0264e+03 16089200
2.0271e+03 17096600
2.0277e+03 18104000
2.0284e+03 19111400
2.0291e+03 20118800
2.0298e+03 21126200
2.0305e+03 22133600
2.0312e+03 23141000
2.0319e+03 24973300
2.0325e+03 26805600
2.0331e+03 28637900
2.0337e+03 30470200
2.0344e+03 32302500
2035 34134800
This is the data and I can't figure out a way to get the piecewise equation. I am new to Matlab. Please guide me.

Réponses (1)

arushi
arushi le 6 Sep 2024
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:
% Perform shape-preserving interpolation using PCHIP
pp = pchip(x, y);
% Evaluate the piecewise function at specific points
x_vals = linspace(min(x), max(x), 100); % Specify the range of x values for evaluation
y_vals = ppval(pp, x_vals); % Evaluate the piecewise function at x_vals
% Plot the interpolated curve
plot(x_vals, y_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.

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by