the inverse of spapi function

6 ビュー (過去 30 日間)
Foufa.h 2019 年 10 月 12 日

Hi, I have a data of (knots and coefs of function of order 5) and i want to plot the function .
5 件のコメント表示非表示 4 件の古いコメント
John D'Errico 2019 年 10 月 13 日
Ok, so you built a spline, apparntly using spapi? And now, you want to know something about the spline?
NO, mkpp will do absolutely nothing for you. It does not apply to existing splines.
Do you want to know the actually polynomial pieces in each segment?

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

回答 (1 件)

John D'Errico 2019 年 10 月 13 日
I think this may be what you are asking for.
x = 1:7;
y = rand(1,7);
S = spapi(5,x,y)
S =
struct with fields:
form: 'B-'
knots: [1 1 1 1 1 3.5 4.5 7 7 7 7 7]
coefs: [0.95949 2.2569 -1.8189 2.4593 0.40081 0.66712 0.75774]
number: 7
order: 5
dim: 1
The result is a 5th order B-spline. It is simple enough to convert to a pp form though, which is a bit more readable.
pp = fn2fm(S,'pp')
pp =
struct with fields:
form: 'pp'
breaks: [1 3.5 4.5 7]
coefs: [3×5 double]
pieces: 3
order: 5
dim: 1
Here we see the result is a set of 3 polynomial segments. There are 4 breaks, so between each pair of breaks you have one polynomial segment. Be careful, as those polynomials are intended to be used relative to the break at the lower end of the corresponding interval. Thus, we see the first polynomial segment as:
format long g
pp.coefs(1,:)
ans =
-0.275001995156781 1.93576726441605 -4.04042647382373 2.07590947732814 0.959492426392903
It lives on the interval [1,3.5], thus the first knot interval from this set:
pp.breaks
ans =
1 3.5 4.5 7
Can we use that polynomial to evaluate the spline? Of course. As you can see, these two calls are equivalent.
fnval(S,2.5)
ans =
0.123413993204698
polyval(pp.coefs(1,:),2.5 - pp.breaks(1))
ans =
0.123413993204696
Is this what you are asking for? Of that, I have no clue.

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

Community Treasure Hunt

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

Start Hunting!