1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
<html>
<head>
<title>JSXGraph example</title>
<link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" />
<script type="text/javascript" src="/javascript/prototype/prototype.js"></script>
<script type="text/javascript" src="../distrib/jsxgraphcore.js"></script>
</head>
<body>
<h2>Funktionsplotter-Beispiel mit Eingabefenster</h2>
<div style="width:960px">
<div id="jxgbox" class="jxgbox" style="width:600px; height:400px; /* float:left;*/ "></div>
<p style="/*float:right*/">
<textarea id="eingabe" rows=15 cols=35 wrap="off" >
function f(x) {
return Math.sin(x)*Math.cos(x)*p.X();
}
c = plot(f);
g = JXG.Math.Numerics.D(f);
plot(g,{strokecolor:'black', dash:1});
h = JXG.Math.Numerics.D(g);
plot(h, {strokecolor:'red', dash:2});
var interval = [0, 2.5];
i_m = JXG.Math.Numerics.I(interval, f);
board.createElement('integral', [interval, c]);
</textarea> <br>
<input type="button" value="run" onClick="doIt()" style='margin:1em'>
<input type="button" value="clear all" onClick="board=clearAll(board)">
</p>
</div>
<br clear=all>
<div id="debug" style="display:block;"></div>
<script type="text/javascript">
/* <![CDATA[ */
board = JXG.JSXGraph.initBoard('jxgbox', {originX: 250, originY: 250, unitX: 40, unitY: 20});
// Axes
b1axisx = board.createElement('axis', [[0,0], [1,0]], {});
b1axisy = board.createElement('axis', [[0,0], [0,1]], {});
// Macro Function plotter
function funktionsPlotter(board, func, atts) {
var f = board.createElement('functiongraph', [func], atts);
return f;
}
// Simplified plotting function
function plot(func, atts) {
if (atts==null) {
return funktionsPlotter(board, func, {strokewidth:2});
} else {
return funktionsPlotter(board, func, atts);
}
}
/**
* Expand math expression which suppressed multiplication dot.
* Examples
* 2x -> 2*x
* (2+3)(3+1) -> (2+3)*(3+1)
* Attention with exponention:
* x^2x -> x^2*x
*/
expandShortMath = function(expr) {
var re = /([\)0-9\.])\s*([\(a-zA-Z_])/g;
return expr.replace(re, '$1*$2');
};
function plotjc(func, atts) {
/*String func */
func = expandShortMath(func);
console.log(func);
if (atts==null) {
return funktionsPlotter(board, func, {strokewidth:2});
} else {
return funktionsPlotter(board, func, atts);
}
}
// Free point
var p = board.createElement('point', [3,-4], {style:6, name:'drag me'});
// Usage of the macro
function doIt() {
var s = $('eingabe').value;
eval(s); // Attention: eval considered harmful
}
function clearAll(board) {
JXG.JSXGraph.freeBoard(board);
board = JXG.JSXGraph.initBoard('jxgbox', {originX: 250, originY: 250, unitX: 40, unitY: 20});
b1axisx = board.createElement('axis', [[0,0], [1,0]], {});
b1axisy = board.createElement('axis', [[0,0], [0,1]], {});
return board;
}
/*
i_s = board.I(interval, f);
*/
/* ]]> */
</script>
</body>
</html>
|