the inverse of spapi function

6 views (last 30 days)
Foufa.h
Foufa.h on 12 Oct 2019
Answered: John D'Errico on 13 Oct 2019
Hi, I have a data of (knots and coefs of function of order 5) and i want to plot the function .
how to do this please??
  5 Comments
Foufa.h
Foufa.h on 13 Oct 2019
Thank you for your explanation.
In my case I dont know the function. I only knows the order =5 and the vector of Knots and vector of coefs.
There is a function of matlab called
pp = mkpp(breaks,coefs) which Make piecewise polynomial. Maybe it is the solution of my problem.
Thank you very much.
John D'Errico
John D'Errico on 13 Oct 2019
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?

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 13 Oct 2019
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!