Finding cubic spline equations by 3 data points
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Given that I have 3 data point, (3,12),(4.5,17),(6.5,38).I wanna find the cubic spline equation which link 3pts together. Here is my code: x=[3 4.5 6.5]; y=[12 17 38]; cs=spline(x,y). Result:
cs =
form: 'pp'
breaks: [3 6.5000]
coefs: [2.0476 0.2619 12]
pieces: 1
order: 3
dim: 1
It just give me 3 coefs.However, it should be 4 coefs in each equations, in total it should has 8 coefs in 2 cubic spline equations.what is wrong with my code?
0 Commenti
Risposte (1)
Aditya
il 4 Feb 2025
Hi Tatai,
When using MATLAB's spline function, it creates a piecewise polynomial (pp) form to represent the cubic spline. This form is used to interpolate the given data points. However, it seems there might be some confusion regarding the coefficients and the expected output.
Here's an example of how you might manually check or use a different method to see the cubic coefficients:
% Given data points
x = [3 4.5 6.5];
y = [12 17 38];
% Use the 'csape' function for a cubic spline with natural boundary conditions
cs = csape(x, y, 'variational');
% Display the coefficients
coefficients = cs.coefs
% Plot to visualize
xx = linspace(min(x), max(x), 100);
yy = ppval(cs, xx);
plot(x, y, 'o', xx, yy, '-');
title('Cubic Spline Interpolation');
xlabel('x');
ylabel('y');
0 Commenti
Vedere anche
Categorie
Scopri di più su Splines in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!