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

7 次查看(过去 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 个评论

请先登录,再进行评论。

采纳的回答

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
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,

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by