how to make a dynamic function to draw integral Graph from user input with JSXGraph?

只谈情不闲聊 提交于 2019-12-13 06:47:15

问题


I have a problem to make a dynamic graph from this library http://jsxgraph.uni-bayreuth.de/docs/symbols/Integral.html

== this will make f(x) = x^3

var c1 = board.create('functiongraph', [function (t) { return t*t*t; }]);
var i1 = board.create('integral', [[-1.0, 4.0], c1]);

but, how can i make function(t) depends from user input ? for example user input x^2+4x from texboxt and the code will generate this: var fx = $("#fx").val(); // fx = x^2 + 4x var c1 = board.create('functiongraph', [function (x) { return fx; }]);


回答1:


JSXGraph comes with its own parser JessieCode (see https://github.com/jsxgraph/JessieCode) which does exactly this. JessieCode reads Math syntax, i.e. x^2 is converted to x*x, and hands over an object which can be plotted by JSXGraph.

Here is your example realized with JessieCode:

var fx = $("#fx").val();
var f = board.jc.snippet(fx, true, 'x', true);
var c1 = board.create('functiongraph', [f]);


来源:https://stackoverflow.com/questions/23927046/how-to-make-a-dynamic-function-to-draw-integral-graph-from-user-input-with-jsxgr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!