# CSharp - FunctionGraph

Settings
 Mathematical expression to make graph of, y = f(x): sin(x * PI / 25) * 50 + sin(x * PI / 250) * 25
 Begin: End: Divs: X-axis: Y-axis: Width: Height: Image: Square Border
Graph
 ▲ + − ▼ ! ◄ + − ►
y = sin(x * PI / 25) * 50 + sin(x * PI / 250) * 25

### 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

### 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^2chs(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 * x2 * x. It will even change the right to left associativity of + and *, x * 6 / 3x * 2. The sub-expressions may also contain functions, x * sin(PI / 4) ^ 2x * 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