jsxgraph 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CHANGELOG.md +25 -2
  2. package/distrib/docs/files.html +2 -2
  3. package/distrib/docs/index.html +2 -2
  4. package/distrib/docs/static/jsxgraph.css +24 -22
  5. package/distrib/docs/static/jsxgraphcore.js +2 -2
  6. package/distrib/docs/symbols/Angle.html +2 -2
  7. package/distrib/docs/symbols/Arc.html +2 -2
  8. package/distrib/docs/symbols/Arrow.html +2 -2
  9. package/distrib/docs/symbols/Arrowparallel.html +2 -2
  10. package/distrib/docs/symbols/Axis.html +2 -2
  11. package/distrib/docs/symbols/Bisector.html +2 -2
  12. package/distrib/docs/symbols/Bisectorlines.html +2 -2
  13. package/distrib/docs/symbols/Boxplot.html +2 -2
  14. package/distrib/docs/symbols/Button.html +4 -4
  15. package/distrib/docs/symbols/Cardinalspline.html +2 -2
  16. package/distrib/docs/symbols/Chart.html +2 -2
  17. package/distrib/docs/symbols/Checkbox.html +17 -17
  18. package/distrib/docs/symbols/Circle.html +2 -2
  19. package/distrib/docs/symbols/Circumcenter.html +4 -4
  20. package/distrib/docs/symbols/Circumcircle.html +2 -2
  21. package/distrib/docs/symbols/CircumcircleArc.html +2 -2
  22. package/distrib/docs/symbols/CircumcircleSector.html +2 -2
  23. package/distrib/docs/symbols/Comb.html +5 -5
  24. package/distrib/docs/symbols/Conic.html +2 -2
  25. package/distrib/docs/symbols/Constants.html +2 -2
  26. package/distrib/docs/symbols/Curve.html +2 -2
  27. package/distrib/docs/symbols/Curve3D.html +2 -2
  28. package/distrib/docs/symbols/CurveDifference.html +2 -2
  29. package/distrib/docs/symbols/CurveIntersection.html +2 -2
  30. package/distrib/docs/symbols/CurveUnion.html +2 -2
  31. package/distrib/docs/symbols/Derivative.html +2 -2
  32. package/distrib/docs/symbols/Ellipse.html +2 -2
  33. package/distrib/docs/symbols/ForeignObject.html +4 -4
  34. package/distrib/docs/symbols/Functiongraph.html +2 -2
  35. package/distrib/docs/symbols/Functiongraph3D.html +2 -2
  36. package/distrib/docs/symbols/Glider.html +4 -4
  37. package/distrib/docs/symbols/Grid.html +2 -2
  38. package/distrib/docs/symbols/Group.html +2 -2
  39. package/distrib/docs/symbols/Hatch.html +2 -2
  40. package/distrib/docs/symbols/Hyperbola.html +2 -2
  41. package/distrib/docs/symbols/Image.html +4 -4
  42. package/distrib/docs/symbols/Incenter.html +4 -4
  43. package/distrib/docs/symbols/Incircle.html +2 -2
  44. package/distrib/docs/symbols/Inequality.html +2 -2
  45. package/distrib/docs/symbols/Input.html +4 -4
  46. package/distrib/docs/symbols/Integral.html +2 -2
  47. package/distrib/docs/symbols/Intersection.html +4 -4
  48. package/distrib/docs/symbols/JXG.AbstractRenderer.html +2 -2
  49. package/distrib/docs/symbols/JXG.Board.html +144 -11
  50. package/distrib/docs/symbols/JXG.Board.infobox.html +2 -2
  51. package/distrib/docs/symbols/JXG.C.html +2 -2
  52. package/distrib/docs/symbols/JXG.CA.html +2 -2
  53. package/distrib/docs/symbols/JXG.CanvasRenderer.html +2 -2
  54. package/distrib/docs/symbols/JXG.Chart.html +2 -2
  55. package/distrib/docs/symbols/JXG.Circle.html +2 -2
  56. package/distrib/docs/symbols/JXG.Complex.html +2 -2
  57. package/distrib/docs/symbols/JXG.Composition.html +2 -2
  58. package/distrib/docs/symbols/JXG.Coords.html +2 -2
  59. package/distrib/docs/symbols/JXG.CoordsElement.html +54 -2
  60. package/distrib/docs/symbols/JXG.Curve.html +2 -2
  61. package/distrib/docs/symbols/JXG.Curve3D.html +2 -2
  62. package/distrib/docs/symbols/JXG.Dump.html +2 -2
  63. package/distrib/docs/symbols/JXG.EventEmitter.html +2 -2
  64. package/distrib/docs/symbols/JXG.ForeignObject.html +3 -3
  65. package/distrib/docs/symbols/JXG.GeometryElement.html +2 -2
  66. package/distrib/docs/symbols/JXG.GeometryElement3D.html +2 -2
  67. package/distrib/docs/symbols/JXG.GeonextParser.html +2 -2
  68. package/distrib/docs/symbols/JXG.Group.html +2 -2
  69. package/distrib/docs/symbols/JXG.Image.html +3 -3
  70. package/distrib/docs/symbols/JXG.JSXGraph.html +2 -2
  71. package/distrib/docs/symbols/JXG.JessieCode.html +2 -2
  72. package/distrib/docs/symbols/JXG.Legend.html +2 -2
  73. package/distrib/docs/symbols/JXG.Line.html +2 -2
  74. package/distrib/docs/symbols/JXG.Line3D.html +2 -2
  75. package/distrib/docs/symbols/JXG.Math.Clip.html +2 -2
  76. package/distrib/docs/symbols/JXG.Math.Extrapolate.html +2 -2
  77. package/distrib/docs/symbols/JXG.Math.Geometry.html +2 -2
  78. package/distrib/docs/symbols/JXG.Math.IntervalArithmetic.html +2 -2
  79. package/distrib/docs/symbols/JXG.Math.Metapost.html +2 -2
  80. package/distrib/docs/symbols/JXG.Math.Nlp.html +2 -2
  81. package/distrib/docs/symbols/JXG.Math.Numerics.html +23 -15
  82. package/distrib/docs/symbols/JXG.Math.Plot.html +2 -2
  83. package/distrib/docs/symbols/JXG.Math.Poly.Monomial.html +2 -2
  84. package/distrib/docs/symbols/JXG.Math.Poly.Polynomial.html +2 -2
  85. package/distrib/docs/symbols/JXG.Math.Poly.Ring.html +2 -2
  86. package/distrib/docs/symbols/JXG.Math.Poly.html +2 -2
  87. package/distrib/docs/symbols/JXG.Math.ProbFuncs.html +2 -2
  88. package/distrib/docs/symbols/JXG.Math.Quadtree.html +122 -7
  89. package/distrib/docs/symbols/JXG.Math.Statistics.html +2 -2
  90. package/distrib/docs/symbols/JXG.Math.Symbolic.html +2 -2
  91. package/distrib/docs/symbols/JXG.Math.html +45 -2
  92. package/distrib/docs/symbols/JXG.NoRenderer.html +2 -2
  93. package/distrib/docs/symbols/JXG.Options.html +2 -2
  94. package/distrib/docs/symbols/JXG.Plane3D.html +2 -2
  95. package/distrib/docs/symbols/JXG.Point.html +3 -3
  96. package/distrib/docs/symbols/JXG.Point3D.html +2 -2
  97. package/distrib/docs/symbols/JXG.Polygon.html +2 -2
  98. package/distrib/docs/symbols/JXG.SVGRenderer.html +2 -2
  99. package/distrib/docs/symbols/JXG.Server.html +2 -2
  100. package/distrib/docs/symbols/JXG.Server.modules.html +2 -2
  101. package/distrib/docs/symbols/JXG.Surface3D.html +2 -2
  102. package/distrib/docs/symbols/JXG.Text.html +8 -8
  103. package/distrib/docs/symbols/JXG.Ticks.html +2 -2
  104. package/distrib/docs/symbols/JXG.Transformation.html +2 -2
  105. package/distrib/docs/symbols/JXG.Turtle.html +2 -2
  106. package/distrib/docs/symbols/JXG.Util.Base64.html +2 -2
  107. package/distrib/docs/symbols/JXG.Util.UTF8.html +2 -2
  108. package/distrib/docs/symbols/JXG.Util.Unzip.html +2 -2
  109. package/distrib/docs/symbols/JXG.Util.html +2 -2
  110. package/distrib/docs/symbols/JXG.VMLRenderer.html +2 -2
  111. package/distrib/docs/symbols/JXG.View3D.html +2 -2
  112. package/distrib/docs/symbols/JXG.XML.html +2 -2
  113. package/distrib/docs/symbols/Label.html +114 -4
  114. package/distrib/docs/symbols/Legend.html +2 -2
  115. package/distrib/docs/symbols/Line.html +2 -2
  116. package/distrib/docs/symbols/Line3D.html +2 -2
  117. package/distrib/docs/symbols/Locus.html +2 -2
  118. package/distrib/docs/symbols/MajorArc.html +2 -2
  119. package/distrib/docs/symbols/MajorSector.html +2 -2
  120. package/distrib/docs/symbols/Metapostspline.html +2 -2
  121. package/distrib/docs/symbols/Midpoint.html +4 -4
  122. package/distrib/docs/symbols/MinorArc.html +2 -2
  123. package/distrib/docs/symbols/MinorSector.html +2 -2
  124. package/distrib/docs/symbols/Mirrorelement.html +2 -2
  125. package/distrib/docs/symbols/Mirrorpoint.html +4 -4
  126. package/distrib/docs/symbols/NonReflexAngle.html +2 -2
  127. package/distrib/docs/symbols/Normal.html +2 -2
  128. package/distrib/docs/symbols/Orthogonalprojection.html +4 -4
  129. package/distrib/docs/symbols/OtherIntersection.html +4 -4
  130. package/distrib/docs/symbols/Parabola.html +2 -2
  131. package/distrib/docs/symbols/Parallel.html +2 -2
  132. package/distrib/docs/symbols/Parallelpoint.html +4 -4
  133. package/distrib/docs/symbols/ParametricSurface3D.html +2 -2
  134. package/distrib/docs/symbols/Perpendicular.html +2 -2
  135. package/distrib/docs/symbols/PerpendicularPoint.html +4 -4
  136. package/distrib/docs/symbols/PerpendicularSegment.html +2 -2
  137. package/distrib/docs/symbols/Point.html +4 -4
  138. package/distrib/docs/symbols/Point3D.html +2 -2
  139. package/distrib/docs/symbols/PolarLine.html +2 -2
  140. package/distrib/docs/symbols/PolePoint.html +4 -4
  141. package/distrib/docs/symbols/Polygon.html +2 -2
  142. package/distrib/docs/symbols/PolygonalChain.html +2 -2
  143. package/distrib/docs/symbols/RadicalAxis.html +2 -2
  144. package/distrib/docs/symbols/Reflection.html +2 -2
  145. package/distrib/docs/symbols/ReflexAngle.html +2 -2
  146. package/distrib/docs/symbols/RegularPolygon.html +2 -2
  147. package/distrib/docs/symbols/Riemannsum.html +7 -3
  148. package/distrib/docs/symbols/Sector.html +2 -2
  149. package/distrib/docs/symbols/Segment.html +2 -2
  150. package/distrib/docs/symbols/Semicircle.html +2 -2
  151. package/distrib/docs/symbols/Slider.html +145 -4
  152. package/distrib/docs/symbols/Slopefield.html +2 -2
  153. package/distrib/docs/symbols/Slopetriangle.html +2 -2
  154. package/distrib/docs/symbols/Smartlabel.html +4 -4
  155. package/distrib/docs/symbols/Spline.html +2 -2
  156. package/distrib/docs/symbols/Stepfunction.html +2 -2
  157. package/distrib/docs/symbols/Tangent.html +2 -2
  158. package/distrib/docs/symbols/Tapemeasure.html +2 -2
  159. package/distrib/docs/symbols/Text.html +4 -4
  160. package/distrib/docs/symbols/Ticks.html +2 -2
  161. package/distrib/docs/symbols/Tracecurve.html +2 -2
  162. package/distrib/docs/symbols/Transformation.html +2 -2
  163. package/distrib/docs/symbols/Turtle.html +2 -2
  164. package/distrib/docs/symbols/Vectorfield.html +2 -2
  165. package/distrib/docs/symbols/View3D.html +2 -2
  166. package/distrib/docs/symbols/_global_.html +2 -2
  167. package/distrib/docs/symbols/src/src_3d_view3d.js.html +29 -30
  168. package/distrib/docs/symbols/src/src_base_board.js.html +5020 -4930
  169. package/distrib/docs/symbols/src/src_base_constants.js.html +1 -1
  170. package/distrib/docs/symbols/src/src_base_coordselement.js.html +1829 -1789
  171. package/distrib/docs/symbols/src/src_base_curve.js.html +783 -778
  172. package/distrib/docs/symbols/src/src_base_text.js.html +345 -358
  173. package/distrib/docs/symbols/src/src_element_checkbox.js.html +30 -30
  174. package/distrib/docs/symbols/src/src_element_slider.js.html +391 -377
  175. package/distrib/docs/symbols/src/src_math_numerics.js.html +1226 -1190
  176. package/distrib/docs/symbols/src/src_math_qdt.js.html +318 -194
  177. package/distrib/docs/symbols/src/src_options.js.html +7137 -7034
  178. package/distrib/docs/symbols/src/src_renderer_abstract.js.html +1168 -1167
  179. package/distrib/docs/symbols/src/src_renderer_canvas.js.html +1 -1
  180. package/distrib/docs/symbols/src/src_renderer_svg.js.html +489 -494
  181. package/distrib/docs/symbols/src/src_utils_env.js.html +127 -90
  182. package/distrib/docs.zip +0 -0
  183. package/distrib/geogebra.min.js +1 -1
  184. package/distrib/geonext.min.js +1 -1
  185. package/distrib/intergeo.min.js +1 -1
  186. package/distrib/jsxgraph.css +24 -22
  187. package/distrib/jsxgraph.zip +0 -0
  188. package/distrib/jsxgraphcore.js +2 -2
  189. package/distrib/jsxgraphcore.mjs +2 -2
  190. package/distrib/jsxgraphcore.mjs.map +1 -1
  191. package/distrib/jsxgraphsrc.js +707 -276
  192. package/distrib/jsxgraphsrc.mjs +707 -276
  193. package/distrib/jsxgraphsrc.mjs.map +1 -1
  194. package/distrib/sketch.min.js +1 -1
  195. package/package.json +1 -1
  196. package/src/3d/view3d.js +0 -1
  197. package/src/base/board.js +140 -50
  198. package/src/base/constants.js +1 -1
  199. package/src/base/coordselement.js +54 -14
  200. package/src/base/curve.js +6 -1
  201. package/src/base/text.js +13 -26
  202. package/src/element/checkbox.js +17 -17
  203. package/src/element/slider.js +16 -2
  204. package/src/math/heap.js +34 -4
  205. package/src/math/numerics.js +112 -76
  206. package/src/math/qdt.js +141 -17
  207. package/src/options.js +115 -12
  208. package/src/renderer/abstract.js +15 -14
  209. package/src/renderer/canvas.js +1 -1
  210. package/src/renderer/svg.js +0 -5
  211. package/src/utils/env.js +75 -38
