【问题标题】:Creating graph of f(x) and f(x-a) by using JSX graph使用 JSX 图创建 f(x) 和 f(x-a) 的图
【发布时间】:2017-02-09 04:12:07
【问题描述】:

如何使用jsx图绘制f(x)(用户输入)和f(x-a)的图,其中a的值是从滑块接收的?例如,如果用户输入 xx 并且滑块 a 的值为 1,那么 jsx 板上将有两个图形:一个是 x 的,另一个是 (x-1)(x-1)?

【问题讨论】:

    标签: jsxgraph


    【解决方案1】:

    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 代码。

    【讨论】:

    • 绘制 f(x)+b、f(-x) 和 -f(x) 的图形需要进行哪些修改? b 的值会在滑块上再次改变。
    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多