Numerical | Science @ Science @ MentDB Weak
Numerical analysis
• Roots, integrals, derivatives and polynomials (Apache Commons Math).
• The functions are written as expressions with one variable, ex: "x^2-2" (see 'math eval' for the syntax).
• The polynomials are JSON arrays of coefficients in ascending order: "[-2, 0, 1]" = -2 + 0*x + 1*x^2 (same order as 'pa polynomial_curve_fit_get_coeff').
• The complex roots use the format a+bi.
• The functions are written as expressions with one variable, ex: "x^2-2" (see 'math eval' for the syntax).
• The polynomials are JSON arrays of coefficients in ascending order: "[-2, 0, 1]" = -2 + 0*x + 1*x^2 (same order as 'pa polynomial_curve_fit_get_coeff').
• The complex roots use the format a+bi.
num derivative <expression> <variable> <x0>num derivative2 <expression> <variable> <x0>num integrate <expression> <variable> <a> <b>num poly_add <json_coeffs1> <json_coeffs2>num poly_derive <json_coeffs>num poly_eval <json_coeffs> <x>num poly_integrate <json_coeffs>num poly_mul <json_coeffs1> <json_coeffs2>num poly_roots <json_coeffs>num solve <expression> <variable> <a> <b>num fft <json_array>num ifft <json_array>num interpolate <json_xs> <json_ys> <x> <mode>num maximize <expression> <variable> <a> <b>num minimize <expression> <variable> <a> <b>num ode <expressions> <y0> <t0> <t1> <nb_steps>num uncertainty <expression> <json_vars>num solve_system <json_equations> <json_init>num integrate2 <expression> <var_x> <a> <b> <var_y> <c> <d>num sum <expression> <variable> <a> <b>num table <expression> <variable> <a> <b> <step>num ode <equations> <initial> <t0> <t1>num ode <equations> <initial> <t0> <t1> <options>num minimize <expression> <start>num minimize <expression> <start> <options>num maximize <expression> <start>num maximize <expression> <start> <options>num interpolate <xs> <ys> <x> <mode>num interpolate_derivative <xs> <ys> <x> <mode>num interpolate_derivative <xs> <ys> <x> <mode> <order>num interpolate_integral <xs> <ys> <a> <b> <mode>num interpolate2 <xs> <ys> <z> <x> <y> <mode>
num derivative <expression> <variable> <x0>
Description
Get the first derivative of a function at a point.
Automatic differentiation: the result is exact up to rounding (no finite differences).
Get the first derivative of a function at a point.
Automatic differentiation: the result is exact up to rounding (no finite differences).
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
x0: The point - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
x0: The point - Number - required
Examples (7)
admin
num derivative "x^3" "x" 2
mentdb
12
Derivative of sin at 0
admin
num derivative "sin(x)" "x" 0
mentdb
1
Velocity from a position law x(t) = 5 t^2 + 2 t
admin
num derivative "5*t^2+2*t" "t" 3
mentdb
32
Derivative of a logarithm
admin
num derivative "ln(x)" "x" 2
mentdb
0.5
Slope of a velocity at t = 2 (acceleration)
admin
num derivative "4.9*t^2" "t" 2
mentdb
19.6
Special function: J0'(1) = -J1(1)
admin
num derivative "bessel_j(0, x)" "x" 1
mentdb
-0.44005058574493355
Derivative of exp(-3x) at 0
admin
num derivative "exp(-3*x)" "x" 0
mentdb
-3
num derivative2 <expression> <variable> <x0>
Description
Get the second derivative of a function at a point (automatic differentiation).
Get the second derivative of a function at a point (automatic differentiation).
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
x0: The point - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
x0: The point - Number - required
Examples (6)
admin
num derivative2 "x^3" "x" 2
mentdb
12
admin
num derivative2 "sin(x)" "x" 1.5707963267948966
mentdb
-1
Curvature of exp at 0
admin
num derivative2 "exp(x)" "x" 0
mentdb
1
Concavity of a cosine at 0: -1
admin
num derivative2 "cos(x)" "x" 0
mentdb
-1
Inflection point of x^3: 0
admin
num derivative2 "x^3" "x" 0
mentdb
0
Acceleration from a position
admin
num derivative2 "5*t^3-2*t" "t" 1
mentdb
30
num integrate <expression> <variable> <a> <b>
Description
Get the definite integral of a function on [a, b]. The bounds can be infinite: inf, -inf (change of variable to a finite interval).
Adaptive Gauss-Kronrod 7-15: relative precision about 1e-12, integrable singularities at the bounds are supported (sqrt(x), 1/sqrt(x) on [0, 1]).
If a > b, the result is negative.
Get the definite integral of a function on [a, b]. The bounds can be infinite: inf, -inf (change of variable to a finite interval).
Adaptive Gauss-Kronrod 7-15: relative precision about 1e-12, integrable singularities at the bounds are supported (sqrt(x), 1/sqrt(x) on [0, 1]).
If a > b, the result is negative.
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
Examples (12)
admin
num integrate "x^2" "x" 0 1
mentdb
0.3333333333333333
Area under a Gaussian
admin
num integrate "exp(-x^2)" "x" -10 10
mentdb
1.7724538509055163
Infinite bound
admin
num integrate "1/(1+x^2)" "x" "-inf" "inf"
mentdb
3.141592653589793
Special function
admin
num integrate "bessel_j(0, x)" "x" 0 10
mentdb
1.067011303956737
Area under sin between 0 and pi = 2
admin
num integrate "sin(x)" "x" 0 3.141592653589793
mentdb
2
Normal law: P(-1.96 < Z < 1.96)
admin
num integrate "exp(-x^2/2)/sqrt(2*pi)" "x" -1.96 1.96
mentdb
0.9500042097035593
Infinite bound: integral of exp(-x) from 0 to infinity = 1
admin
num integrate "exp(-x)" "x" 0 "inf"
mentdb
0.9999999999999999
Singularity at the bound: integral of 1/sqrt(x) on [0, 1] = 2
admin
num integrate "1/sqrt(x)" "x" 0 1
mentdb
1.9999999999997646
Work of a spring F = k x (k = 200 N/m) from 0 to 0.1 m
admin
num integrate "200*x" "x" 0 0.1
mentdb
1
Length of an arc: y = x^2 from 0 to 1
admin
num integrate "sqrt(1+4*x^2)" "x" 0 1
mentdb
1.4789428575445975
Oscillating function
admin
num integrate "sin(x)/x" "x" 1e-9 100
mentdb
1.562225465889056
Reversed bounds: negative value
admin
num integrate "x" "x" 1 0
mentdb
-0.5
num poly_add <json_coeffs1> <json_coeffs2>
Description
Add two polynomials
Add two polynomials
Parameters
json_coeffs1: The coefficients of the first polynomial (ascending order) - String - required
json_coeffs2: The coefficients of the second polynomial (ascending order) - String - required
json_coeffs1: The coefficients of the first polynomial (ascending order) - String - required
json_coeffs2: The coefficients of the second polynomial (ascending order) - String - required
Examples (4)
admin
num poly_add "[1, 2]" "[0, 0, 3]"
mentdb
[1,2,3]
Sum of two polynomials
admin
num poly_add "[1, 2, 3]" "[-1, 0, 1]"
mentdb
[0,2,4]
The coefficients are in increasing powers: (1 + x) + (2 - x)
admin
num poly_add "[1, 1]" "[2, -1]"
mentdb
[3]
Terms that cancel
admin
num poly_add "[0, 0, 1]" "[0, 0, -1]"
mentdb
[0]
num poly_derive <json_coeffs>
Description
Get the derivative of a polynomial
Get the derivative of a polynomial
Parameters
json_coeffs: The coefficients (ascending order) - String - required
json_coeffs: The coefficients (ascending order) - String - required
Examples (4)
admin
num poly_derive "[1, 2, 3]"
mentdb
[2,6]
Derivative of x^3
admin
num poly_derive "[0, 0, 0, 1]"
mentdb
[0,0,3]
Constant: 0
admin
num poly_derive "[5]"
mentdb
[0]
Derivative of 1 + x + x^2 + x^3
admin
num poly_derive "[1, 1, 1, 1]"
mentdb
[1,2,3]
num poly_eval <json_coeffs> <x>
Description
Evaluate a polynomial at x
Evaluate a polynomial at x
Parameters
json_coeffs: The coefficients (ascending order) - String - required
x: The value - Number - required
json_coeffs: The coefficients (ascending order) - String - required
x: The value - Number - required
Examples (5)
admin
num poly_eval "[-2, 0, 1]" 3
mentdb
7
Value of 1 + 2x + 3x^2 at x = 2
admin
num poly_eval "[1, 2, 3]" 2
mentdb
17
1 + x + x^2 at x = 0.5
admin
num poly_eval "[1, 1, 1]" 0.5
mentdb
1.75
Root: x^2 - 4 at x = 2
admin
num poly_eval "[-4, 0, 1]" 2
mentdb
0
Taylor polynomial of exp at x = 1
admin
num poly_eval "[1, 1, 0.5, 0.16666666666666666, 0.041666666666666664]" 1
mentdb
2.708333333333333
num poly_integrate <json_coeffs>
Description
Get the primitive of a polynomial (constant = 0)
Get the primitive of a polynomial (constant = 0)
Parameters
json_coeffs: The coefficients (ascending order) - String - required
json_coeffs: The coefficients (ascending order) - String - required
Examples (4)
admin
num poly_integrate "[1, 2, 3]"
mentdb
[0,1,1,1]
Primitive of 1
admin
num poly_integrate "[1]"
mentdb
[0,1]
Primitive of 3x^2: x^3
admin
num poly_integrate "[0, 0, 3]"
mentdb
[0,0,0,1]
Primitive of 1 + x
admin
num poly_integrate "[1, 1]"
mentdb
[0,1,0.5]
num poly_mul <json_coeffs1> <json_coeffs2>
Description
Multiply two polynomials
Multiply two polynomials
Parameters
json_coeffs1: The coefficients of the first polynomial (ascending order) - String - required
json_coeffs2: The coefficients of the second polynomial (ascending order) - String - required
json_coeffs1: The coefficients of the first polynomial (ascending order) - String - required
json_coeffs2: The coefficients of the second polynomial (ascending order) - String - required
Examples (4)
admin
num poly_mul "[1, 1]" "[-1, 1]"
mentdb
[-1,0,1]
(1 + x)^2
admin
num poly_mul "[1, 1]" "[1, 1]"
mentdb
[1,2,1]
(1 + x)^3 in two steps
admin
num poly_mul (num poly_mul "[1, 1]" "[1, 1]") "[1, 1]"
mentdb
[1,3,3,1]
(x - 1)(x - 2)(x - 3)
admin
num poly_mul (num poly_mul "[-1, 1]" "[-2, 1]") "[-3, 1]"
mentdb
[-6,11,-6,1]
num poly_roots <json_coeffs>
Description
Get all the roots of a polynomial, real and complex (JSON array of strings, format a+bi), sorted by real part then imaginary part. A multiple root is repeated.
Get all the roots of a polynomial, real and complex (JSON array of strings, format a+bi), sorted by real part then imaginary part. A multiple root is repeated.
Parameters
json_coeffs: The coefficients (ascending order) - String - required
json_coeffs: The coefficients (ascending order) - String - required
Examples (7)
admin
num poly_roots "[-2, 0, 1]"
mentdb
["-1.414213562373095","1.414213562373095"]
admin
num poly_roots "[5, 2, 1]"
mentdb
["-1-2i","-1+2i"]
Complex roots of x^2 + 1
admin
num poly_roots "[1, 0, 1]"
mentdb
["-i","i"]
Cubic x^3 - 6x^2 + 11x - 6 = (x-1)(x-2)(x-3)
admin
num poly_roots "[-6, 11, -6, 1]"
mentdb
["1","2","3"]
Double root: (x - 1)^2
admin
num poly_roots "[1, -2, 1]"
mentdb
["1","1"]
Degree 4: x^4 - 1
admin
num poly_roots "[-1, 0, 0, 0, 1]"
mentdb
["-1","-i","i","1"]
Roots of a product built with poly_mul
admin
num poly_roots (num poly_mul "[-1, 1]" "[2, 1]")
mentdb
["-2","1"]
num solve <expression> <variable> <a> <b>
Description
Find a root of f(x) = 0 in [a, b]. The function must change sign on the interval (Brent method, then Newton polishing).
Find a root of f(x) = 0 in [a, b]. The function must change sign on the interval (Brent method, then Newton polishing).
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
Examples (8)
admin
num solve "x^2-2" "x" 0 2
mentdb
1.414213562373095
Root of cos(x) = x
admin
num solve "cos(x)-x" "x" 0 1
mentdb
0.7390851332151607
First zero of J0
admin
num solve "bessel_j(0, x)" "x" 2 3
mentdb
2.404825557695773
Root of a polynomial in [1, 2]
admin
num solve "x^3-x-2" "x" 1 2
mentdb
1.5213797068045676
Interest rate: 1000 becomes 1500 in 8 years
admin
num solve "1000*(1+r)^8-1500" "r" 0 1
mentdb
0.05198950550864404
exp(x) = 3: x = ln(3)
admin
num solve "exp(x)-3" "x" 0 5
mentdb
1.0986122886681096
Kepler equation E - 0.5 sin(E) = 1
admin
num solve "E-0.5*sin(E)-1" "E" 0 3
mentdb
1.4987011335178484
No change of sign on the interval: error
admin
num solve "x^2+1" "x" -1 1
mentdb
Sorry, an error appears (no sign change on [-1, 1]: f(-1) = 2, f(1) = 2).
num fft <json_array>
Description
Get the discrete Fourier transform (JSON array of numbers or complex numbers a+bi). The values are padded with zeros to the next power of 2. No normalization (like numpy.fft.fft).
Get the discrete Fourier transform (JSON array of numbers or complex numbers a+bi). The values are padded with zeros to the next power of 2. No normalization (like numpy.fft.fft).
Parameters
json_array: The values (numbers or complex numbers) - String - required
json_array: The values (numbers or complex numbers) - String - required
Examples (6)
admin
num fft "[1, 2, 3, 4]"
mentdb
["10","-2+2i","-2","-2-2i"]
Spectrum of a constant: everything at frequency 0
admin
num fft "[1, 1, 1, 1]"
mentdb
["4","0","0","0"]
Impulse: flat spectrum
admin
num fft "[1, 0, 0, 0]"
mentdb
["1","1","1","1"]
Alternating signal: everything at the Nyquist frequency
admin
num fft "[1, -1, 1, -1]"
mentdb
["0","0","4","0"]
3 values: padded with zeros to 4
admin
num fft "[1, 2, 3]"
mentdb
["6","-2-2i","2","-2+2i"]
Complex input
admin
num fft "[\"1+i\", \"0\", \"0\", \"0\"]"
mentdb
["1+i","1+i","1+i","1+i"]
num ifft <json_array>
Description
Get the inverse discrete Fourier transform (1/n normalization, like numpy.fft.ifft)
Get the inverse discrete Fourier transform (1/n normalization, like numpy.fft.ifft)
Parameters
json_array: The values (numbers or complex numbers) - String - required
json_array: The values (numbers or complex numbers) - String - required
Examples (3)
admin
num ifft "[\"10\", \"-2+2i\", \"-2\", \"-2-2i\"]"
mentdb
["1","2","3","4"]
Inverse of the FFT gives the signal back
admin
num ifft (num fft "[1, 2, 3, 4]")
mentdb
["1","2","3","4"]
Flat spectrum: impulse
admin
num ifft "[1, 1, 1, 1]"
mentdb
["1","0","0","0"]
num interpolate <json_xs> <json_ys> <x> <mode>
Description
Interpolate y at x from points (sorted automatically).
Modes: linear, spline (natural cubic spline), lagrange (polynomial through all the points).
Only lagrange extrapolates outside [min(x), max(x)].
Interpolate y at x from points (sorted automatically).
Modes: linear, spline (natural cubic spline), lagrange (polynomial through all the points).
Only lagrange extrapolates outside [min(x), max(x)].
Parameters
json_xs: The x values - String - required
json_ys: The y values - String - required
x: The point - Number - required
mode: linear, spline or lagrange - String - required
json_xs: The x values - String - required
json_ys: The y values - String - required
x: The point - Number - required
mode: linear, spline or lagrange - String - required
Examples (14)
admin
num interpolate "[0, 1, 2, 3]" "[0, 1, 4, 9]" 1.5 "spline"
mentdb
2.2
admin
num interpolate "[0, 1, 2, 3]" "[0, 1, 4, 9]" 1.5 "linear"
mentdb
2.5
Natural spline at several x
admin
num interpolate "[0, 1, 2, 3, 4, 5]" "[0, 0.8, 0.9, 0.1, -0.8, -1]" "[0.5, 2.5, 4.5]" "natural"
mentdb
[0.448086124401914, 0.5789473684210527, -0.967822966507177]
Monotone data without overshoot (pchip)
admin
num interpolate "[0, 1, 2, 3]" "[0, 0, 1, 1]" "[0.5, 1.5, 2.5]" "pchip"
mentdb
[0, 0.5, 1]
Step function (previous)
admin
num interpolate "[0, 10, 20]" "[1.5, 2.0, 2.4]" 15 "previous"
mentdb
2
Akima
admin
num interpolate "[0, 1, 2, 3, 4, 5]" "[0, 0.8, 0.9, 0.1, -0.8, -1]" 2.5 "akima"
mentdb
0.5210937499999999
Nearest point
admin
num interpolate "[0, 10, 20]" "[1.5, 2.0, 2.4]" 14 "nearest"
mentdb
2
Next point
admin
num interpolate "[0, 10, 20]" "[1.5, 2.0, 2.4]" 5 "next"
mentdb
2
Clamped spline (zero slopes at the ends)
admin
num interpolate "[0, 1, 2, 3]" "[0, 1, 0, 1]" 1.5 "clamped"
mentdb
0.5000000000000001
Lagrange polynomial
admin
num interpolate "[0, 1, 2, 3]" "[1, 2, 0, 2]" 1.5 "lagrange"
mentdb
0.9375
Temperature of water density table at 15 degC (cubic)
admin
num interpolate "[0, 10, 20, 30, 40]" "[999.84, 999.70, 998.21, 995.65, 992.22]" 15 "cubic"
mentdb
999.105
Outside the data: error
admin
num interpolate "[0, 1, 2]" "[0, 1, 4]" 5 "linear"
mentdb
Sorry, an error appears (x = 5 is out of [0, 2] (only 'lagrange' extrapolates)).
Akima: no oscillation near an outlier
admin
num interpolate "[0, 1, 2, 3, 4, 5, 6]" "[0, 0, 0, 1, 0, 0, 0]" "[1.5, 2.5]" "akima"
mentdb
[0, 0.5]
Natural spline (same as spline)
admin
num interpolate "[0, 1, 2, 3]" "[0, 1, 4, 9]" 1.5 "natural"
mentdb
2.2
num maximize <expression> <variable> <a> <b>
Description
Find the maximum of a function on [a, b]: scan of 200 points, Brent method around the best one, then Newton polishing on f'(x) = 0.
Returns {x, value}.
Find the maximum of a function on [a, b]: scan of 200 points, Brent method around the best one, then Newton polishing on f'(x) = 0.
Returns {x, value}.
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
Examples (5)
admin
num maximize "sin(x)" "x" 0 3
mentdb
{"x": 1.5707963267948966, "value": 1}
Maximum of the power transferred P = R/(R+5)^2
admin
num maximize "R/(R+5)^2" "R" 0 50
mentdb
{"x": 5, "value": 0.05}
Maximum of x exp(-x)
admin
num maximize "x*exp(-x)" "x" 0 5
mentdb
{"x": 1, "value": 0.36787944117144233}
Best angle for the range of a projectile (degrees)
admin
num maximize "sin(2*a*pi/180)" "a" 0 90
mentdb
{"x": 45, "value": 1}
Area of a rectangle of perimeter 20
admin
num maximize "x*(10-x)" "x" 0 10
mentdb
{"x": 5, "value": 25}
num minimize <expression> <variable> <a> <b>
Description
Find the minimum of a function on [a, b] (global on the scan of 200 points, then Brent and Newton polishing).
Returns {x, value}.
Find the minimum of a function on [a, b] (global on the scan of 200 points, then Brent and Newton polishing).
Returns {x, value}.
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
Examples (6)
admin
num minimize "x^4-3*x^2+x" "x" -3 3
mentdb
{"x": -1.300839565941577, "value": -3.5139050389347886}
admin
num minimize "x^2-4*x" "x" -10 10
mentdb
{"x": 2, "value": -4}
Minimum of a cost
admin
num minimize "x+100/x" "x" 1 50
mentdb
{"x": 10, "value": 20}
Shortest distance from (3, 1) to the curve y = x^2
admin
num minimize "(x-3)^2+(x^2-1)^2" "x" -3 3
mentdb
{"x": 1.289623901485061, "value": 3.3651275396764504}
Minimum of a function with a special function
admin
num minimize "bessel_j(0, x)" "x" 2 5
mentdb
{"x": 3.8317059702075125, "value": -0.40275939570255287}
Cost of a cylindrical can of 1 L: area with r
admin
num minimize "2*pi*r^2+2*0.001/r" "r" 0.01 0.5
mentdb
{"x": 0.0541926070139289, "value": 0.05535810445932085}
num ode <expressions> <y0> <t0> <t1> <nb_steps>
Description
Solve a differential equation y' = f(t, y) or a system, from t0 to t1 (Dormand-Prince 8(5,3), adaptive step, tolerance 1e-12).
- One equation: an expression in t and y, y0 a number.
- A system: a JSON array of expressions in t, y1, y2... yn, y0 a JSON array.
Returns [[t, y...], ...] at nb_steps+1 equally spaced points.
A second order equation y'' = g is written as a system: ["y2", "g"] with y1 = y, y2 = y'.
Solve a differential equation y' = f(t, y) or a system, from t0 to t1 (Dormand-Prince 8(5,3), adaptive step, tolerance 1e-12).
- One equation: an expression in t and y, y0 a number.
- A system: a JSON array of expressions in t, y1, y2... yn, y0 a JSON array.
Returns [[t, y...], ...] at nb_steps+1 equally spaced points.
A second order equation y'' = g is written as a system: ["y2", "g"] with y1 = y, y2 = y'.
Parameters
expressions: An expression (t, y) or a JSON array of expressions (t, y1...yn) - String - required
y0: The initial value (number or JSON array) - String - required
t0: The initial time - Number - required
t1: The final time - Number - required
nb_steps: The number of output intervals (1 to 10000) - Number - required
expressions: An expression (t, y) or a JSON array of expressions (t, y1...yn) - String - required
y0: The initial value (number or JSON array) - String - required
t0: The initial time - Number - required
t1: The final time - Number - required
nb_steps: The number of output intervals (1 to 10000) - Number - required
Examples (14)
admin
num ode "-2*t*y" 1 0 2 2
mentdb
[ [0,1], [1,0.36787944117177024], [2,0.018315638888744514] ]
admin
num ode "[\"y2\", \"-y1\"]" "[1, 0]" 0 3.141592653589793 2
mentdb
[ [0,1,0], [1.5707963267948966,2.2160051571518125E-13,-0.9999999999999845], [3.141592653589793,-0.9999999999999685,-4.435063427621344E-13] ]
Old form: one equation y' = -2 t y
admin
num ode "-2*t*y" 1 0 1 2
mentdb
[ [0,1], [0.5,0.7788007830713138], [1,0.36787944117215393] ]
Damped oscillator, 5 times
admin
num ode "{\"x\": \"v\", \"v\": \"-0.5*v - 4*x\"}" "{\"x\": 1, \"v\": 0}" 0 4 "{\"points\": 5}"
mentdb
{"t": [0, 1, 2, 3, 4], "x": [1, -0.2230979954748353, -0.4668947505330462, 0.4275428418908705, 0.015589074523268139], "v": [0, -1.437591689066472, 0.8997813813429967, 0.30877481101850157, -0.7390055903790133], "method": "dp853"}
Free fall with air resistance until the ground (event)
admin
num ode "{\"z\": \"v\", \"v\": \"-_g0 + 0.02*v^2\"}" "{\"z\": 100, \"v\": 0}" 0 60 "{\"points\": 2, \"event\": \"z\", \"direction\": -1}"
mentdb
{"t": [0, 6.070725570327769], "z": [100, -4.0101255649460654E-13], "v": [0, -21.939729876648734], "method": "dp853", "event": {"t": 6.070725570327769, "z": -4.0101255649460654E-13, "v": -21.939729876648734}}
Stiff chemical kinetics (Robertson): implicit method
admin
num ode "{\"a\": \"-0.04*a + 1e4*b*c\", \"b\": \"0.04*a - 1e4*b*c - 3e7*b^2\", \"c\": \"3e7*b^2\"}" "{\"a\": 1, \"b\": 0, \"c\": 0}" 0 1000 "{\"points\": 2, \"method\": \"stiff\"}"
mentdb
{"t": [0, 1000], "a": [1, 0.33687453057880784], "b": [0, 2.0137023175350857E-6], "c": [0, 0.6631234557188748], "method": "radau"}
Lotka-Volterra predator-prey, 3 times
admin
num ode "{\"prey\": \"1.1*prey - 0.4*prey*pred\", \"pred\": \"0.1*prey*pred - 0.4*pred\"}" "{\"prey\": 10, \"pred\": 10}" 0 20 "{\"points\": 3}"
mentdb
{"t": [0, 10, 20], "prey": [10, 1.1226461550490554, 0.03211427990043338], "pred": [10, 0.28927267091214304, 1.4605400298178421], "method": "dp853"}
Old form: exponential decay y' = -0.5 y
admin
num ode "-0.5*y" 1 0 4 4
mentdb
[ [0,1], [1,0.6065306597126627], [2,0.36787944117147786], [3,0.22313016014846418], [4,0.1353352832366446] ]
Logistic growth with the new form, 5 times
admin
num ode "{\"N\": \"0.8*N*(1-N/100)\"}" "{\"N\": 5}" 0 10 "{\"points\": 5}"
mentdb
{"t": [0, 2.5, 5, 7.5, 10], "N": [5, 28.000456216554113, 74.18413371616752, 95.50220053833608, 99.36665779828142], "method": "dp853"}
Precision options: rtol and atol
admin
num ode "{\"y\": \"-y\"}" "{\"y\": 1}" 0 10 "{\"points\": 2, \"rtol\": 1e-12, \"atol\": 1e-14}"
mentdb
{"t": [0, 10], "y": [1, 4.5399929762877376E-5], "method": "dp853"}
SIR epidemic model
admin
num ode "{\"S\": \"-0.3*S*I\", \"I\": \"0.3*S*I - 0.1*I\", \"R\": \"0.1*I\"}" "{\"S\": 0.99, \"I\": 0.01, \"R\": 0}" 0 100 "{\"points\": 5}"
mentdb
{"t": [0, 25, 50, 75, 100], "S": [0.99, 0.3865727937509217, 0.08214399850417996, 0.06145026033183859, 0.059130728721926235], "I": [0.01, 0.2999656222655743, 0.08811228261202575, 0.012057449453134163, 0.001551201508317014], "R": [0, 0.3134615839835039, 0.8297437188837942, 0.9264922902150271, 0.9393180697697566], "method": "dp853"}
Pendulum with large amplitude (non-linear), 4 times
admin
num ode "{\"th\": \"w\", \"w\": \"-9.81/1*sin(th)\"}" "{\"th\": 2.5, \"w\": 0}" 0 3 "{\"points\": 4}"
mentdb
{"t": [0, 1, 2, 3], "th": [2.5, -0.9967697935813276, -2.107636914460269, 2.2284790442266535], "w": [0, -5.135410713018086, 2.3841785167280864, 1.93003482580656], "method": "dp853"}
Event when x crosses 0 going down
admin
num ode "{\"x\": \"v\", \"v\": \"-x\"}" "{\"x\": 1, \"v\": 0}" 0 10 "{\"points\": 2, \"event\": \"x\", \"direction\": -1}"
mentdb
{"t": [0, 1.5707963268128147], "x": [1, -1.1102230246251565E-16], "v": [0, -1.0000000000690774], "method": "dp853", "event": {"t": 1.5707963268128147, "x": -1.1102230246251565E-16, "v": -1.0000000000690774}}
Unknown method: error
admin
num ode "{\"y\": \"-y\"}" "{\"y\": 1}" 0 1 "{\"method\": \"euler\"}"
mentdb
Sorry, an error appears (unknown method 'euler' (auto, dp853, radau or stiff)).
num uncertainty <expression> <json_vars>
Description
Propagate the uncertainties through a formula (first order, independent variables): u(f) = sqrt(sum((df/dxi*u(xi))^2)), with exact derivatives.
- variables (JSON object): [value, uncertainty] for a measured value, a number alone for an exact value
- option "_angle": "deg" or "grad" for the trigonometric functions
Returns {value, uncertainty, relative, text, derivatives, variance_share}: 'text' is rounded as in 'math round_uncertainty', 'variance_share' gives the part of each variable in the final uncertainty (sum = 1).
Propagate the uncertainties through a formula (first order, independent variables): u(f) = sqrt(sum((df/dxi*u(xi))^2)), with exact derivatives.
- variables (JSON object): [value, uncertainty] for a measured value, a number alone for an exact value
- option "_angle": "deg" or "grad" for the trigonometric functions
Returns {value, uncertainty, relative, text, derivatives, variance_share}: 'text' is rounded as in 'math round_uncertainty', 'variance_share' gives the part of each variable in the final uncertainty (sum = 1).
Parameters
expression: The formula, ex: m*g*h - String - required
json_vars: The variables: {"x": [value, uncertainty], "c": 3} - String - required
expression: The formula, ex: m*g*h - String - required
json_vars: The variables: {"x": [value, uncertainty], "c": 3} - String - required
Examples (7)
admin
num uncertainty "m*g*h" "{\"m\": [1.250, 0.005], \"g\": 9.81, \"h\": [2.40, 0.03]}"
mentdb
{"value": 29.43, "uncertainty": 0.38625123174560877, "relative": 0.013124404748406687, "text": "29.4 ± 0.4", "derivatives": {"m": 23.544, "h": 12.262500000000001}, "variance_share": {"m": 0.09288824383164009, "h": 0.90711175616836}}
admin
num uncertainty "sin(t)" "{\"t\": [30, 0.5], \"_angle\": \"deg\"}"
mentdb
{"value": 0.49999999999999994, "uncertainty": 0.007557497350975908, "relative": 0.015114994701951818, "text": "0.500 ± 0.008", "derivatives": {"t": 0.015114994701951816}, "variance_share": {"t": 1}}
Density of a cylinder rho = m / (pi r^2 h)
admin
num uncertainty "m/(pi*r^2*h)" "{\"m\": [0.2345, 0.0002], \"r\": [0.0125, 5e-05], \"h\": [0.05, 0.0001]}"
mentdb
{"value": 9554.38954369266, "uncertainty": 79.20779191777947, "relative": 0.008290199133660883, "text": "9550 ± 80", "derivatives": {"m": 40743.6654315252, "r": -1528702.3269908256, "h": -191087.7908738532}, "variance_share": {"m": 0.010583866958675556, "r": 0.9312151840388936, "h": 0.05820094900243085}}
Period of a pendulum T = 2 pi sqrt(L/g)
admin
num uncertainty "2*pi*sqrt(L/g)" "{\"L\": [0.75, 0.002], \"g\": 9.81}"
mentdb
{"value": 1.7373047071809469, "uncertainty": 0.0023164062762412625, "relative": 0.0013333333333333333, "text": "1.7373 ± 0.0023", "derivatives": {"L": 1.1582031381206312}, "variance_share": {"L": 1}}
Density of a cube: m / a^3
admin
num uncertainty "m/a^3" "{\"m\": [0.5432, 0.0005], \"a\": [0.04, 0.0002]}"
mentdb
{"value": 8487.5, "uncertainty": 127.5519808254658, "relative": 0.01502821570844958, "text": "8490 ± 130", "derivatives": {"m": 15624.999999999998, "a": -636562.4999999999}, "variance_share": {"m": 0.0037515060045704746, "a": 0.9962484939954295}}
Resistance R = U / I
admin
num uncertainty "U/I" "{\"U\": [12.0, 0.1], \"I\": [0.50, 0.01]}"
mentdb
{"value": 24, "uncertainty": 0.52, "relative": 0.021666666666666667, "text": "24.0 ± 0.5", "derivatives": {"U": 2, "I": -48}, "variance_share": {"U": 0.14792899408284027, "I": 0.8520710059171598}}
With a constant: kinetic energy
admin
num uncertainty "m*v^2/2" "{\"m\": [2.00, 0.01], \"v\": [3.0, 0.1]}"
mentdb
{"value": 9, "uncertainty": 0.6016851336039475, "relative": 0.06685390373377194, "text": "9.0 ± 0.6", "derivatives": {"m": 4.5, "v": 6}, "variance_share": {"m": 0.005593536357986325, "v": 0.9944064636420137}}
num solve_system <json_equations> <json_init>
Description
Solve a system of non-linear equations from initial values (Levenberg-Marquardt with the exact Jacobian, then Newton steps), like fsolve in Python or MATLAB.
- the equations: a JSON array of expressions, "f = g" or "f" (= 0)
- the unknowns are the keys of the initial values; with more equations than unknowns, the least squares solution is used if it satisfies all the equations
- like every non-linear solver, it finds the solution near the initial values: a system can have several solutions
Returns {solution, residuals, iterations}.
Solve a system of non-linear equations from initial values (Levenberg-Marquardt with the exact Jacobian, then Newton steps), like fsolve in Python or MATLAB.
- the equations: a JSON array of expressions, "f = g" or "f" (= 0)
- the unknowns are the keys of the initial values; with more equations than unknowns, the least squares solution is used if it satisfies all the equations
- like every non-linear solver, it finds the solution near the initial values: a system can have several solutions
Returns {solution, residuals, iterations}.
Parameters
json_equations: The equations (JSON array of expressions) - String - required
json_init: The unknowns and their initial values (JSON object) - String - required
json_equations: The equations (JSON array of expressions) - String - required
json_init: The unknowns and their initial values (JSON object) - String - required
Examples (6)
admin
num solve_system "[\"x^2+y^2=4\", \"x*y=1\"]" "{\"x\": 2, \"y\": 0.5}"
mentdb
{"solution": {"x": 1.9318516525781366, "y": 0.5176380902050415}, "residuals": [0, -1.1102230246251565E-16], "iterations": 5}
Intersection of a circle and a line
admin
num solve_system "[\"x^2+y^2=25\", \"y=x+1\"]" "{\"x\": 2, \"y\": 3}"
mentdb
{"solution": {"x": 3, "y": 4}, "residuals": [0, 0], "iterations": 6}
Chemical equilibrium (3 unknowns)
admin
num solve_system "[\"x*y/z = 0.5\", \"x + z = 1\", \"y + z = 2\"]" "{\"x\": 0.5, \"y\": 1.5, \"z\": 0.5}"
mentdb
{"solution": {"x": 0.28077640640441515, "y": 1.2807764064044151, "z": 0.7192235935955849}, "residuals": [0, 0, 0], "iterations": 7}
Linear system of 2 equations
admin
num solve_system "[\"2*x+y=5\", \"x-y=1\"]" "{\"x\": 0, \"y\": 0}"
mentdb
{"solution": {"x": 2, "y": 1}, "residuals": [0, 0], "iterations": 2}
Intersection of a circle and a line: other initial values give the other solution
admin
num solve_system "[\"x^2+y^2=25\", \"y=x+1\"]" "{\"x\": -5, \"y\": -4}"
mentdb
{"solution": {"x": -4, "y": -3}, "residuals": [0, 0], "iterations": 6}
Equilibrium of a chemical reaction
admin
num solve_system "[\"x^2/((1-x)*(2-x))=4\"]" "{\"x\": 0.5}"
mentdb
{"solution": {"x": 0.8452994616207484}, "residuals": [-1.3322676295501878E-15], "iterations": 8}
num integrate2 <expression> <var_x> <a> <b> <var_y> <c> <d>
Description
Double integral of f(x, y) for x from a to b and y from c to d (adaptive Gauss-Kronrod in both directions), like dblquad in Python.
- c and d can be expressions of x: a triangle (0 to x), a disk (-sqrt(1-x^2) to sqrt(1-x^2))...
- a and b: numbers or constant expressions (pi, 2*pi...)
Double integral of f(x, y) for x from a to b and y from c to d (adaptive Gauss-Kronrod in both directions), like dblquad in Python.
- c and d can be expressions of x: a triangle (0 to x), a disk (-sqrt(1-x^2) to sqrt(1-x^2))...
- a and b: numbers or constant expressions (pi, 2*pi...)
Parameters
expression: The function f(x, y) - String - required
var_x: The outer variable, ex: x - String - required
a: The first bound of x - Number - required
b: The last bound of x - Number - required
var_y: The inner variable, ex: y - String - required
c: The first bound of y (number or expression of x) - String - required
d: The last bound of y (number or expression of x) - String - required
expression: The function f(x, y) - String - required
var_x: The outer variable, ex: x - String - required
a: The first bound of x - Number - required
b: The last bound of x - Number - required
var_y: The inner variable, ex: y - String - required
c: The first bound of y (number or expression of x) - String - required
d: The last bound of y (number or expression of x) - String - required
Examples (6)
admin
num integrate2 "x*y" "x" 0 1 "y" 0 "x"
mentdb
0.125
Area of the unit disk
admin
num integrate2 "1" "x" -1 1 "y" "-sqrt(1-x^2)" "sqrt(1-x^2)"
mentdb
3.141592653589928
Volume under a Gaussian
admin
num integrate2 "exp(-(x^2+y^2))" "x" -5 5 "y" -5 5
mentdb
3.141592653580133
Volume under the plane z = x + y on [0, 1] x [0, 1]
admin
num integrate2 "x+y" "x" 0 1 "y" 0 1
mentdb
1
Triangle 0 <= y <= x <= 1: area 1/2
admin
num integrate2 "1" "x" 0 1 "y" 0 "x"
mentdb
0.5
Mass of a plate of density x^2 + y^2 on the unit disc
admin
num integrate2 "x^2+y^2" "x" -1 1 "y" "-sqrt(1-x^2)" "sqrt(1-x^2)"
mentdb
1.5707963267949439
num sum <expression> <variable> <a> <b>
Description
Get the sum of f(k) for k = a to b (integers, at most 10000000 terms, Kahan summation)
Get the sum of f(k) for k = a to b (integers, at most 10000000 terms, Kahan summation)
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The first integer - Number - required
b: The last integer - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The first integer - Number - required
b: The last integer - Number - required
Examples (7)
admin
num sum "k^2" "k" 1 100
mentdb
338350
Sum of 1/k^2 (-> pi^2/6)
admin
num sum "1/k^2" "k" 1 100000
mentdb
1.6449240668982263
Geometric series
admin
num sum "0.5^k" "k" 0 50
mentdb
1.9999999999999991
Harmonic numbers: H_10
admin
num sum "1/k" "k" 1 10
mentdb
2.9289682539682538
Leibniz series for pi/4
admin
num sum "(-1)^k/(2*k+1)" "k" 0 1000
mentdb
0.7856479135848858
Number e: sum of 1/k!
admin
num sum "1/gamma(k+1)" "k" 0 20
mentdb
2.718281828459045
Total of a loan: 12 payments with interest
admin
num sum "100*1.01^k" "k" 1 12
mentdb
1280.9328043328942
num table <expression> <variable> <a> <b> <step>
Description
Get a table of values [[x, f(x)], ...] for x = a, a+step, ... <= b (at most 100000 rows)
Get a table of values [[x, f(x)], ...] for x = a, a+step, ... <= b (at most 100000 rows)
Parameters
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The first x - Number - required
b: The last x - Number - required
step: The step (> 0) - Number - required
expression: The function, ex: x^2-2 - String - required
variable: The name of the variable, ex: x - String - required
a: The first x - Number - required
b: The last x - Number - required
step: The step (> 0) - Number - required
Examples (5)
admin
num table "x^2" "x" 0 1 0.25
mentdb
[ [0,0], [0.25,0.0625], [0.5,0.25], [0.75,0.5625], [1,1] ]
Table of a damped oscillation
admin
num table "exp(-t)*cos(2*pi*t)" "t" 0 1 0.25
mentdb
[ [0,1], [0.25,4.7687794308092406E-17], [0.5,-0.6065306597126334], [0.75,-8.677232802578295E-17], [1,0.36787944117144233] ]
Table of a damped oscillation
admin
num table "exp(-x)*sin(5*x)" "x" 0 1 0.2
mentdb
[ [0,0], [0.2,0.6889381730850401], [0.4,0.6095202930098793], [0.6,0.07744830250893793], [0.8,-0.3400532812580398], [1,-0.35276852628880606] ]
Table of a polynomial
admin
num table "2*x^2-1" "x" 0 2 0.5
mentdb
[ [0,-1], [0.5,-0.5], [1,1], [1.5,3.5], [2,7] ]
Step larger than the interval: one row
admin
num table "x" "x" 0 1 5
mentdb
[ [0,0] ]
num ode <equations> <initial> <t0> <t1>
Description
Solve a system of ordinary differential equations with named variables (as solve_ivp in Python): a JSON object gives the derivative of each variable, t is the time.
- the expressions use the syntax of 'math eval'; [k] session variables, _g0 constants (CODATA)
- result: {"t": [...], "x": [...], "v": [...], "method": ...} at 101 equally spaced times (draw it with 'plot ode')
- method auto: Dormand-Prince 8(5,3) (rtol 1e-10, atol 1e-12), or Radau IIA order 5 (implicit) when the problem is stiff
- the old form (JSON array of expressions in t, y1, y2...) is still available
Solve a system of ordinary differential equations with named variables (as solve_ivp in Python): a JSON object gives the derivative of each variable, t is the time.
- the expressions use the syntax of 'math eval'; [k] session variables, _g0 constants (CODATA)
- result: {"t": [...], "x": [...], "v": [...], "method": ...} at 101 equally spaced times (draw it with 'plot ode')
- method auto: Dormand-Prince 8(5,3) (rtol 1e-10, atol 1e-12), or Radau IIA order 5 (implicit) when the problem is stiff
- the old form (JSON array of expressions in t, y1, y2...) is still available
Parameters
equations: JSON object: the derivative of each variable, ex: {"x": "v", "v": "-[k]*x"} - String - required
initial: JSON object: the value of each variable at t0 - String - required
t0: The first time - Number - required
t1: The last time (can be < t0) - Number - required
equations: JSON object: the derivative of each variable, ex: {"x": "v", "v": "-[k]*x"} - String - required
initial: JSON object: the value of each variable at t0 - String - required
t0: The first time - Number - required
t1: The last time (can be < t0) - Number - required
Examples (5)
admin
num ode "{\"x\": \"v\", \"v\": \"-x\"}" "{\"x\": 1, \"v\": 0}" 0 3
mentdb
{"t": [0, 0.03, 0.06, 0.09, 0.12, 0.15, 0.18, 0.21, 0.24, 0.27, 0.3, 0.33, 0.36, 0.39, 0.42, 0.45, 0.48, 0.51, 0.54, 0.57, 0.6, 0.63, 0.66, 0.69, 0.72, 0.75, 0.78, 0.81, 0.84, 0.87, 0.9, 0.93, 0.96, 0.99, 1.02, 1.05, 1.08, 1.11, 1.14, 1.17, 1.2, 1.23, 1.26, 1.29, 1.32, 1.35, 1.38, 1.41, 1.44, 1.47, 1.5, 1.53, 1.56, 1.59, 1.62, 1.65, 1.68, 1.71, 1.74, 1.77, 1.8, 1.83, 1.86, 1.89, 1.92, 1.95, 1.98, 2.01, 2.04, 2.07, 2.1, 2.13, 2.16, 2.19, 2.22, 2.25, 2.28, 2.31, 2.34, 2.37, 2.4, 2.43, 2.46, 2.49, 2.52, 2.55, 2.58, 2.61, 2.64, 2.67, 2.7, 2.73, 2.76, 2.79, 2.82, 2.85, 2.88, 2.91, 2.94, 2.97, 3], "x": [1, 0.9995500337489875, 0.9982005399352042, 0.9959527330119943, 0.9928086358538663, 0.9887710779 ...
Logistic growth with session variables
admin
-> "[r]" 0.8; -> "[K]" 100; num ode "{\"N\": \"[r]*N*(1-N/[K])\"}" "{\"N\": 5}" 0 10
mentdb
{"t": [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10], "N": [5, 5.3939729289562495, 5.817087955073017, 6.2711929634649515, 6.758203512598109, 7.280096915005272, 7.838904588067428, 8.436702474443273, 9.075599333010905, 9.757722708988846, 10.485202407751006, 11.260 ...
Free fall from 100 m (named variables)
admin
num ode "{\"z\": \"v\", \"v\": \"-_g0\"}" "{\"z\": 100, \"v\": 0}" 0 2
mentdb
{"t": [0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, 0.6, 0.62, 0.64, 0.66, 0.68, 0.7, 0.72, 0.74, 0.76, 0.78, 0.8, 0.82, 0.84, 0.86, 0.88, 0.9, 0.92, 0.94, 0.96, 0.98, 1, 1.02, 1.04, 1.06, 1.08, 1.1, 1.12, 1.14, 1.16, 1.18, 1.2, 1.22, 1.24, 1.26, 1.28, 1.3, 1.32, 1.34, 1.36, 1.38, 1.4, 1.42, 1.44, 1.46, 1.48, 1.5, 1.52, 1.54, 1.56, 1.58, 1.6, 1.62, 1.64, 1.66, 1.68, 1.7, 1.72, 1.74, 1.76, 1.78, 1.8, 1.82, 1.84, 1.86, 1.88, 1.9, 1.92, 1.94, 1.96, 1.98, 2], "z": [100, 99.99803867, 99.99215468, 99.98234803, 99.96861872, 99.95096674999999, 99.92939211999999, 99.903894829 ...
RC circuit: charge of a capacitor
admin
num ode "{\"U\": \"(10-U)/(1000*0.001)\"}" "{\"U\": 0}" 0 5
mentdb
{"t": [0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3, 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4, 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5], "U": [0, 0.4877057549928603, 0.9516258196404047, 1.3929202357494226, 1.8126924692201825, 2.2119921692859523, 2.5918177931828223, 2.9531191028128667, ...
Radioactive chain A -> B -> C
admin
num ode "{\"A\": \"-0.5*A\", \"B\": \"0.5*A-0.1*B\", \"C\": \"0.1*B\"}" "{\"A\": 1, \"B\": 0, \"C\": 0}" 0 10
mentdb
{"t": [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10], "A": [1, 0.9512294245007139, 0.9048374180359595, 0.8607079764250578, 0.8187307530779818, 0.7788007830714048, 0.7408182206817178, 0.7046880897187134, 0.6703200460356392, 0.6376281516217732, 0.6065306597126334, ...
num ode <equations> <initial> <t0> <t1> <options>
Description
Solve a system of ordinary differential equations with options: {"points": number of times (2 to 100001, default 101), "method": "auto" | "dp853" | "radau" (or "stiff"), "rtol": 1e-10, "atol": 1e-12, "event": an expression of t and the variables (the integration stops when it crosses 0), "direction": -1 (decreasing), 1 (increasing) or 0}.
With an event, the result has "event": {"t": ..., "x": ...} and stops there
Solve a system of ordinary differential equations with options: {"points": number of times (2 to 100001, default 101), "method": "auto" | "dp853" | "radau" (or "stiff"), "rtol": 1e-10, "atol": 1e-12, "event": an expression of t and the variables (the integration stops when it crosses 0), "direction": -1 (decreasing), 1 (increasing) or 0}.
With an event, the result has "event": {"t": ..., "x": ...} and stops there
Parameters
equations: JSON object: the derivative of each variable - String - required
initial: JSON object: the value of each variable at t0 - String - required
t0: The first time - Number - required
t1: The last time - Number - required
options: JSON object: points, method, rtol, atol, event, direction - String - required
equations: JSON object: the derivative of each variable - String - required
initial: JSON object: the value of each variable at t0 - String - required
t0: The first time - Number - required
t1: The last time - Number - required
options: JSON object: points, method, rtol, atol, event, direction - String - required
Examples (2)
admin
num ode "{\"x\": \"v\", \"v\": \"-x\"}" "{\"x\": 1, \"v\": 0}" 0 3 "{\"points\": 4}"
mentdb
{"t": [0, 1, 2, 3], "x": [1, 0.5403023058732985, -0.41614683653630213, -0.9899924965961377], "v": [0, -0.8414709848036515, -0.9092974268292137, -0.14112000807637803], "method": "dp853"}
admin
num ode "{\"x\": \"v\", \"v\": \"-_g0\"}" "{\"x\": 10, \"v\": 0}" 0 5 "{\"points\": 3, \"event\": \"x\"}"
mentdb
{"t": [0, 1.4280869812290369], "x": [10, -1.7763568394002505E-15], "v": [0, -14.004749194469737], "method": "dp853", "event": {"t": 1.4280869812290369, "x": -1.7763568394002505E-15, "v": -14.004749194469737}}
num minimize <expression> <start>
Description
Minimum of a function of several variables from a starting point (as scipy.optimize.minimize): Newton's method with the exact gradient and Hessian (automatic differentiation).
Returns {variables, value, iterations, method, converged}. A local method: the result depends on the starting point. [k] session variables, _c constants
Minimum of a function of several variables from a starting point (as scipy.optimize.minimize): Newton's method with the exact gradient and Hessian (automatic differentiation).
Returns {variables, value, iterations, method, converged}. A local method: the result depends on the starting point. [k] session variables, _c constants
Parameters
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable, ex: {"x": 0, "y": 0} - String - required
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable, ex: {"x": 0, "y": 0} - String - required
Examples (6)
admin
num minimize "(1-x)^2+100*(y-x^2)^2" "{\"x\": -1.2, \"y\": 1}"
mentdb
{"x": 1, "y": 1, "value": 0, "iterations": 23, "method": "newton", "converged": true}
Least squares by hand: best line through 3 points
admin
num minimize "(a+b*1-2)^2+(a+b*2-3.9)^2+(a+b*3-6.1)^2" "{\"a\": 0, \"b\": 1}"
mentdb
{"a": -0.1, "b": 2.05, "value": 0.015, "iterations": 2, "method": "newton", "converged": true}
Himmelblau function from (0, 0)
admin
num minimize "(x^2+y-11)^2+(x+y^2-7)^2" "{\"x\": 0, \"y\": 0}"
mentdb
{"x": 3, "y": 2, "value": 0, "iterations": 10, "method": "newton", "converged": true}
Least squares by hand: line through 3 points
admin
num minimize "(a+b*0-1)^2+(a+b*1-3.1)^2+(a+b*2-4.9)^2" "{\"a\": 0, \"b\": 0}"
mentdb
{"a": 1.05, "b": 1.95, "value": 0.015, "iterations": 2, "method": "newton", "converged": true}
Minimum of a function of 3 variables
admin
num minimize "(x-1)^2+(y+2)^2+(z-3)^2+x*y" "{\"x\": 0, \"y\": 0, \"z\": 0}"
mentdb
{"x": 2.6666666666666665, "y": -3.3333333333333335, "z": 3, "value": -4.333333333333334, "iterations": 2, "method": "newton", "converged": true}
Unbounded function: error
admin
num minimize "x+y" "{\"x\": 0, \"y\": 0}"
mentdb
Sorry, an error appears (no minimum found: the function seems to decrease without limit (at x = -1.0E11, y = -1.0E11)).
num minimize <expression> <start> <options>
Description
Minimum of a function of several variables with bounds and constraints: {"bounds": {"x": [min, max]} (null: no bound), "constraints": ["x + y <= 1", "x*y = 2", "x >= 0"], "tol": 1e-12, "max_iter": 1000}.
Augmented Lagrangian, then Newton on the optimality conditions (KKT) for full precision; the result has max_violation (the largest violation of a constraint)
Minimum of a function of several variables with bounds and constraints: {"bounds": {"x": [min, max]} (null: no bound), "constraints": ["x + y <= 1", "x*y = 2", "x >= 0"], "tol": 1e-12, "max_iter": 1000}.
Augmented Lagrangian, then Newton on the optimality conditions (KKT) for full precision; the result has max_violation (the largest violation of a constraint)
Parameters
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable - String - required
options: JSON object: bounds, constraints, tol, max_iter - String - required
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable - String - required
options: JSON object: bounds, constraints, tol, max_iter - String - required
Examples (6)
admin
num minimize "(x-1)^2+(y-2.5)^2" "{\"x\": 2, \"y\": 0}" "{\"constraints\": [\"x - 2*y + 2 >= 0\", \"-x - 2*y + 6 >= 0\", \"-x + 2*y + 2 >= 0\"], \"bounds\": {\"x\": [0, null], \"y\": [0, null]}}"
mentdb
{"x": 1.4, "y": 1.7, "value": 0.8, "iterations": 16, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
Point of the circle x^2 + y^2 = 1 closest to (2, 1)
admin
num minimize "(x-2)^2+(y-1)^2" "{\"x\": 1, \"y\": 0}" "{\"constraints\": \"x^2 + y^2 = 1\"}"
mentdb
{"x": 0.8944271909999159, "y": 0.4472135954999579, "value": 1.527864045000421, "iterations": 40, "method": "augmented_lagrangian", "converged": true, "max_violation": 1.1102230246251565E-16}
Bounds only
admin
num minimize "(x-5)^2+(y+3)^2" "{\"x\": 0, \"y\": 0}" "{\"bounds\": {\"x\": [0, 2], \"y\": [-1, 1]}}"
mentdb
{"x": 2, "y": -1, "value": 13, "iterations": 35, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
Production: minimum cost with a production of 100 units (Cobb-Douglas)
admin
num minimize "20*K+10*L" "{\"K\": 10, \"L\": 10}" "{\"constraints\": \"K^0.5*L^0.5 = 100\", \"bounds\": {\"K\": [0, null], \"L\": [0, null]}}"
mentdb
{"K": 70.71067811865476, "L": 141.4213562373095, "value": 2828.42712474619, "iterations": 8, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
Several equality and inequality constraints
admin
num minimize "x^2+y^2+z^2" "{\"x\": 1, \"y\": 1, \"z\": 1}" "{\"constraints\": [\"x+y+z = 1\", \"x >= 0.5\"]}"
mentdb
{"x": 0.5, "y": 0.25, "z": 0.25, "value": 0.375, "iterations": 19, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
Portfolio: minimum variance with an expected return of 8 %
admin
num minimize "0.04*a^2+0.09*b^2+0.012*a*b" "{\"a\": 0.5, \"b\": 0.5}" "{\"constraints\": [\"a + b = 1\", \"0.06*a + 0.12*b = 0.08\"]}"
mentdb
{"a": 0.6666666666666665, "b": 0.3333333333333334, "value": 0.030444444444444444, "iterations": 16, "method": "augmented_lagrangian", "converged": true, "max_violation": 1.3877787807814457E-17}
num maximize <expression> <start>
Description
Maximum of a function of several variables from a starting point (see 'num minimize')
Maximum of a function of several variables from a starting point (see 'num minimize')
Parameters
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable - String - required
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable - String - required
Examples (4)
admin
num maximize "-(x-2)^2-(y+1)^2+5" "{\"x\": 0, \"y\": 0}"
mentdb
{"x": 2, "y": -1, "value": 5, "iterations": 2, "method": "newton", "converged": true}
Maximum of a two-variable profit
admin
num maximize "60*x+40*y-2*x^2-y^2-x*y" "{\"x\": 1, \"y\": 1}"
mentdb
{"x": 11.428571428571429, "y": 14.285714285714286, "value": 628.5714285714288, "iterations": 2, "method": "newton", "converged": true}
Profit of two products
admin
num maximize "40*x+30*y-x^2-y^2" "{\"x\": 0, \"y\": 0}"
mentdb
{"x": 20, "y": 15, "value": 625, "iterations": 2, "method": "newton", "converged": true}
Maximum of a Gaussian in 2 dimensions
admin
num maximize "exp(-((x-1)^2+(y-2)^2))" "{\"x\": 0, \"y\": 0}"
mentdb
{"x": 1, "y": 2, "value": 1, "iterations": 15, "method": "newton", "converged": true}
num maximize <expression> <start> <options>
Description
Maximum of a function of several variables with bounds and constraints (see 'num minimize'). Ex: the box of largest volume with a surface of 24
Maximum of a function of several variables with bounds and constraints (see 'num minimize'). Ex: the box of largest volume with a surface of 24
Parameters
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable - String - required
options: JSON object: bounds, constraints, tol, max_iter - String - required
expression: The function of several variables - String - required
start: JSON object: the starting value of each variable - String - required
options: JSON object: bounds, constraints, tol, max_iter - String - required
Examples (4)
admin
num maximize "x*y*z" "{\"x\": 1, \"y\": 1, \"z\": 1}" "{\"constraints\": \"2*(x*y + y*z + x*z) = 24\", \"bounds\": {\"x\": [0, null], \"y\": [0, null], \"z\": [0, null]}}"
mentdb
{"x": 2, "y": 2, "z": 2, "value": 8, "iterations": 15, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
Cylinder of largest volume with an area of 100 (r, h)
admin
num maximize "pi*r^2*h" "{\"r\": 1, \"h\": 1}" "{\"constraints\": \"2*pi*r^2 + 2*pi*r*h = 100\", \"bounds\": {\"r\": [0, null], \"h\": [0, null]}}"
mentdb
{"r": 2.3032943298089035, "h": 4.606588659617806, "value": 76.77647766029678, "iterations": 24, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
Box without a lid: maximum volume with 1 m2 of material
admin
num maximize "x*y*h" "{\"x\": 0.5, \"y\": 0.5, \"h\": 0.2}" "{\"constraints\": \"x*y + 2*h*(x+y) = 1\", \"bounds\": {\"x\": [0, null], \"y\": [0, null], \"h\": [0, null]}}"
mentdb
{"x": 0.5773502691896257, "y": 0.5773502691896257, "h": 0.28867513459481287, "value": 0.09622504486493762, "iterations": 25, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
Linear programme: 2 products, 2 resources
admin
num maximize "3*x+5*y" "{\"x\": 0, \"y\": 0}" "{\"constraints\": [\"x <= 4\", \"2*y <= 12\", \"3*x + 2*y <= 18\"], \"bounds\": {\"x\": [0, null], \"y\": [0, null]}}"
mentdb
{"x": 2, "y": 6, "value": 36, "iterations": 8, "method": "augmented_lagrangian", "converged": true, "max_violation": 0}
num interpolate <xs> <ys> <x> <mode>
Description
Interpolation (as scipy.interpolate) at one x or at a JSON array of x. Modes: linear, nearest, previous, next, cubic (spline not-a-knot, as CubicSpline), natural (natural spline, = spline), clamped (zero slopes at the ends), pchip (monotone, no overshoot), akima, lagrange (polynomial, extrapolates)
Interpolation (as scipy.interpolate) at one x or at a JSON array of x. Modes: linear, nearest, previous, next, cubic (spline not-a-knot, as CubicSpline), natural (natural spline, = spline), clamped (zero slopes at the ends), pchip (monotone, no overshoot), akima, lagrange (polynomial, extrapolates)
Parameters
xs: JSON array of x - String - required
ys: JSON array of y - String - required
x: A number or a JSON array of numbers - String - required
mode: linear, nearest, previous, next, cubic, natural, clamped, pchip, akima, spline, lagrange - String - required
xs: JSON array of x - String - required
ys: JSON array of y - String - required
x: A number or a JSON array of numbers - String - required
mode: linear, nearest, previous, next, cubic, natural, clamped, pchip, akima, spline, lagrange - String - required
Examples (2)
admin
num interpolate "[0, 1, 2, 3, 4]" "[0, 1, 8, 27, 64]" "[0.5, 1.5, 2.5]" "cubic"
mentdb
[0.125, 3.375, 15.625]
admin
num interpolate "[0, 1, 2, 3]" "[0, 1, 1, 0]" 1.5 "pchip"
mentdb
1
num interpolate_derivative <xs> <ys> <x> <mode>
Description
First derivative of the interpolating function at x (a number or a JSON array)
First derivative of the interpolating function at x (a number or a JSON array)
Parameters
xs: JSON array of x - String - required
ys: JSON array of y - String - required
x: A number or a JSON array of numbers - String - required
mode: The mode (see 'num interpolate') - String - required
xs: JSON array of x - String - required
ys: JSON array of y - String - required
x: A number or a JSON array of numbers - String - required
mode: The mode (see 'num interpolate') - String - required
Examples (4)
admin
num interpolate_derivative "[0, 1, 2, 3, 4]" "[0, 1, 8, 27, 64]" 2 "cubic"
mentdb
12
Velocity from measured positions
admin
num interpolate_derivative "[0, 1, 2, 3, 4]" "[0, 4.9, 19.6, 44.1, 78.4]" "[1, 2, 3]" "cubic"
mentdb
[9.8, 19.6, 29.400000000000002]
Velocity from measured positions (pchip)
admin
num interpolate_derivative "[0, 1, 2, 3, 4]" "[0, 4.9, 19.6, 44.1, 78.4]" 2.5 "pchip"
mentdb
25.010416666666664
Linear: slope of the segment
admin
num interpolate_derivative "[0, 1, 2]" "[0, 2, 3]" 0.5 "linear"
mentdb
2
num interpolate_derivative <xs> <ys> <x> <mode> <order>
Description
Derivative of order 1, 2 or 3 of the interpolating function at x
Derivative of order 1, 2 or 3 of the interpolating function at x
Parameters
xs: JSON array of x - String - required
ys: JSON array of y - String - required
x: A number or a JSON array of numbers - String - required
mode: The mode - String - required
order: 1, 2 or 3 - Number - required
xs: JSON array of x - String - required
ys: JSON array of y - String - required
x: A number or a JSON array of numbers - String - required
mode: The mode - String - required
order: 1, 2 or 3 - Number - required
Examples (4)
admin
num interpolate_derivative "[0, 1, 2, 3, 4]" "[0, 1, 8, 27, 64]" 2 "cubic" 2
mentdb
12
Acceleration from measured positions (second derivative)
admin
num interpolate_derivative "[0, 1, 2, 3, 4]" "[0, 4.9, 19.6, 44.1, 78.4]" 2 "cubic" 2
mentdb
9.79999999999999
Third derivative of a cubic spline
admin
num interpolate_derivative "[0, 1, 2, 3, 4]" "[0, 1, 8, 27, 64]" 2.5 "cubic" 3
mentdb
6
Order 1 is the same as the 4 parameters
admin
num interpolate_derivative "[0, 1, 2, 3, 4]" "[0, 1, 8, 27, 64]" 2 "cubic" 1
mentdb
12
num interpolate_integral <xs> <ys> <a> <b> <mode>
Description
Integral of the interpolating function from a to b (exact for the piecewise polynomial)
Integral of the interpolating function from a to b (exact for the piecewise polynomial)
Parameters
xs: JSON array of x - String - required
ys: JSON array of y - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
mode: The mode - String - required
xs: JSON array of x - String - required
ys: JSON array of y - String - required
a: The lower bound - Number - required
b: The upper bound - Number - required
mode: The mode - String - required
Examples (5)
admin
num interpolate_integral "[0, 1, 2, 3, 4]" "[0, 1, 8, 27, 64]" 0 4 "cubic"
mentdb
64
admin
num interpolate_integral "[0, 1, 2, 3]" "[1, 3, 2, 4]" 0 3 "linear"
mentdb
7.5
Distance from measured speeds
admin
num interpolate_integral "[0, 10, 20, 30, 40]" "[0, 12, 20, 24, 25]" 0 40 "cubic"
mentdb
696.6666666666667
Distance from a table of speeds (m/s) every 10 s
admin
num interpolate_integral "[0, 10, 20, 30]" "[0, 8, 12, 13]" 0 30 "pchip"
mentdb
273.3333333333333
Part of the interval
admin
num interpolate_integral "[0, 1, 2, 3]" "[0, 1, 4, 9]" 1 2 "cubic"
mentdb
2.333333333333333
num interpolate2 <xs> <ys> <z> <x> <y> <mode>
Description
Interpolation on a 2D grid: z[i][j] = f(xs[i], ys[j]). Modes: linear (bilinear, as RegularGridInterpolator), cubic (bicubic spline, as RectBivariateSpline, at least 4 x and 4 y), nearest. x and y: numbers or JSON arrays of the same size
Interpolation on a 2D grid: z[i][j] = f(xs[i], ys[j]). Modes: linear (bilinear, as RegularGridInterpolator), cubic (bicubic spline, as RectBivariateSpline, at least 4 x and 4 y), nearest. x and y: numbers or JSON arrays of the same size
Parameters
xs: JSON array of x (rows) - String - required
ys: JSON array of y (columns) - String - required
z: JSON matrix: one row per x, one value per y - String - required
x: A number or a JSON array - String - required
y: A number or a JSON array - String - required
mode: linear, cubic, nearest - String - required
xs: JSON array of x (rows) - String - required
ys: JSON array of y (columns) - String - required
z: JSON matrix: one row per x, one value per y - String - required
x: A number or a JSON array - String - required
y: A number or a JSON array - String - required
mode: linear, cubic, nearest - String - required
Examples (6)
admin
num interpolate2 "[0, 1, 2]" "[0, 1]" "[[0, 1], [1, 2], [2, 3]]" 0.5 0.5 "linear"
mentdb
1
admin
num interpolate2 "[0, 1, 2, 3]" "[0, 1, 2, 3]" "[[0, 1, 4, 9], [1, 2, 5, 10], [4, 5, 8, 13], [9, 10, 13, 18]]" 1.5 2.5 "cubic"
mentdb
8.5
Bilinear interpolation in a temperature grid
admin
num interpolate2 "[0, 10, 20]" "[0, 100]" "[[15, 12], [17, 13], [20, 15]]" 15 50 "linear"
mentdb
16.25
Nearest point of the grid
admin
num interpolate2 "[0, 1, 2]" "[0, 1]" "[[0, 1], [1, 2], [2, 3]]" 1.4 0.6 "nearest"
mentdb
2
At a point of the grid: the value
admin
num interpolate2 "[0, 1, 2]" "[0, 1]" "[[0, 1], [1, 2], [2, 3]]" 1 1 "linear"
mentdb
2
Outside the grid: error
admin
num interpolate2 "[0, 1, 2]" "[0, 1]" "[[0, 1], [1, 2], [2, 3]]" 3 0 "linear"
mentdb
Sorry, an error appears (x = 3 is out of [0, 2]).
