6 views (last 30 days)

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

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.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755475

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755475

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755479

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755479

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755486

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755486

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755654

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755654

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755759

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/484909-the-inverse-of-spapi-function#comment_755759

Sign in to comment.