the inverse of spapi function
Mostra commenti meno recenti
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 Commenti
John D'Errico
il 12 Ott 2019
Modificato: John D'Errico
il 12 Ott 2019
Um, interesting question. Your subject asks to find an inverse, but your question asks how to plot it. You might try making up your mind as to what you really need to do, otherwise we are just guessing. Make it easy for someone to help you.
Foufa.h
il 12 Ott 2019
John D'Errico
il 12 Ott 2019
Modificato: John D'Errico
il 12 Ott 2019
Sorry, but how does a function evolve? Does it start out as a constant, then gradiually become linear, then higher order? Do functions have DNA at all?
Seriously, what are you asking? Evolution makes no sense in this context.
If all you want to do is plot the function, then fplot will do nicely.
If you are asking for an explanation of what a spline is, and what the parameters mean (that is, knots/breaks & coefficients) I'd strongly suggest reading the first few chapters of deBoors book, "A Practical Guide to Splines".
Foufa.h
il 13 Ott 2019
John D'Errico
il 13 Ott 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?
Risposte (1)
John D'Errico
il 13 Ott 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.
Categorie
Scopri di più su Spline Postprocessing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!