I hate that I'm asking this question but I've been through every single stack overflow post tagged with mathjs or math.js and a whole load of posts with "x is not a function" but none of them are relevant or helpful. Here is the full stack trace I get in Google Chrome:
Uncaught TypeError: v is not a function
at p (math.js:1741)
at typed (eval at p (math.js:1740), <anonymous>:15:16)
at Object.r [as factory] (math.js:15041)
at t (math.js:232)
at Object.n [as factory] (math.js:30335)
at t (math.js:232)
at Object.n [as factory] (math.js:30256)
at t (math.js:232)
at Object.n [as factory] (math.js:29710)
at t (math.js:232)
Notice how none of the error points to my code, and I get the same exact error if I try to call any math methods in the console.
I'm using p5.js just to make a little interactive thing for my website and I need the expression parsing functionality of math.js.
Here's my html file:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2D plotter</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.3.0/math.min.js"></script> <!-- here's where I load math.js from a cdn -->
<!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) -->
<script language="javascript" type="text/javascript" src="libraries/p5.min.js"></script>
<script language="javascript" type="text/javascript" src="Function.js"></script>
<script language="javascript" type="text/javascript" src="Plot.js"></script>
<script language="javascript" type="text/javascript" src="WebsitePlotter2D.js"></script>
<!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN -->
<!-- This line removes any default padding and style.
You might only need one of these values set. -->
<style> body { padding: 0; margin: 0; } </style>
</head>
<body>
</body>
</html>
The "please no changes" lines were there when the Processing editor generated the original html file, and I haven't messed with it. And here the code that calls on the math.js library, although at this point I'm convinced it's irrelevant:
draw() {
let lastPoint = null;
let nx, ny, y;
const parser = math.parser();
stroke(this.lineColor);
strokeWeight(this.lineWeight);
for (let xv=this.plot.xStart; xv<this.plot.xStop; xv+=this.step) {
parser.set('x', xv);
y = parser.evaluate(this.func);
ny = this.plot.scalePixelY(y);
nx = this.plot.scalePixelX(xv);
if (lastPoint !== null && 4) {
line(lastPoint.xVal, lastPoint.yVal, nx, ny);
}
lastPoint = {xVal: nx, yVal: ny,};
}
}
Also if I go to the lines in math.js referenced in the traceback there is no method call or even variable name of v
so I'm not sure what's going on. Any help is appreciated, I want to put this silly error behind me.