Finding cubic spline equations by 3 data points

조회 수: 1 (최근 30일)
taitai ho
taitai ho 2015년 9월 27일
답변: Aditya 2025년 2월 4일
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?

답변 (1개)

Aditya
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');

카테고리

Help CenterFile Exchange에서 Splines에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by