const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5],
axis: true
});
var c1 = board.create('curve', [
function(t) {
var val = Math.cos(t);
if (val < 0.5) {
return val;
} else {
return NaN;
}
},
function(t) {
return Math.sin(t) + t;
},
-2 * Math.PI,
2 * Math.PI
], {strokeWidth: 3});
var A = board.create('point', [0,0], {visible: function() { return (A.X() < 0) ? true : false; }});
A = board.create('point', [0,0]);
A.on('drag', function() {
if (A.X() < 0) {
A.moveTo([0, A.Y()]);
}
});
y=x^2{1<y<5}{x<2}
var c = board.create('curve', [function (t) {
if (t < 2) {
return t;
} else {
return NaN;
}
}, func('x^2'), 1, 5], set);
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-6, 6, 6, -6],
axis: true
});
// User input
var txt = 'x^2'; // Input from user
var f = board.jc.snippet(txt, true, 'x', true); // Create a JavaScript function from the user input
// Restrictions
var x_interval = [-Infinity, 2];
var y_interval = [1, 5];
// Wrapper function
var wrap = function(x) {
var y = f(x);
if (x_interval[0] < x && x < x_interval[1] &&
y_interval[0] < y && y < y_interval[1]
) {
return y;
} else {
return NaN;
}
}
board.create('functiongraph', [wrap, -10, 10]);
e^(x*log(x))
JXG.Math.mod(x,6)
mod(x,6)
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5],
axis: true
});
var f = board.jc.snippet('EULER^(x*log(x))', true, 'x', true);
board.create('functiongraph', [f]);
var g = board.jc.snippet('x % 6', true, 'x', true);
board.create('functiongraph', [g]);
board.create('functiongraph', [
function(x) { return JXG.Math.Statistics.mean([x, 1, 2, 3]); }
]);
f = 'function(x) { return ' + eq + '; }';
var eq = 'JXG.Math.Statistics.mean([x, 1, 2, 3]'; // User input, i am formatting it like that to pass to jsx. Formatting other stat functions too like that.
var key = 'somekey';
var set = {
name: key,
strokeWidth: 2,
strokeColor: "#333333",
withLabel: false,
highlightStrokeColor: "#333333",
needsRegularUpdate: true,
};
obj_graph[key] = board.create('curve', [function (t) {
return t;
},
func(eq)], set);
var func = function(fun) {
var evl = eval("g = function(x){ with(Math) return " + mathjs(fun) + " }");
return evl;
}
var set = {
strokeWidth: 2,
// ... some more attributes
};
// The function (in x) which we want to plot
var eq = 'JXG.Math.Statistics.mean([x, 1, 2, 3])';
var func = function(fun) {
// Create a JavaScript function.
// var g = new Function('x', 'with (Math) return ' + mathjs(fun) + ';');
var g = new Function('x', 'with (Math) return ' + fun + ';');
// Restrictions
var x_interval = [-Infinity, 2];
var y_interval = [1, 5];
// Wrapper function
var wrap = function(x) {
var y = g(x);
if (x_interval[0] < x && x < x_interval[1] &&
y_interval[0] < y && y < y_interval[1]
) {
return y;
} else {
return NaN;
}
};
return wrap;
}
board.create('functiongraph', [func(eq)], set);
var set = {
name: 'name',
strokeWidth: 2,
strokeColor: "#333333",
withLabel: false,
highlightStrokeColor: "#333333",
needsRegularUpdate: true,
};
function generateWrapper(eq, key){
var x_start,x_end,y_start,y_end;
// Parse and Get ranges defined in equation.
// Returns like [-Infinity, Infinity, -Infinity, Infinity]
var vals = calculateRanges(key);
x_start = vals[0];
x_end = vals[1];
y_start = vals[2];
y_end = vals[3];
// Creates a JavaScript function.
// var g = new Function('x', 'with (Math) return ' + mathjs(eq) + ';');var g = new Function('x', 'with (Math) return ' + eq + ';');// Restrictions
var x_interval = [x_start, x_end];
var y_interval = [y_start, y_end];
// Wrapper js function.
var wrap = function(x) {
//var y = f(x);
var y = g(x);
if (x_interval[0] < x && x < x_interval[1] &&
y_interval[0] < y && y < y_interval[1]
) {
return y;
} else {
return NaN;
}
}
return wrap;
}
// Plotting with xcoordinats limists while plotting curve.obj_graph[key] = board.create('curve', [wrap,
function (t) {
return t;
},-5000,5000], set);
// Plotting withOUT xcoordinats limists while plotting curve. DEFAULT VALUE IS BEING SET TO [-10 10]obj_graph[key] = board.create('curve', [wrap,
function (t) {
return t;
}], set);
board.create('curve', [X, Y, a, b]);// Zoom settings
var zoom_setting = {
enabled: true,
factorX: 1.75,
factorY: 1.75,
wheel: true,
needShift: false,
min: 0.01,
max: 5000.0,
pinchHorizontal: true,
pinchVertical: true,
pinchSensitivity: 7,
keepaspectratio:true
};
// Pan settings
var pan_setting = {
needTwoFingers: false,
needShift: false,
needCtrl: false,
enabled: true
};
// Default settings with bondingbox, which displays grids.
var default_setting = {boundingbox:[-10,10,10,-10],xlabel:'', grid:true,
keepaspectratio:true, axis:false,showNavigation:true,zoom:zoom_setting,
needsRegularUpdate: true, pan:pan_setting };
x_axis = board.create('axis', [[0, 0], [1, 0]], {name:new_setting.xlabel,
withLabel: true, label: {position: 'rt', offset: [-15, 20]},
margin: 0,ticks: {drawLabels: new_setting.axis_number, ticksDistance: 5},
lastArrow: false,needsRegularUpdate: true});
y_axis = board.create('axis', [[0, 0], [0, 1]], {name:new_setting.ylabel,
withLabel: true,label: {position: 'top',offset: [-20, 0] },
margin: -30,ticks: {drawLabels: new_setting.axis_number,
ticksDistance: 5}, lastArrow: false,needsRegularUpdate: true});
recursionDepthHigh: 17,
recursionDepthLow: 13
var set = {
name: 'name',
strokeWidth: 2,
strokeColor: "#333333",
withLabel: false,
highlightStrokeColor: "#333333",
needsRegularUpdate: true,
recursionDepthLow: 16,
recursionDepthLow: 17
};
board.create('curve', [wrap,
function (t) {
return t;I am irritated now...