@@ -131,36 +131,36 @@ var priv = {
131
131
  * }, checkbox);
132
132
  * })();
133
133
  * </script><pre>
134
- *
135
134
  * @example
136
- * var i1 = board.create('input', [-3, 4, 'sin(x)', 'f(x)='], {cssStyle: 'width:4em', maxlength: 2});
137
- * var c1 = board.create('checkbox', [-3, 2, 'label 1'], {});
138
- * var b1 = board.create('button', [-3, -1, 'Change texts', function () {
139
- * i1.setText('g(x)');
135
+ * var i1 = board.create('input', [1, 5, 'sin(x)', 'f(x)='], {cssStyle: 'width:4em', maxlength: 2});
136
+ * var c1 = board.create('checkbox', [1, 3, 'label 1'], {});
137
+ * var b1 = board.create('button', [1, 1, 'Change texts', function () {
138
+ * i1.setText('g(x)=');
140
139
  * i1.set('cos(x)');
141
140
  * c1.setText('label 2');
142
141
  * b1.setText('Texts are changed');
143
142
  * }],
144
- * {cssStyle: 'width:400px'});
145
- *
146
- * </pre><div id="JXG11cac8gg-2354-47e7-9da4-eb298e53de05" class="jxgbox" style="width: 300px; height: 300px;"></div>
143
+ * {cssStyle: 'width:200px'});
144
+ *
145
+ * </pre><div id="JXG31c6d070-354b-4f09-aab9-9aaa796f730c" class="jxgbox" style="width: 300px; height: 300px;"></div>
147
146
  * <script type="text/javascript">
148
147
  * (function() {
149
- * var board = JXG.JSXGraph.initBoard('JXG11cac8gg-2354-47e7-9da4-eb298e53de05',
150
- * {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
151
- * var i1 = board.create('input', [-3, 4, 'sin(x)', 'f(x)='], {cssStyle: 'width:4em', maxlength: 2});
152
- * var c1 = board.create('checkbox', [-3, 2, 'label 1'], {});
153
- * var b1 = board.create('button', [-3, -1, 'Change texts', function () {
154
- * i1.setText('g(x)');
148
+ * var board = JXG.JSXGraph.initBoard('JXG31c6d070-354b-4f09-aab9-9aaa796f730c',
149
+ * {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false});
150
+ * var i1 = board.create('input', [1, 5, 'sin(x)', 'f(x)='], {cssStyle: 'width:4em', maxlength: 2});
151
+ * var c1 = board.create('checkbox', [1, 3, 'label 1'], {});
152
+ * var b1 = board.create('button', [1, 1, 'Change texts', function () {
153
+ * i1.setText('g(x)=');
155
154
  * i1.set('cos(x)');
156
155
  * c1.setText('label 2');
157
156
  * b1.setText('Texts are changed');
158
157
  * }],
159
- * {cssStyle: 'width:400px'});
160
- *
158
+ * {cssStyle: 'width:200px'});
159
+ *
161
160
  * })();
162
- *
161
+ *
163
162
  * </script><pre>
163
+ *
164
164
  */
165
165
  JXG.createCheckbox = function (board, parents, attributes) {
166
166
  var t,
@@ -168,6 +168,7 @@ JXG.createSlider = function (board, parents, attributes) {
168
168
  ticks, ti, t,
169
169
  startx, starty,
170
170
  withText, withTicks,
171
+ snapValues, snapValueDistance,
171
172
  snapWidth, sw, s,
172
173
  attr;
173
174
 
@@ -175,6 +176,8 @@ JXG.createSlider = function (board, parents, attributes) {
175
176
  withTicks = attr.withticks;
176
177
  withText = attr.withlabel;
177
178
  snapWidth = attr.snapwidth;
179
+ snapValues = attr.snapvalues;
180
+ snapValueDistance = attr.snapvaluedistance;
178
181
 
179
182
  // start point
180
183
  attr = Type.copyAttributes(attributes, board.options, "slider", "point1");
@@ -211,7 +214,7 @@ JXG.createSlider = function (board, parents, attributes) {
211
214
  attr.withLabel = false;
212
215
  // gliders set snapwidth=-1 by default (i.e. deactivate them)
213
216
  p3 = board.create("glider", [startx, starty, l1], attr);
214
- p3.setAttribute({ snapwidth: snapWidth });
217
+ p3.setAttribute({ snapwidth: snapWidth, snapvalues: snapValues, snapvaluedistance: snapValueDistance });
215
218
 
216
219
  // Segment from start point to glider point: highline
217
220
  attr = Type.copyAttributes(attributes, board.options, "slider", "highline");
@@ -226,7 +229,18 @@ JXG.createSlider = function (board, parents, attributes) {
226
229
  */
227
230
  p3.Value = function () {
228
231
  var sdiff = this._smax - this._smin,
229
- ev_sw = Type.evaluate(this.visProp.snapwidth);
232
+ ev_sw = Type.evaluate(this.visProp.snapwidth),
233
+ snapValues, i, v;
234
+
235
+ snapValues = Type.evaluate(this.visProp.snapvalues);
236
+ if (Type.isArray(snapValues)) {
237
+ for (i=0; i < snapValues.length; i++) {
238
+ v = (snapValues[i] - this._smin) / (this._smax - this._smin);
239
+ if(this.position === v) {
240
+ return snapValues[i];
241
+ }
242
+ }
243
+ }
230
244
 
231
245
  return ev_sw === -1
232
246
  ? this.position * sdiff + this._smin
package/src/math/heap.js CHANGED
@@ -33,10 +33,17 @@
33
33
  /*jslint nomen: true, plusplus: true*/
34
34
 
35
35
  import Mat from "./math";
36
- import Type from "../utils/type";
37
36
 
38
37
  /**
39
- * Heap
38
+ * Instantiate a new heap.
39
+ * Elements of the heap are objects (node) with a property <tt>v</tt>.
40
+ * <p>
41
+ * The heap nodes are stored in a JavaScript array.
42
+ *
43
+ * @name JXG.Math.Heap
44
+ * @exports Mat.Heap as JXG.Math.Heap
45
+ *
46
+ * @constructor
40
47
  */
41
48
  Mat.Heap = function () {
42
49
  this.pq = [];
@@ -44,19 +51,28 @@ Mat.Heap = function () {
44
51
  };
45
52
 
46
53
  /**
47
- * public
54
+ * Clear the heap, i.e. remove all nodes.
48
55
  */
49
56
  Mat.Heap.prototype.empty = function () {
50
57
  this.pq = [];
51
58
  this.N = 0;
52
59
  };
53
60
 
61
+ /**
62
+ * Insert element <tt>node</tt>into heap. An element is an object having at least the property <tt>v</tt>.
63
+ * @param {Object} node
64
+ */
54
65
  Mat.Heap.prototype.insert = function (node) {
55
66
  this.pq[this.N] = node;
56
67
  this.N++;
57
68
  this.fixUp(this.N);
58
69
  };
59
70
 
71
+ /**
72
+ * Remove and return largest node in heap.
73
+ *
74
+ * @returns largest (in respect to property <tt>v</tt>) node
75
+ */
60
76
  Mat.Heap.prototype.delmax = function () {
61
77
  this.exchange(0, this.N - 1);
62
78
  this.fixDown(0, this.N - 1);
@@ -66,7 +82,9 @@ Mat.Heap.prototype.delmax = function () {
66
82
  };
67
83
 
68
84
  /**
69
- * private
85
+ * Restore heap properties from position k, i.e. positions < k.
86
+ * @param {Number} k
87
+ * @private
70
88
  */
71
89
  Mat.Heap.prototype.fixUp = function (k) {
72
90
  var i = k - 1;
@@ -77,9 +95,16 @@ Mat.Heap.prototype.fixUp = function (k) {
77
95
  }
78
96
  };
79
97
 
98
+ /**
99
+ * Restore heap properties between positions k and N.
100
+ * @param {Number} k
101
+ * @param {Number} N
102
+ * @private
103
+ */
80
104
  Mat.Heap.prototype.fixDown = function (k, N) {
81
105
  var j,
82
106
  i = k;
107
+
83
108
  while (2 * i < N) {
84
109
  j = 2 * i;
85
110
 
@@ -96,6 +121,11 @@ Mat.Heap.prototype.fixDown = function (k, N) {
96
121
  }
97
122
  };
98
123
 
124
+ /**
125
+ * Swap heap elements at position i and j
126
+ * @param {Number} i
127
+ * @param {Number} j
128
+ */
99
129
  Mat.Heap.prototype.exchange = function (i, j) {
100
130
  var t = this.pq[i];
101
131
  this.pq[i] = this.pq[j];
@@ -2960,12 +2960,18 @@ Mat.Numerics = {
2960
2960
  /**
2961
2961
  * Helper function to create curve which displays Riemann sums.
2962
2962
  * Compute coordinates for the rectangles showing the Riemann sum.
2963
+ * <p>
2964
+ * In case of type "simpson" and "trapezoidal", the horizontal line approximating the function value
2965
+ * is replaced by a parabola or a secant. IN case of "simpson",
2966
+ * the parabola is approximated visually by a polygonal chain of fixed step width.
2967
+ *
2963
2968
  * @param {Function,Array} f Function or array of two functions.
2964
2969
  * If f is a function the integral of this function is approximated by the Riemann sum.
2965
2970
  * If f is an array consisting of two functions the area between the two functions is filled
2966
2971
  * by the Riemann sum bars.
2967
2972
  * @param {Number} n number of rectangles.
2968
2973
  * @param {String} type Type of approximation. Possible values are: 'left', 'right', 'middle', 'lower', 'upper', 'random', 'simpson', or 'trapezoidal'.
2974
+ * "simpson" is Simpson's 1/3 rule.
2969
2975
  * @param {Number} start Left border of the approximation interval
2970
2976
  * @param {Number} end Right border of the approximation interval
2971
2977
  * @returns {Array} An array of two arrays containing the x and y coordinates for the rectangles showing the Riemann sum. This
@@ -2974,18 +2980,14 @@ Mat.Numerics = {
2974
2980
  * @memberof JXG.Math.Numerics
2975
2981
  */
2976
2982
  riemann: function (gf, n, type, start, end) {
2977
- var i,
2978
- delta,
2983
+ var i, delta,
2984
+ k, a, b, c, f0, f1, f2, xx, h,
2985
+ steps = 30, // Fixed step width for Simpson's rule
2979
2986
  xarr = [],
2980
2987
  yarr = [],
2981
- j = 0,
2982
2988
  x = start,
2983
- y,
2984
2989
  sum = 0,
2985
- f,
2986
- g,
2987
- ylow,
2988
- yup;
2990
+ y, f, g;
2989
2991
 
2990
2992
  if (Type.isArray(gf)) {
2991
2993
  g = gf[0];
@@ -3002,61 +3004,94 @@ Mat.Numerics = {
3002
3004
 
3003
3005
  delta = (end - start) / n;
3004
3006
 
3005
- // Upper bar ends
3006
- for (i = 0; i < n; i++) {
3007
- y = this._riemannValue(x, f, type, delta);
3008
- xarr[j] = x;
3009
- yarr[j] = y;
3010
-
3011
- j += 1;
3012
- x += delta;
3013
- if (type === "trapezoidal") {
3014
- y = f(x);
3015
- }
3016
- xarr[j] = x;
3017
- yarr[j] = y;
3018
-
3019
- j += 1;
3020
- }
3021
-
3022
- // Lower bar ends
3007
+ // "Upper" horizontal line defined by function
3023
3008
  for (i = 0; i < n; i++) {
3024
- if (g) {
3025
- y = this._riemannValue(x, g, type, -delta);
3009
+ if (type === "simpson") {
3010
+ sum += this._riemannValue(x, f, type, delta) * delta;
3011
+
3012
+ h = delta * 0.5;
3013
+ f0 = f(x);
3014
+ f1 = f(x + h);
3015
+ f2 = f(x + 2 * h);
3016
+
3017
+ a = (f2 + f0 - 2 * f1) / (h * h) * 0.5;
3018
+ b = (f2 - f0) / (2 * h);
3019
+ c = f1;
3020
+ for (k = 0; k < steps; k++) {
3021
+ xx = k * delta / steps - h;
3022
+ xarr.push(x + xx + h);
3023
+ yarr.push(a * xx * xx + b * xx + c);
3024
+ }
3025
+ x += delta;
3026
+ y = f2;
3026
3027
  } else {
3027
- y = 0.0;
3028
- }
3029
- xarr[j] = x;
3030
- yarr[j] = y;
3028
+ y = this._riemannValue(x, f, type, delta);
3029
+ xarr.push(x);
3030
+ yarr.push(y);
3031
+
3032
+ x += delta;
3033
+ if (type === "trapezoidal") {
3034
+ f2 = f(x);
3035
+ sum += (y + f2) * 0.5 * delta;
3036
+ y = f2;
3037
+ } else {
3038
+ sum += y * delta;
3039
+ }
3031
3040
 
3032
- j += 1;
3033
- x -= delta;
3034
- if (type === "trapezoidal" && g) {
3035
- y = g(x);
3041
+ xarr.push(x);
3042
+ yarr.push(y);
3036
3043
  }
3037
- xarr[j] = x;
3038
- yarr[j] = y;
3044
+ xarr.push(x);
3045
+ yarr.push(y);
3046
+ }
3039
3047
 
3040
- // Add the area of the bar to 'sum'
3041
- if (type !== "trapezoidal") {
3042
- ylow = y;
3043
- yup = yarr[2 * (n - 1) - 2 * i];
3048
+ // "Lower" horizontal line
3049
+ // Go backwards
3050
+ for (i = 0; i < n; i++) {
3051
+ if (type === "simpson" && g) {
3052
+ sum -= this._riemannValue(x, g, type, -delta) * delta;
3053
+
3054
+ h = delta * 0.5;
3055
+ f0 = g(x);
3056
+ f1 = g(x - h);
3057
+ f2 = g(x - 2 * h);
3058
+
3059
+ a = (f2 + f0 - 2 * f1) / (h * h) * 0.5;
3060
+ b = (f2 - f0) / (2 * h);
3061
+ c = f1;
3062
+ for (k = 0; k < steps; k++) {
3063
+ xx = k * delta / steps - h;
3064
+ xarr.push(x - xx - h);
3065
+ yarr.push(a * xx * xx + b * xx + c);
3066
+ }
3067
+ x -= delta;
3068
+ y = f2;
3044
3069
  } else {
3045
- yup = 0.5 * (f(x + delta) + f(x));
3046
3070
  if (g) {
3047
- ylow = 0.5 * (g(x + delta) + g(x));
3071
+ y = this._riemannValue(x, g, type, -delta);
3048
3072
  } else {
3049
- ylow = 0.0;
3073
+ y = 0.0;
3074
+ }
3075
+ xarr.push(x);
3076
+ yarr.push(y);
3077
+
3078
+ x -= delta;
3079
+ if (g) {
3080
+ if (type === "trapezoidal") {
3081
+ f2 = g(x);
3082
+ sum -= (y + f2) * 0.5 * delta;
3083
+ y = f2;
3084
+ } else {
3085
+ sum -= y * delta;
3086
+ }
3050
3087
  }
3051
3088
  }
3052
- sum += (yup - ylow) * delta;
3089
+ xarr.push(x);
3090
+ yarr.push(y);
3053
3091
 
3054
3092
  // Draw the vertical lines
3055
- j += 1;
3056
- xarr[j] = x;
3057
- yarr[j] = yarr[2 * (n - 1) - 2 * i];
3058
-
3059
- j += 1;
3093
+ xarr.push(x);
3094
+ yarr.push(f(x));
3060
3095
  }
3061
3096
 
3062
3097
  return [xarr, yarr, sum];
@@ -3082,12 +3117,12 @@ Mat.Numerics = {
3082
3117
  * @memberof JXG.Math.Numerics
3083
3118
  */
3084
3119
  riemannsum: function (f, n, type, start, end) {
3085
- JXG.deprecated("Numerics.riemannsum()", "Numerics.riemann()");
3120
+ JXG.deprecated("Numerics.riemannsum()", "Numerics.riemann()[2]");
3086
3121
  return this.riemann(f, n, type, start, end)[2];
3087
3122
  },
3088
3123
 
3089
3124
  /**
3090
- * Solve initial value problems numerically using Runge-Kutta-methods.
3125
+ * Solve initial value problems numerically using <i>explicit</i> Runge-Kutta methods.
3091
3126
  * See {@link https://en.wikipedia.org/wiki/Runge-Kutta_methods} for more information on the algorithm.
3092
3127
  * @param {object,String} butcher Butcher tableau describing the Runge-Kutta method to use. This can be either a string describing
3093
3128
  * a Runge-Kutta method with a Butcher tableau predefined in JSXGraph like 'euler', 'heun', 'rk4' or an object providing the structure
@@ -3099,18 +3134,20 @@ Mat.Numerics = {
3099
3134
  * c: &lt;Array&gt;
3100
3135
  * }
3101
3136
  * </pre>
3102
- * which corresponds to the Butcher tableau structure shown here: https://en.wikipedia.org/w/index.php?title=List_of_Runge%E2%80%93Kutta_methods&oldid=357796696
3103
- * @param {Array} x0 Initial value vector. If the problem is of one-dimensional, the initial value also has to be given in an array.
3137
+ * which corresponds to the Butcher tableau structure
3138
+ * shown here: https://en.wikipedia.org/w/index.php?title=List_of_Runge%E2%80%93Kutta_methods&oldid=357796696 .
3139
+ * <i>Default</i> is 'euler'.
3140
+ * @param {Array} x0 Initial value vector. Even if the problem is one-dimensional, the initial value has to be given in an array.
3104
3141
  * @param {Array} I Interval on which to integrate.
3105
- * @param {Number} N Number of evaluation points.
3142
+ * @param {Number} N Number of integration intervals, i.e. there are <i>N+1</i> evaluation points.
3106
3143
  * @param {function} f Function describing the right hand side of the first order ordinary differential equation, i.e. if the ode
3107
- * is given by the equation <pre>dx/dt = f(t, x(t)).</pre> So f has to take two parameters, a number <tt>t</tt> and a
3108
- * vector <tt>x</tt>, and has to return a vector of the same dimension as <tt>x</tt> has.
3144
+ * is given by the equation <pre>dx/dt = f(t, x(t))</pre>. So, f has to take two parameters, a number <tt>t</tt> and a
3145
+ * vector <tt>x</tt>, and has to return a vector of the same length as <tt>x</tt> has.
3109
3146
  * @returns {Array} An array of vectors describing the solution of the ode on the given interval I.
3110
3147
  * @example
3111
3148
  * // A very simple autonomous system dx(t)/dt = x(t);
3112
- * function f(t, x) {
3113
- * return x;
3149
+ * var f = function(t, x) {
3150
+ * return [x[0]];
3114
3151
  * }
3115
3152
  *
3116
3153
  * // Solve it with initial value x(0) = 1 on the interval [0, 2]
@@ -3121,7 +3158,8 @@ Mat.Numerics = {
3121
3158
  * var dataX = [];
3122
3159
  * var dataY = [];
3123
3160
  * var h = 0.1; // (I[1] - I[0])/N = (2-0)/20
3124
- * for(var i=0; i&lt;data.length; i++) {
3161
+ * var i;
3162
+ * for(i=0; i&lt;data.length; i++) {
3125
3163
  * dataX[i] = i*h;
3126
3164
  * dataY[i] = data[i][0];
3127
3165
  * }
@@ -3129,7 +3167,7 @@ Mat.Numerics = {
3129
3167
  * </pre><div class="jxgbox" id="JXGd2432d04-4ef7-4159-a90b-a2eb8d38c4f6" style="width: 300px; height: 300px;"></div>
3130
3168
  * <script type="text/javascript">
3131
3169
  * var board = JXG.JSXGraph.initBoard('JXGd2432d04-4ef7-4159-a90b-a2eb8d38c4f6', {boundingbox: [-1, 5, 5, -1], axis: true, showcopyright: false, shownavigation: false});
3132
- * function f(t, x) {
3170
+ * var f = function(t, x) {
3133
3171
  * // we have to copy the value.
3134
3172
  * // return x; would just return the reference.
3135
3173
  * return [x[0]];
@@ -3148,11 +3186,7 @@ Mat.Numerics = {
3148
3186
  */
3149
3187
  rungeKutta: function (butcher, x0, I, N, f) {
3150
3188
  var e,
3151
- i,
3152
- j,
3153
- k,
3154
- l,
3155
- s,
3189
+ i, j, k, l, s,
3156
3190
  x = [],
3157
3191
  y = [],
3158
3192
  h = (I[1] - I[0]) / N,
@@ -3167,17 +3201,19 @@ Mat.Numerics = {
3167
3201
  s = butcher.s;
3168
3202
 
3169
3203
  // don't change x0, so copy it
3170
- for (e = 0; e < dim; e++) {
3171
- x[e] = x0[e];
3172
- }
3204
+ // for (e = 0; e < dim; e++) {
3205
+ // x[e] = x0[e];
3206
+ // }
3207
+ x = x0.slice();
3173
3208
 
3174
- for (i = 0; i < N; i++) {
3209
+ for (i = 0; i <= N; i++) {
3175
3210
  // Optimization doesn't work for ODEs plotted using time
3176
3211
  // if((i % quotient == 0) || (i == N-1)) {
3177
- result[r] = [];
3178
- for (e = 0; e < dim; e++) {
3179
- result[r][e] = x[e];
3180
- }
3212
+ // result[r] = [];
3213
+ // for (e = 0; e < dim; e++) {
3214
+ // result[r][e] = x[e];
3215
+ // }
3216
+ result[r] = x.slice();
3181
3217
 
3182
3218
  r += 1;
3183
3219
  k = [];
@@ -3250,7 +3286,7 @@ Mat.Numerics = {
3250
3286
  * @param {Function} f Function, whose root is to be found
3251
3287
  * @param {Number} x0 Start value
3252
3288
  * @param {Object} object Parent object in case f is method of it
3253
- * @returns {Array} [x_0, f(x_0), x_1, f(x_1)] in case that x_0 <= x_1
3289
+ * @returns {Array} [x_0, f(x_0), x_1, f(x_1)] in case that x_0 <= x_1
3254
3290
  * or [x_1, f(x_1), x_0, f(x_0)] in case that x_1 < x_0.
3255
3291
  *
3256
3292
  * @see JXG.Math.Numerics.fzero