From e82114b2cc42a8051be7fc7a83b891f339b33929 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 27 Nov 2009 12:17:01 -0500 Subject: [PATCH] some built-in functions for the plotter --- docs/plotter.html | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/plotter.html b/docs/plotter.html index 325c731..f36573b 100644 --- a/docs/plotter.html +++ b/docs/plotter.html @@ -22,19 +22,52 @@ for (var i = 0; i < width; i++) { var x = x1 + i * xs; var y = fn(x); - data.push([x, y]); + var row = [x]; + if (y.length > 0) { + for (var j = 0; j < y.length; j++) { + row.push(y[j]); + } + } else { + row.push(y); + } + data.push(row); } - g = new Dygraph(graph, data, { labels: ["x", "y"] }); + g = new Dygraph(graph, data); + } + + function preset() { + var sel = document.getElementById("presets").selectedIndex; + var id = document.getElementById("presets").options[sel].id; + var presets = { + 'id': [ -10, 10, 'function(x) {\n return x;\n}' ], + 'sine': [ -10, 10, 'function(x) {\n return Math.sin(x);\n}' ], + 'taylor': [ -3, 3, 'function(x) {\n return [Math.cos(x), 1 - x*x/2 + x*x*x*x/24];\n}' ], + 'sawtooth': [-10, 10, 'function(x) {\n var y = 0;\n for (var i = 1; i < 20; i+=2) {\n y += Math.sin(i * x)/i;\n }\n var final = 1 - 2*(Math.abs(Math.floor(x / Math.PI)) % 2);\n return [4/Math.PI * y, final];\n}' ] + }; + + if (id == "custom") { return; } + document.getElementById("x1").value = presets[id][0]; + document.getElementById("x2").value = presets[id][1]; + document.getElementById("eq").value = presets[id][2]; + plot(); } - +

Equation:
+ return [0.1 * x, 0.1 * x + Math.sin(x), 0.1*x + Math.cos(x)]; +}
+Preset functions:

+

x range: to

-- 2.7.4