I'm a mathematician relatively new to javascript / Math.js, and am trying to figure out how to basic algebraic operations to a collection of functions. The setup is as below: I have three functions (the x,y,z coordinates of some parameterization in terms of the parameters u,v) that I start with as strings, entered by the user. I want to do some differential geometry, so right now I am using Math.js to parse them and take their derivatives:
const x = math.parse(xCoordText);
const y = math.parse(yCoordText);
const z = math.parse(zCoordText);
const u = math.parse('u');
const v = math.parse('v');
const RXu = math.derivative(x, u);
const RYu = math.derivative(y, u);
const RZu = math.derivative(z, u);
const RXv = math.derivative(x, v);
const RYv = math.derivative(y, v);
const RZv = math.derivative(z, v);
So far everything seems to work fine. But the next computations I need to do involve sums and products of the R's. One example: I need the dot product of the vector [RXu,RYu,RZu] with itself. But an expression like the following does not work
const E = math.parse('RXu*RXu+RYu*RYu+RZu*RZu');
As the parser does not know that RXu should be the thing defined above, and not just a string of letters. I think I found a way around this: I can convert each of the R** expressions into a string with .toString() and then manually create the right addition: for example to get RXu*RXu I could do:
RXu.toString();
math.parse(RXu.concat('*').concat(RXu));
But I assume this cannot be the right way to do this - and would be quite a mess in any case as I have a lot of computation I am hoping to do before reaching the final expressions I need! I tried looking through the documentation on the Math.js site for how to do algebraic operations to two expression trees, but did not figure it out. Much thanks for any help or pointing to resources!