How to obtain the piecewise expressions of spline fit obtained using MATLAB's command spapi?

3 visualizzazioni (ultimi 30 giorni)
I am working on fitting the data using B-form splines. I am using "spapi" command in MATLAB. Here is my code:
x = [0.0 0.3 0.5 0.6 1.0 1.0 0.0 0.2 0.6 0.8];
y = [1.0 0.5 0.9 0.8 0.0 1.0 0.0 0.1 0.2 0.7];
[yy,xx] = meshgrid(y,x); z = sin(xx+yy);
sp = spapi({3,5},{x,y},z)
fnplt(sp)
fnval(sp,[x;y])
I want to obtain the piece wise expressions of the splines. I tried see the documentation of spapi but they haven't mentioned any formulations for those. The function fnval only provide the value at some points, but i want to obtain the expression and calculate it derivatives further.

Risposte (1)

Steven Lord
Steven Lord il 22 Set 2022
i want to obtain the expression and calculate it derivatives further.
Do you need the actual expression, or do you just want to be able to evaluate and differentiate it?
To evaluate it, use fnval. To differentiate it, use fnder.
load census
S = spapi(2, cdate, pop);
S2 = fnder(S);
[minYear, maxYear] = bounds(cdate);
Y = minYear:5:maxYear;
plot(cdate, pop, 'o', Y, fnval(S, Y), '-+')
figure
plot(Y, fnval(S2, Y), 'x--')

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by