user3679616
user3679616

Reputation: 19

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

Fx from user input

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; }]); GRaph FX from user input

Upvotes: 0

Views: 1033

Answers (1)

Alfred Wassermann
Alfred Wassermann

Reputation: 2323

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]);

Upvotes: 1

Related Questions