Finding cubic spline equations by 3 data points
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Aditya
2025-2-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!