【发布时间】:2017-02-09 04:12:07
【问题描述】:
如何使用jsx图绘制f(x)(用户输入)和f(x-a)的图,其中a的值是从滑块接收的?例如,如果用户输入 xx 并且滑块 a 的值为 1,那么 jsx 板上将有两个图形:一个是 x 的,另一个是 (x-1)(x-1)?
【问题讨论】:
标签: jsxgraph
如何使用jsx图绘制f(x)(用户输入)和f(x-a)的图,其中a的值是从滑块接收的?例如,如果用户输入 xx 并且滑块 a 的值为 1,那么 jsx 板上将有两个图形:一个是 x 的,另一个是 (x-1)(x-1)?
【问题讨论】:
标签: jsxgraph
从Changing the function in the text box is not changing the graph 获取我的答案,同时绘制用户提供的函数f(x) 和依赖于滑块的函数f(x-a),如下所示:
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-6, 12, 8, -6], axis: true});
a = board.create('slider', [[-4,7], [4,7], [-10, 1,10]], {name:'a'});
doPlot = function() {
var txtraw = document.getElementById('input').value, // Read user input
f = board.jc.snippet(txtraw, true, 'x', true), // Parse input with JessieCode
curve, curve2;
board.removeObject('f'); // Remove element with name f
board.removeObject('g'); // Remove element with name g
curve = board.create('functiongraph', [f, -10, 10], {name:'f'});
curve2 = board.create('functiongraph', [
function(x) {
return f(x - a.Value());
}, -10, 10], {name:'g', strokeColor: 'red'});
};
doPlot();
这意味着诀窍是定义第二个返回f(x-a) 的函数。见https://jsfiddle.net/qmp0qdvv/1/。和上面提到的其他问题一样,这个例子允许使用 JSXGraph 的 JessieCode 解析器输入纯数学语法而不是 JavaScript 代码。
【讨论】: