MATLAB Answers

finding the equation of spline in matlab

526 ビュー (過去 30 日間)
fardad
fardad 2011 年 12 月 1 日
コメント済み: farouk messaoud 2018 年 10 月 23 日
I have a curve (spline or polynomial) and suppose I can find as many points as I want. How can I find the equation of the curve I have plotted in MATLAB?

  0 件のコメント

サインインしてコメントする。

回答 (3 件)

Roche de Guzman
Roche de Guzman 2018 年 4 月 30 日
For the MATLAB function: spline, use the syntax: pp = spline(x,y) to get a structure data. Then extract the coefficients of the cubic spline arranged per row in a matrix form: C = pp.coefs, where C rows are: [a b c d] of the equation: f(x) = (a(x-x1)^3)+(b(x-x1)^2)+(c(x-x1))+(d) in the interval: [x1 x2].

  3 件のコメント

farouk messaoud
farouk messaoud 2018 年 10 月 22 日
hey; I have data to fit by cubic B-spline; How can I get the piecewise equations of the curves and the knot vector? thank you sir
farouk messaoud
farouk messaoud 2018 年 10 月 23 日
I did not find how to generate the b-spline piecewise functions?

サインインしてコメントする。


Hin Kwan Wong
Hin Kwan Wong 2011 年 12 月 1 日
Your question is ambigious. Are you trying to fit a spline to a spline or some data you don't know its nature?
You can't easily, given a spline curve, to fit a spline over it and reclaim the original spline parameters, as you need to know exactly the break points and the order of the spline. However, if you are talking about data, you can fit a spline or polynomial over the data as you see fit.
Just read
doc polyfit
For polynomial you use the polyfit function, which performas a least square regression to find the equation of the polynomial.
doc spline
is the spline fitting function.

  0 件のコメント

サインインしてコメントする。


Matt Allen
Matt Allen 2013 年 6 月 25 日
編集済み: Matt Allen 2013 年 6 月 25 日
If I understand your question correctly, you want to fit data to a spline over a grid. As Mr. Wong mentions, with Matlab's basic functionality you can fit a polynomial to data (which performs poorly for a complex function) or you can use a spline to interpolate on known values, but you can't fit a spline to data. To do this you need the curve fitting toolbox. The help for that toolbox is not very good but you can experiment with the functionality you want using "splinetool".
Most of us want a command line option, and after some digging I found that the following works:
x = 0:.25:10; y = sin(x);
xd=[0:.01:10];
yd=sin(xd)+0.1*randn(size(xd));
figure(1)
plot(x,y,'o-',xd,yd)
B= spap2(6,4,xd,yd) % 6 is the number of divisions, 4 the order of polynomial on each.
% fnplt(B) % this is a quick way to plot the fit, but doesn't give much freedom.
yfit=fnval(B,xd);
hold on; plot(xd,yfit,'r');

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by