Menu

[r3629]: / trunk / py4science / examples / spline_demo.py  Maximize  Restore  History

Download this file

23 lines (18 with data), 580 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from __future__ import division
import sys
import numpy as N
import pylab as P
from scipy import interpolate
#paramaters
dt1 = 0.005 # step size
dt2 = 0.001
tfine = N.arange(0.0, 5, 0.01)
tcoarse = N.arange(0.0, 5, 0.1)
s = N.cos(N.pi*tcoarse) * N.sin(2*N.pi*tcoarse)
# create sinterp by computing the spline fitting tcoarse to s and then
evaluating it on tfine. Plot tcoarse vs s with markers and tfine vs
sinterp with a solid line
tck = interpolate.splrep(tcoarse, s, s=0)
sinterp = interpolate.splev(tfine, tck, der=0)
P.plot(tcoarse, s, 'o', tfine, sinterp)
P.show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.