How can I obtain the analytical expression (polynomial) of the spline curve from a curve fitting?

조회 수: 12 (최근 30일)
I have extracted data from some graphs (images) and then I curve fitted that data to obtain some spline curves. What I need is the polynomial of those spline, the f(x) that draw the initial graphs, the function that relates the x and y points. How can I do that? Thanks!
  댓글 수: 3
Radu Andrei Matei
Radu Andrei Matei 2022년 3월 3일
Thanks, after reading the answers to this question I could understand the ones for that question better.

댓글을 달려면 로그인하십시오.

채택된 답변

David Goodmanson
David Goodmanson 2022년 3월 3일
편집: David Goodmanson 2022년 3월 3일
Hi Radu,
x = 1:10;
y = sin(x).^3;
a = interp1(x,y,'spline','pp')
a =
struct with fields:
form: 'pp'
breaks: [1 2 3 4 5 6 7 8 9 10]
coefs: [9×4 double]
pieces: 9
order: 4
dim: 1
orient: 'first'
>> a.coefs
ans =
0.3050 -1.3676 1.2186 0.5958
0.3050 -0.4525 -0.6016 0.7518
-0.3075 0.4626 -0.5914 0.0028
0.6000 -0.4598 -0.5886 -0.4335
-0.7723 1.3403 0.2920 -0.8818
0.6265 -0.9767 0.6556 -0.0218
-0.7998 0.9029 0.5818 0.2836
0.6101 -1.4966 -0.0119 0.9684
0.6101 0.3337 -1.1748 0.0700
each row is a polynomial in standard Matlab notation, coefficient of x^3 first, coefficient of x^0 last.
a = spline(x,y) does the same thing.
  댓글 수: 3
Radu Andrei Matei
Radu Andrei Matei 2022년 3월 3일
Hi, I think I found it. I think using ppval I can find the f(x) value for a given x in the entire spline. Correct me if I'm wrong please.
David Goodmanson
David Goodmanson 2022년 3월 3일
편집: David Goodmanson 2022년 3월 3일
Hello Radu,
Yes, each polynomial describes the function for a given little range. Also each polynomial is local in the sense that x = 0 effectively restarts at the beginning of each range. And you are correct, ppval will reconstruct the whole works.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2022년 3월 3일
편집: Matt J 2022년 3월 3일
What I need is the polynomial of those spline
A spline consists of many polynomials stuck together, not just one.Also, there are a number of different forms in which spline fits can exist in Matlab, and we don't know which ones you have. If you really need to break down a spline, and it is in the form of a pp structure you could use unmkpp. More likely, you used cftool, in which case you have a cfit object.
Regardless, there is a reason that Matlab doesn't provide you with an analytical form for the spline. It's because far better tools are provided to post-process a fit,
  댓글 수: 1
Radu Andrei Matei
Radu Andrei Matei 2022년 3월 3일
Hi, thank you for your answer, but as I am a big matlab noob I could understand David Goodmanson's answer better.

댓글을 달려면 로그인하십시오.

카테고리

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