We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cd41eb3 commit 56dff41Copy full SHA for 56dff41
sindemo.coffee
@@ -0,0 +1,28 @@
1
+###
2
+sindemo
3
+
4
+Sample and cubic interpolate the sin function, then print out max and average error.
5
6
7
+{Smooth} = require './Smooth'
8
9
+s = (Math.sin 2*Math.PI*x for x in [0...1] by 1/8)
10
11
12
+#Scale the function
13
+smooth_sin = ((f) ->
14
+ scaleVal = 0.5*s.length/Math.PI
15
+ return (x) -> f x*scaleVal
16
+) Smooth s, method:Smooth.METHOD_CUBIC, clip:Smooth.CLIP_PERIODIC
17
18
+totalError = 0
19
+count = 0
20
+maxError = 0
21
+for x in [-10..10] by .001
22
+ error = Math.abs Math.sin(x) - smooth_sin(x)
23
+ maxError = Math.max error, maxError
24
+ totalError += error
25
+ count++
26
27
+console.log "Max Error:\t #{(100*maxError).toFixed(10)}%"
28
+console.log "Average Error:\t #{(100*totalError/count).toFixed(10)}%"
0 commit comments