math.js | Sage/Mathemica/WolframAlpha/Matlab/Octave in the browser
kandi X-RAY | math.js Summary
kandi X-RAY | math.js Summary
Sage/Mathemica/WolframAlpha/Matlab/Octave in the browser
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of math.js
math.js Key Features
math.js Examples and Code Snippets
Community Discussions
Trending Discussions on math.js
QUESTION
I need to allow a user to write expressions and build XML tree from the expression. My plan is to use math.js
which parses and generates an expression tree, then convert that expression tree into DOM tree, and then convert DOM tree into XML using XMLSerializer. The part in bold is tricky one.
For the expression:
...ANSWER
Answered 2021-Jun-09 at 08:34You can extend the node object with a custom property like DOM
and append children to the DOM
of the parent node:
QUESTION
i started to use math.js just for convenience and i was wondering if i could use math.sum method and pass a collection of input values as argument and return the sum of all input values,for example,something like this :
code to visualize my concept :
...ANSWER
Answered 2021-Mar-30 at 23:12You need to map the element values to an array first.
The math library doesn't know anything about getting values from a jQuery collection of elements
Simple case with no validation:
QUESTION
today I met a bug I have never seen before, also, there is none of relevant SO post about this.
ReferenceError: Cannot access 'Math' before initialization
I have tried to add IIFE but still not working.
In my previous work on web dev, I never needed to include math.js
or import it, I always thought it was provided. Before my last attempt, it always works fine, in my other scripts, I can call Math.abs, Math.floor
, etcetera.
Sorry I could not provide any minimum working example, here is the full error reporting.
This is the script I am trying to run: ...Uncaught ReferenceError: Cannot access 'Math' before initialization
ANSWER
Answered 2021-Feb-13 at 14:48I think this might be the initiator of the issue :-
QUESTION
I'm trying to get audio from video to work with Web Audio API. But audio in video is muted. HTML5 audio is working when I am testing this code locally (on jsfiddle it is not working when Web Audio API is on) but locally and on jsfiddle video has no audio (it is muted and user can not change that). No errors shows in the console. I've added function to apply to Autoplay Policy Changes: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio. Here is my code:
...ANSWER
Answered 2020-Dec-08 at 03:38You'll need to pause the audio until a user explicitly interacts (e.g. clicks) the page. This is a modern requirement to prevent audio from autoplaying without explicit invocation from users.
QUESTION
I would like to change the color of MathJax links that were created by \eqref{}
tags to match the color scheme of my site. How can I achieve this preferably WITHOUT additional CSS?
I'm using MathJax 2.7.7 with SVG outputs and my current config looks like the following:
...ANSWER
Answered 2020-Nov-26 at 11:07After looking for this all day and posting a question on StackOverflow as my last chance, I accidentally found the answer in the source code of the MathJax SVG output style's jax.js
file, which happens to be available online in numerous sources.
The color of the references when using the SVG output style is determined in this by the
QUESTION
In the below program i had created two files, one which is exporting modules and another file which is using this modules in a switch case, my aim here is to make a basic calculator program using switch case where user is allowed to give input more than once,to do that i had used a infinite while loop, but the problem is at prompt.get() line just after while(1) control of program is not stopping to take input from user and it keeps on going in a infinite loop. To point that line specifically i had put a comment over it.
math.js
...ANSWER
Answered 2020-Nov-04 at 14:25While loop is going in an infinite loop because value passed in it is always true. For your requirement, I suggest using recursion. I'm pasting working code below. Let me know if it works.
QUESTION
I am trying to use math.js
in Postman.
Already saw Tip#5 in their website. So, in one request I have
...ANSWER
Answered 2020-Nov-03 at 19:55This solves your problem:
QUESTION
I am creating a numerical text input for my VueJS application that will allow math.js expressions to be evaluated in the text field. The idea is that on blur or on pressing enter inside the text box, the expression will be evaluated, if possible.
...ANSWER
Answered 2020-Nov-02 at 19:07It's because by using v-model, you change the localValue, which is not equal to this.value anymore. You should try to remove localValue completely, and use this.value instead.
QUESTION
After a lot of research and experimentation I've learned a few things which have led me to re-frame the question. Rather than trying to find an "exponential regression", I'm really trying to optimize a non-linear error function with bounded input and potentially unbounded output.
So long as a function is linear, there exists a way to directly compute the optimal parameters to minimize the squared error terms (by taking the derivative of the function, locating the point where the derivative equals zero, then using this local minima as your solution). Many times when people say "exponential regression" they're referring to an equation of the form a * e^(b*x)
. Ths reason, described below, is that by taking the natural log of both sides this maps perfectly onto a linear equation and so can be directly computed in a single step using the same method.
However in my case the equation a * b^x
does not map onto a linear equation, and so there is no direct solution. Instead a solution must be determined iteratively.
There are a few non-linear curve fitting algorithms out there. Notably Levenberg-Marquardt. I found a handful of implementations of this algorithm:
- C++: https://www.gnu.org/software/gsl/doc/html/nls.html
- Python: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
- JavaScript: https://github.com/mljs/levenberg-marquardt
Unfortunately I tried all three of these implementations and the curve fitting was just atrocious. I have some sample data with 11,000 points for which I know the optimal parameters are a = 0.08
and b = 1.19
, however these algorithms often returned bizarre results like a = 117, b = 0.000001
or a = 0, b = 3243224
Next I tried verifying my understanding of the problem by using Excel. An error function can be written defined as sum((y - y')^2)
where y'
is the estimated value given your parameters and an input x
. The problem then falls to minimizing this error function. I opened up my data (CSV), added a column for the "computed" values, added another column for the squared error terms, then finally used Solver to optimize the sum of the error terms. This worked beautifully! I got back a = 0.0796, b = 1.1897
. Plotting two lines on the same graph (original data and estimated data) showed a really good fit.
I tried doing the same using OpenOffice at first, however the solver built into OpenOffice was just as bad as the Levenberg-Marquardt experiments I did, and repeatedly gave worthless solutions. Even when I set initial values it would "optimize" the problem and come up with something far worse than it started.
Having proven my concept in Excel I then tried using optimization-js. I tried both their genetic optimization and powell optimization (because I don't have a gradient function) and in both cases it produced awful results.
I did find a question regarding how Excel's Solver works which linked to an ugly PDF. I haven't taken the time to read the PDF yet, but it may provide hints for solving the problem manually. I also found a Python example that reportedly implements Generalized Gradient Descent (the same algorithm as Excel), so if I can make sense of it and rewrite it to accept a generic function as input then I may be able to use that.
New Question (given all that):How, preferably in JavaScript (though other languages are acceptable so long as they can be run on AWS Lambda), can I optimize the parameters to the following function to minimize its output?
...ANSWER
Answered 2020-Oct-04 at 05:29- My equation is differentiable, I just wasn't sure how to differentiate it. The error function is a sum so the partial derivatives are just the derivatives of the inside of the sum, which is computed using chain rule. This means any nonlinear optimizer algorithm that requires a gradient was available to me
- Many nonlinear optimizers have trouble when very small changes in inputs lead to massive changes in outputs, which can be the case with exponential functions. Tuning the damping parameters or convergence parameters can help with this
I was able to get a version of gradient descent to compute the same answer as Excel after some work, but it took 15 seconds to run (vs Excel ran Solver in ~2 seconds) -- clearly my implementation was bad
More ImportantlySee: https://math.stackexchange.com/a/3850781/209313
There is no meaningful difference between e^(bx)
and b^x
. Because b^x == e^(log(b)*x)
. So we can use a linear regression model and then compute b
by taking e
to the power of whatever the model spits out.
Using regression-js:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
Install math.js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page