josdejong / mathjs

An extensive math library for JavaScript and Node.js
https://mathjs.org
Apache License 2.0
14.43k stars 1.24k forks source link

the rocket_trajectory_optimization example throw an error and not works #3323

Closed iahu closed 1 week ago

iahu commented 1 week ago

Describe the bug it throw an error, and no chart be rendered.

object.js:43 Uncaught TypeError: Cannot clone: unknown type of value (value: function se(e,t){return arguments.length===J&&C(e)&&_(t)?H.apply(this,arguments):arguments.length===X&&T(e)&&k(t)?G.apply(this,arguments):arguments.length===Q&&D(e)&&P(t)?V.apply(this,arguments):arguments.length===K&&F(e)&&U(t)?W.apply(this,arguments):arguments.length===ee&&O(e)&&L(t)?Z.apply(this,arguments):arguments.length===te&&B(e)&&$(t)?Y.apply(this,arguments):ae.apply(this,arguments)})
    at ae (object.js:43:9)
    at object.js:31:14
    at Array.map (<anonymous>)
    at ae (object.js:30:14)
    at new DenseMatrix (DenseMatrix.js:30:22)
    at r.map (DenseMatrix.js:603:20)
    at ndsolve (rocket_trajectory_optimization.html:46:24)
    at FunctionNode.js:208:24
    at AssignmentNode.js:133:25
    at Object.evaluate (Node.js:54:16)
ae @ object.js:43
(anonymous) @ object.js:31
ae @ object.js:30
DenseMatrix @ DenseMatrix.js:30
r.map @ DenseMatrix.js:603
ndsolve @ rocket_trajectory_optimization.html:46
(anonymous) @ FunctionNode.js:208
(anonymous) @ AssignmentNode.js:133
evaluate @ Node.js:54
string, Map | Object @ evaluate.js:53
evaluate @ typed-function.js:1468
n.evaluate @ Parser.js:83
(anonymous) @ rocket_trajectory_optimization.html:99

To Reproduce see it online

josdejong commented 1 week ago

It turns out that #3251 made a change that first creates a clone of the matrix, function clone did not support functions, and the Rocket example creates a matrix with functions and maps of that.

Solved by adding support for cloning functions to function clone via https://github.com/josdejong/mathjs/commit/e00d3678c6a347608db1bc44aeb6b27be415ed0d

josdejong commented 1 week ago

Fixed now in v13.2.3