|
|
Expression help
Number format: 123.456E+123
Functions and constants are case insensitive.
Constants may have an empty (), e.g. PI().
Functions without arguments do not need an empty (), e.g. random.
The standard order of operations (precedence) is used.
Note the unary minus precedence: -3^2 = -(3^2) = -9
For best optimization, keep constant values together, e.g. use x*PI/4 or PI/4*x, but do not use PI*x/4. |
Operators | Prec |
+ | Addition | 1 |
- | Subtraction |
* | Multiplication | 2 |
/ | Division |
% | Modulus |
+ | Positive | 3 |
- | Negative |
^ | Exponentiation | 4 |
! | Factorial | 5 |
|
Mathematical Constants |
E | Euler's Number e, 2.7182… |
LN2 | Natural log of 2, 0.6931… |
LN10 | Natural log of 10, 2.3025… |
LOG2E | Base 2 log of e, 1.4426… |
LOG10E | Base 10 log of e, 0.4342… |
PI | Archimedes' Constant π, 3.1415… |
SQRT1_2 | Square root of 1/2, 0.7071… |
SQRT2 | Square root of 2, 1.4142… |
Physical Constants |
C0 | Speed of light in vacuum, 299792458 m/s |
E0 | Vacuum permittivity (electric constant), 8.854187817…E-12 F/m |
EC | Elementary charge, 1.602176634E-19 C |
G0 | Standard gravity, 9.80665 m/s2 |
GC | Gravitational constant, 6.6743E-11 N∙m2/kg2 |
HC | Planck constant, 6.62607015E-34 J∙s |
KB | Boltzmann constant, 1.380649E-23 J/K |
NA | Avogadro constant, 6.02214076E23 mol-1 |
R | Molar gas constant, 8.31446261815324 J/(mol∙K) |
U0 | Vacuum permeability (magnetic constant), 1.2566370614…E-6 N/A2 |
Imperial Units |
FT | Foot in m, 0.3048 m/ft |
IN | Inch in mm, 25.4 mm/in |
LB | Pound in kg, 0.45359237 kg/lbm |
PSI | Pound per square inch (lbf/in2) in Pa (N/m2), 6894.757293168 Pa/psi |
YD | Yard in m, 0.9144 m/yd |
Functions |
abs(x) | The absolute value of x |
acos(x) | The arccosine in radians of x |
acosh(x) | The area (inverse) hyperbolic cosine of x |
acot(x) | The arccotangent in radians of x, PI/2 - atan(x) (0 < acot(x) < PI) |
acoth(x) | The area (inverse) hyperbolic cotangent of x, atanh(1/x) |
acsc(x) | The arccosecant in radians of x, asin(1/x) |
acsch(x) | The area (inverse) hyperbolic cosecant of x, asinh(1/x) |
add(x,y) | x + y |
asec(x) | The arcsecant in radians of x, acos(1/x) |
asech(x) | The area (inverse) hyperbolic secant of x, acosh(1/x) |
asin(x) | The arcsine in radians of x |
asinh(x) | The area (inverse) hyperbolic sine of x |
atan(x) | The arctangent in radians of x (-PI/2 < atan(x) < PI/2) |
atan2(y,x) | The arctangent in radians of y/x (-PI < atan2(y,x) < PI) |
atanh(x) | The area (inverse) hyperbolic tangent of x |
ceil(x) | Round up to the nearest integer |
cos(x) | The cosine of x in radians |
cosh(x) | The hyperbolic cosine of x |
cot(x) | The cotangent of x in radians, 1/tan(x) |
coth(x) | The hyperbolic cotangent of x, 1/tanh(x) |
chs(x) | - x, change sign of x |
csc(x) | The cosecant of x in radians, 1/sin(x) |
csch(x) | The hyperbolic cosecant of x, 1/sinh(x) |
deg(x) | Convert x from radians to degrees |
deg180(x) | Convert x from radians to degrees within -180 to +180 |
deg360(x) | Convert x from radians to degrees within 0 to 360 |
div(x,y) | x / y |
exp(x) | e to the power of x, pow(E,x) or E^x |
fact(x) | The factorial of x, x! = Γ(x+1) |
floor(x) | Round down to the nearest integer |
gamma(x) | The gamma of x, Γ(x) = (x-1)! |
high(x,y) | if x ≥ y then 1 else 0 |
log(x) | The natural logarithm (base e) of x |
log10(x) | The base 10 logarithm of x |
log2(x) | The base 2 logarithm of x |
logb(y,x) | The base y logarithm of x |
low(x,y) | if x ≤ y then 1 else 0 |
max(x,y) | Gets the number with the highest value |
min(x,y) | Gets the number with the lowest value |
mod(x,y) | x % y |
mul(x,y) | x * y |
nop(x) | No operation |
pow(x,y) | The value of x to the power of y, x^y, xy |
rad(x) | Convert x from degrees to radians |
random() | Random number between 0 and 1 (0 ≤ random() < 1) |
range(x,y,z) | if x ≥ y and x ≤ z then 1 else 0 |
round(x,y) | Rounds x to y decimals (nearest integer if y=0) |
sec(x) | The secant of x in radians, 1/cos(x) |
sech(x) | The hyperbolic secant of x, 1/cosh(x) |
sign(x) | if x > 0 then 1 else if x < 0 then -1 else 0 |
signz(x) | if x ≥ 0 then 1 else -1 |
sin(x) | The sine of x in radians |
sinh(x) | The hyperbolic sine of x |
sqrt(x) | The square root of x |
sub(x,y) | x - y |
tan(x) | The tangent of x in radians |
tanh(x) | The hyperbolic tangent of x |
Mathematical expression parser with image draw of function graph
This C# ASP.NET page will parse a mathematical expression, that is a function of x, and then generate an image with a graph of y = f(x).
The syntax of the mathematical expression is a de facto syntax used on computers, and is not the syntax of C# or any other specific programming language.
For each pixel on the X-axis, the parsed expression is evaluated, and a line is drawn to the pixel on the Y-axis.
With the tool buttons, the graph may be zoomed and scrolled. Whenever a button is pressed, a new image is created and sent back to the browser.
Clicking the OK button will save the inputs in the current session, until the web browser is closed.
No third-party add-ons or softwares are used on this page, only plain HTML with an image is used.
Internally, the expression parser can be said to translate operations to functions, e.g. 3 + 2 * x is translated to add(3,mul(2,x)). Actually, it translates to Reverse Polish Notation (RPN) format, 3 2 x mul add. Another example is -3^2 → chs(pow(3,2)) → 3 2 pow chs.
The parser does expression optimization before drawing the graph of f(x), by pre-evaluating constant sub-expressions, e.g. 6 / 3 * x → 2 * x. It will even change the right to left associativity of + and *, x * 6 / 3 → x * 2. The sub-expressions may also contain functions, x * sin(PI / 4) ^ 2 → x * 0.5. Note that random() is never pre-evaluated.
Optimized RPN Converter
DAL: | sin(x * PI / 25) * 50 + sin(x * PI / 250) * 25 |
RPN: | x 0.125663706143592 mul sin 50 mul x 0.0125663706143592 mul sin 25 mul add |
|