how to convert Spline to Piecewise?
I want to get the result analytic expression of a spline. How to get it? Thanks for help.
I want to get the result analytic expression of a spline. How to get it? Thanks for help.
spline from GSL is a numerical tool. To obtain symbolic values you can use maxima:
sage: maxima('load(interpol)')
sage: maxima('p:[[7,2],[8,2],[3,2],[6,7]]')
[[7,2],[8,2],[3,2],[6,7]]
sage: # Sage symbolic expressions
sage: p1=maxima('part(cspline(p),1,1)').sage();p1
-95/279*x^3 + 95/31*x^2 - 415/93*x - 3
sage: p2=maxima('part(cspline(p),2,1)').sage();p2
-140/93*x^3 + 1120/31*x^2 - 26740/93*x + 23582/31
sage: p3=maxima('part(cspline(p),3,1)').sage();p3
235/93*x^3 - 1505/31*x^2 + 28385/93*x - 19293/31
sage: # maxima expression for comparison
sage: maxima('cspline(p)')
(-95*x^3/279+95*x^2/31-415*x/93-3)*charfun2(x,minf,6)+(-140*x^3/93+1120*x^2/31-26740*x/93+23582/31)*charfun2(x,7,inf)+(235*x^3/93-1505*x^2/31+28385*x/93-19293/31)*charfun2(x,6,7)
Some primitive comparison GSL/maxima:
#Sage spline
p=[[7,2],[8,2],[3,2],[6,7]]
f=spline(p)
[f(k) for k in[3..8]] # k have to be in [3,8]
[2.0, 6.39068100358423, 8.738351254480287, 7.0, 2.0, 1.9999999999999996]
[f(k+0.5) for k in[3..7]]
[4.323028673835125, 7.947580645161291, 8.507616487455198, 4.318548387096774, 1.4354838709677418]
/*maxima cspline*/
load(interpol);
p:[[7,2],[8,2],[3,2],[6,7]];
c:cspline(p);
makelist(ev(subst(k,x,c),numer),k,3,8); /* k can be outside of [3,8]*/
[1.999999999999998,6.39068100358423,8.738351254480285,6.999999999999545,2.000000000000341,2.000000000000455]
makelist(ev(subst(k+0.5,x,c),numer),k,3,7);
[4.323028673835125,7.947580645161292,8.507616487455195,4.318548387096712,1.435483870968369]
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2012-10-23 02:20:06 +0100
Seen: 756 times
Last updated: Oct 23 '12
spline representation of a spiral
How to plot derivative and antiderivative of a spline
How to plot B-spline basis functions
Correct input for list_plot3d(..., interpolation='spline')
Spline interpolation varies hugely when variables are rescaled in 3d-lists ?
Using interpolated curve on parametric plot
Is there any extrapolation method already implemented in Sage?