paulmasson / math Goto Github PK
View Code? Open in Web Editor NEWComplex special functions and common mathematical operations in JavaScript
License: MIT License
Complex special functions and common mathematical operations in JavaScript
License: MIT License
Round[a,b]
in Mathematica is available for 2 arguments.
Also Round, Floor, Ceiling,...
works on complex numbers by separately evaluating real and imaginary parts.
Can we have such functions also in math.js?
Hi Paul, the zeta function returns NaN for complex numbers with Im>80. It seems that the factorial product overflows. Would this algorithm be suitable for Imaginary numbers > 80? This complex implementation of the zeta function has been my favorite and I would prefer to resolve this issue for plotting output values for imaginary inputs up to 1000. Thanks!
arctan(x,y) should call Math.atan2(x,y) for real values
Can you please implement surd(x,n)
for x
real number and n
integer number
I didn't see it in the online github interface?
Line 2102 in 6dcf33b
There are expIntegralE
and expIntegralEi
functions but no expIntegral
?
Please implement the LogisticSigmoid function
It would be nice to have a piecewise() function.
piecewise() is often used in cumulative distribution functions and probability density functions.
m
seems to be unnecessary in carlsonRF
math/src/functions/elliptic-integrals.js
Line 46 in 0eaa35e
Can you add a betaRegularized
function?
The beta()
and gamma()
functions already exists in math
project.
function betaRegularized(z, a, b) {
return (beta(z, a, b)*gamma(a + b))/(gamma(a)*gamma(b));
}
function betaRegularized(z0, z1, a, b) {
return ((-beta(z0, a, b) + beta(z1, a, b))*gamma(a + b))/(gamma(a)*gamma(b));
}
Switch to an asymptotic form for large argument
The following example should return -0.5
:
console.log(hypergeometric2F1(-3.0,-1.0,-2.0,1.0));
The following example should return appro: 5.513090059384266E23
console.log(hypergeometric2F1(2,2,3.01,0.95));
See tests:
Please implement haversine:
1/2 * (1-Cos(x))
and inverseHaversine
2*ArcSin( Sqrt(x) )
or alternative formula if numerically better suited.
console.log( expIntegralEn(2.0,0.666667))
should return 0.2478109908494504
console.log( expIntegralEn(4.0,0.666667))
should return 0.13244901461322484
hypergeometric2F1(0.5,0.333,0.666,1)
should return NaN
or complex infinity, but returns -0.611282
Does it make sense to implement a multinomial function derived from the gamma
function:
Or is there a faster approach using existing functions?
Please implement the subfactorial(n)
function as
gamma(n+1,-1)/E
Defintion for integers >= 0:
,
| 1 for n = 0
!n = { 0 for n = 1
| (n - 1)*(!(n - 1) + !(n - 2)) for n > 1
`
console.log(weierstrassHalfPeriods(1.0,complex(0,2)));
should return [1.30139... - 0.29912...*I, -0.29912... + 1.30139...*I}
instead of
0: Object { re: 1.3013924813453168, im: -0.29912656788829045 }
1: Object { re: 2.3036583948098155, im: 0.7031393455731271 }
โ
Can you please compare, if you would back port the following commit:
gives a better precision for your hypergeometric0F1()
implementation?
math/src/functions/hypergeometric.js
Line 114 in de987ba
The Java implementation uses:
Is the performance the same?
My Java tool warns me about NUM09-J. Do not use floating-point variables as loop counters
One corresponding example in math.js
is:
math/src/functions/elliptic-functions.js
Line 86 in 0eaa35e
Should the floating-point iterations integer loop counter i
not exceed a "configurated iteration limit" to be sure to stop the loop, for example if tolerance is choosen "too small"?
console.log(ellipticPi(2.0, 0.5));
should return -0.313545...
instead of re: -0.31354468346461095; im: -1.8137993642342178
(Firefox console)?
โ
Hi!
x-values close to -1, eg -0.9999999999999976 results in an eternal while-loop, See https://github.com/paulmasson/math/blob/master/src/functions/hypergeometric.js#L384
E.g:
const y = hypergeometric2F1(1, 0.5, 1.5, -1.0000000000000024);
which calls hypergeometric2F1(1, 0.5, 1.5, -0.9999999999999976);
Can be solved by a tolerance check on line 372?: if ( Math.abs(x+1)< tolerance )
. Or a max number of iterations check?
https://github.com/paulmasson/math/blob/master/src/functions/hypergeometric.js#L372
Line 314 in 5ca4e14
Should the pattern
if ( isComplex(x) ) return result;
be replaced with
if ( isComplex(result) ) return result;
in the functions cosIntegral, coshIntegral, sinIntegral, sinhIntegral
?
The documentation lists the function setPrecision, but the actual implementation is called setPrecisionScale.
(Discovered while comparing documentation and source in https://observablehq.com/@ambassadors/library-analysis.)
console.log(sphericalBesselY(2.0,-5));
should return -0.164995...
instead of 0.16499545760108847
(Firefox console)?
Can we have functions for the imaginary and real parts for both real and complex numbers?
Do you have any unit tests available for the implemented functions?
console.log( sinIntegral(0.0));
doesn't evaluate to 0
The coshIntegral
script slows down the browser.
Is there some wrong call to coshIntegral?
<html>
<head>
<meta charset="utf-8">
<title>JSXGraph</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/distrib/jsxgraph.css"/>
<script src="https://cdn.jsdelivr.net/gh/paulmasson/[email protected]/build/math.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/distrib/jsxgraphcore.js"></script>
</head>
<body>
<div id="jxgbox" class="jxgbox"></div>
<script>
var board = JXG.JSXGraph.initBoard('jxgbox', {axis:true,boundingbox:[-2.75,6.05,2.75,-6.05]});
board.suspendUpdate();
var a = board.create('slider',[[-2.2,4.84],[2.2,4.84],[1,1,10]],{name:'a'});
function $f1(x) { try { return [re(coshIntegral(mul(a.Value(),x)))];} catch(e) { return Number.NaN;} }
function $f2(x) { try { return [im(coshIntegral(mul(a.Value(),x)))];} catch(e) { return Number.NaN;} }
board.create('functiongraph',[$f1, -2.0, 2.0],{strokecolor:'#5e81b5'});
board.create('functiongraph',[$f2, -2.0, 2.0],{strokecolor:'#e19c24'});
board.unsuspendUpdate();
</script>
</body>
</html>
Renaming expIntegral
to expIntegralEi
and expIntegralEn
to expIntegralE
would be clearer as to which function is which. This is in line with both Mathematica and SageMath.
Thanks to @axkr for pointing this out!
console.log(besselYZero(0.0, 1.0))
returns 2.3582698006047504
but should return 0.893577
Can you define it for complex number too?
The formula 2*arctan(tanh(z/2))
seems to be better suited for complex arg.
Same for the inverse?
If you get a NaN for double values you can try complex evaluation as fallback.
Now that the library has weierstrassP, it would be nice to have methods that return the derivative and half periods (like Mathematica's WeierstrassPPrime, WeierstrassHalfPeriodW1 , etc).
Example:
console.log(polylog(new complex(2.0, 0.0),new complex(0.9993319736282411, 0.03654595031305655)));
See also:
ellipticF(-1.5708,1.5708)
hangs up in the browser
Input
console.log(struveH(0,50.0))
returns
-1012.3484633626421
and should be
-0.085337674826119
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.