Questions tagged [mathjs]

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.

Math JS Site

An extensive math library for JavaScript and Node.js

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices. Powerful and easy to use.

Features

-Supports numbers, big numbers, complex numbers, units, strings, arrays, and matrices.

-Is compatible with JavaScript’s built-in Math library.

-Contains a flexible expression parser.

-Supports chained operations.

-Comes with a large set of built-in functions and constants.

-Has no dependencies. Runs on any JavaScript engine.

-Is easily extensible

98 questions
1
vote
0 answers

How can I replace missing variables from scope with some default values?

I'm using mathjs for calculating some expressions from JSON data. I call eval, where I pass JSON data as a scope. I can use JSON paths in the mathjs script, like user1.age > user2.age. But when these paths are not contained in JSON, mathjs throws an…
Rob Yart
  • 323
  • 1
  • 2
  • 13
1
vote
1 answer

Print mathjs expression with variables substituted

Is there a way to print the expression string after the scope substitutions? var n = math.compile('x * 2'); n.eval({x:2}); // returns 4 // I WISH I could do this: n.toString({x:2}); // returns '2 * 2'
Scott
  • 3,204
  • 3
  • 31
  • 41
1
vote
1 answer

Element-Wise Arithmetic Operations in Jagged Multidimensional Arrays in JavaScript

I want to perform some element-wise arithmetric or mathematical operations on 2D jagged-arrays without flattening the output array; in this example, array C. const A = [[1, 2, 30, 4],[5, 16, 7],[8, 9, 12, 14, 90]]; const B = [[45, 60, 15,…
1
vote
0 answers

How to solve function f(x,y) for either x or y (if the other is given)?

I started to work with mathjs and tried to rewrite some Python code using sympy for algebraic calculations. I implemented a fit function I got from a research article (see link in code snippet if interested) in code and need to rearrange/solve that…
albert
  • 8,027
  • 10
  • 48
  • 84
1
vote
1 answer

mathjs eval error: (intermediate value)(intermediate value)(intermediate value) is not a function

If I run a code: obj = {}; obj['number'] = 1; obj['expressionS'] = 'Sin(0.5 * c1)'; obj['compiledExpressionS'] = null; let cnr = 'c' + obj.number; let params = {}; params[cnr] = 2; var parsedExpressionS =…
ael
  • 514
  • 9
  • 26
1
vote
1 answer

Javascript parser to add percentages to non-percentages

Looking for a consistent way to write (or extend) a parser to do math equations. I'm using mathjs for most of this, and it works great. But it does not handle percentages. I'm trying to write rules that will handle adding percentages to percentages,…
GN.
  • 8,672
  • 10
  • 61
  • 126
1
vote
1 answer

How to connect MathJax and Math.js to sliders

I've found multiple examples of user input that automatically updates a MathJax equation parsed with the Math.js javascript library (example), but it seems to break whenever I connect it to sliders for some reason. Here's a CodePen I've been playing…
In_Circ
  • 83
  • 9
1
vote
1 answer

Convert [2,x,y] matrix into [y+1,2x] for use in dygraphs

I have sets of data called series, containing [x,y] pairs, in the format: [ [x1,a1], [x2,a2], [x3,a3], ... ],[ [x4,b1], [x1,b2], [x5,b3], ... ] These multiple sets need to be combined (matching x-values) to fit into Dygraph's data…
Chris
  • 2,057
  • 1
  • 15
  • 25
1
vote
1 answer

MathJS in ionic 2

Can someone please help me how to use mathjs in ionic 2? I just don't get it imported to use, really don't know what to do. In ionic 1 it was easy to load the library and use it, but not so in ionic 2. Thanks!
bastifix
  • 443
  • 1
  • 6
  • 18
1
vote
1 answer

Mathjs custom sum function

i am trying to implement my own custom sum function. The goal is to have a function called "sumFromTo" that takes 4 parameter * iteratorname * from * to * function where "function" can be some other function and where the solution is to sum all.…
jdoeName
  • 11
  • 1
1
vote
1 answer

Trouble understanding how lusolve works

I am trying to use the lusolve function from mathjs 3.8.0 to solve a linear system. However, I have some trouble interpreting the returned result with respect to the input. I will explain based upon the example from the docs: The example sources…
O. R. Mapper
  • 20,083
  • 9
  • 69
  • 114
1
vote
2 answers

Is there away to do array push with mathjs matrix objects?

Well, the title says it all. I am looking for a way to add rows or columns to an object created with mm = math.matrix([[0, 1], [2, 3], [4, 5]]); // can we do something like mm.push([0,1]); I refer to the mathjs library here.
Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
1
vote
1 answer

How can I avoid exponential notation in mathjs results

In a function that uses mathjs would like to have the results displayed as 1000000000000000000000000000 instead of 1e+27. I tried the math.format() function, but didn't work. > x = 1e+27 < 1e+27 > math.format(x, {notation: 'fixed'}) < "1e+27" >…
Victor
  • 23,172
  • 30
  • 86
  • 125
0
votes
0 answers

Import Mathjs in Ionic React leads to Uncaught TypeError

I would like to use mathjs in my Ionic react project. I've installed the library by using npm install mathjs. Now I'm trying to use the library with the following code from the mathjs website: import { sqrt } from…
KTSB
  • 79
  • 4
0
votes
0 answers

Validate parameters for function node in mathjs expression

in the project I am working right now we use mathjs to be able to write complex expressions that we then want to validate and evaluate. My issue is with the validate part. We want to validate different things so far: The expression is valid (well…
DiegoTArg
  • 452
  • 1
  • 4
  • 14