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

3 visualizaciones (últimos 30 días)
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.

Respuestas (1)

Steven Lord
Steven Lord el 22 de Sept. de 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--')

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by