how to make a dynamic function integral Graph from user input

167 views
Skip to first unread message

vengg...@gmail.com

unread,
May 29, 2014, 11:31:05 PM5/29/14
to jsxg...@googlegroups.com
i have a problem to make a dynamic graph from this library http://jsxgraph.uni-bayreuth.de/docs/symbols/Integral.html

i have made a dynamic x1 and x2 from user input and it is success (oh yeahhhh!!!) 
var c1 = board.create('functiongraph', [function (t) { return t*t*t; }]);
var i1 = board.create('integral', [[x1,x2], 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; }]); 



i have tried this but it doesn`t draw anything ? any solutions ?

Murray Bourne

unread,
May 29, 2014, 11:41:53 PM5/29/14
to jsxg...@googlegroups.com
Hi Venggeance

You need to use an "eval" as per this example:


I've been trying to do it without the evils of eval, but haven't figured out how, yet.


Regards,
Murray Bourne
                                                                        
Interactive Mathematics: http://www.intmath.com/


--
You received this message because you are subscribed to the Google Groups "JSXGraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsxgraph+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

calvin sugianto

unread,
May 30, 2014, 12:42:48 AM5/30/14
to jsxg...@googlegroups.com
hi Murray, it works , thanks bro
but now the problem is when i input x^2 or 3x or cos(x) , it doesn`t work, do you have any idea to generate it to becomes x*x , 3*x , Math.cos(x) ?
and the image of cursor {+,-, <- , -> } doesn`t appear, what`s the problem anyway?


Best Regards,
Calvin
bug.JPG

calvin sugianto

unread,
May 30, 2014, 1:03:18 AM5/30/14
to jsxg...@googlegroups.com
i have solved the 3x, 2x , 9x,etc problems
with this code:
fx2 = fx.replace(/(\d)\s*x/g,"$1 * x");
 

Alfred Wassermann

unread,
May 30, 2014, 2:25:16 AM5/30/14
to jsxg...@googlegroups.com

Depending on the application, the use of eval() may not be the most secure way to convert a function term into a JavaScript function. JSXGraph comes with its own parser JessieCode (see https://github.com/jsxgraph/JessieCode). JessieCode reads Math synatx, i.e. x^2 is converted to x*x, …

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

Best wishes,
Alfred

Message has been deleted

calvin sugianto

unread,
May 30, 2014, 7:39:02 AM5/30/14
to jsxg...@googlegroups.com
oh Yeahhhh, it works bro, Thx a lot Alfred

how to make the button image {+,-, <- , -> } appear?
because in my web, the symbol change into the weird symbol 

Alfred Wassermann

unread,
May 30, 2014, 8:25:37 AM5/30/14
to jsxg...@googlegroups.com

This is probably an encoding problem. If possible, try enforcing UTF-8 encoding on your websites:

<meta http-equiv="content-type" content="text/html;charset=utf-8">

Best wishes,
Alfred

calvin sugianto

unread,
May 30, 2014, 10:42:28 AM5/30/14
to jsxg...@googlegroups.com
thank you very much Alfred, it works, but what is encoding mean and it`s functionality

Alfred Wassermann

unread,
May 30, 2014, 11:08:57 AM5/30/14
to jsxg...@googlegroups.com
UTF-8 is the the name of the encoding system how text is converted into bits.
See http://en.wikipedia.org/wiki/UTF-8

Best wishes,
Alfred


Reply all
Reply to author
Forward
0 new messages