Ask Your Question
1

how to convert Spline to Piecewise?

asked 2012-10-22 19:20:06 -0500

zasdfgbnm gravatar image

I want to get the result analytic expression of a spline. How to get it? Thanks for help.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2012-10-23 02:39:57 -0500

achrzesz gravatar image

updated 2012-10-23 02:51:27 -0500

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)
edit flag offensive delete link more

Comments

Do you think it would be worth wrapping these, and would they agree with the GSL ones?

kcrisman gravatar imagekcrisman ( 2012-10-23 03:27:32 -0500 )edit

thanks for your reply

zasdfgbnm gravatar imagezasdfgbnm ( 2012-10-23 18:22:14 -0500 )edit
0

answered 2012-10-23 05:56:08 -0500

achrzesz gravatar image

updated 2012-10-23 07:12:31 -0500

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]
edit flag offensive delete link more

Comments

Yeah, maybe connecting this with Piecewise, primitive as that is...

kcrisman gravatar imagekcrisman ( 2012-10-23 09:43:04 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-10-22 19:20:06 -0500

Seen: 407 times

Last updated: Oct 23 '12