Numerical Methods at work

Disclaimer:
Permission to use, copy, and distribute this software, and It’s documentation for any non-commercial purpose is hereby granted without fee, provided: THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL Henrik Vestermark, BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Complex Expression Calculator

This is a small expression calculator. It also supports complex numbers and has some simple functions and saving of temporary variables.

Complex Expression Evaluator: vs. 2.3




  • History
  • Help

Version 2.3: This web tool evaluates any real and complex expression. It supports the usual arithmetic operators, build-in constants and built-in functions.

Arithmetic Operators:

+,-,*,/ ,% and ^

Example:
2+3*5-1 which evaluates to 16. Or with complex numbers (2-i)*(5+i3) which evaluates to (13+i1), you can also do the power operator ^ with a complex number. E.g. (2-i1)^(5+i3) which evaluates to approx. 223.6+i21.5

Relational Operators

>,<,>=,<=,== and !=

Example:
1>2 return false (same as 0). x==3 return true (same as 1) if the value of the variable is 3 otherwise false

Boolean operators

? &,|,&&,||

Example:
x>y||y==3 returns true is x>y or y==3.

Build in constants:

Constants

Math Symbol

Value

PI

Π

3.141592653589793

E

E

2.718281828459045

LN10

Loge10

2.302585092994046

LN2

Loge2

0.6931471805599453

LOG10E

Log10e

0.4342944819032518

LOG2E

Log102

1.4426950408889633

INFINITY

+∞

+∞

SQRT2

√2

1.4142135623730951

SQRT1_2

1/√2

0.7071067811865476

Build-in constant can't be overwritten by the assignment statement. E.g. LN2=10 will return a syntax error message.
Implicit multiplication is also supported e.g. 2PI evaluates to approx. 6.28 and 5(sqrt(2)+2) evaluates to approx. 17.07

Assignment Statement: You can use the assignment statement (= assignment operator) to save the result in a variable. E.g. x=2 and then later use the variable x in a later statement or expression e.g. sqrt(x). You can change the contents of the variable with a new assignment statement.

Build-in functions:
abs, acos, asin, atan, atan2*, asinh, acosh, atanh, ceil*, cosh, cos, exp, floor*, gcd*, norm, imag, ipow lcm*,log, max*, min*, pow, random**, real, round*, sinh, sin, sqrt, tanh, tan.

**) marked are functions that take zero arguments. *) marked are functions that only take real arguments, all other takes real or complex arguments. e.g. sqrt(2-i2) evaluates to approx. (1.55+i0.64).

Build-in functions can't be overwritten by the assignment statement. E.g. sin=3 will give a syntax error message.

Two new basic built-in functions have been added. gcd(a,b,c,...) which finds the greatest common divisor of the numbers. E.g. gcd(4,7,8) return 1. lcm(a,b,c,...) find the least common multiplier e.g. lcm(4,7,8) return 56.

min() and max() have been expanded to also accept vector or matrix as arguments.

Variables: You can also assign an expression to a variable for later use: e.g. x=sqrt(2-i2)*3/4 and then used them later. E.g. y=log(123.5)/x etc.

Functions: In version 1.2 we have added functions. First, you would need to define a function as in the following:

f(x)=2*sqrt(x)

and then just call the function with a parameter e.g.:

3*log(f(4))

Compound Statements: You can use compound statements in functions or just in general to create a block of statements. e.g.

f(x)={ y=x; y=3+y; z=5; }

Comma Expressions:? Can also be useful when you want to evaluate several expressions in a function but only return the last expression as the result of the function call. E.g.

f(x)={ y=2, x=sqrt(x)/y, log(x+2) }

here log(x+2) is returned as the value of the function to be used in another statement.

In a function call, you can have as many parameters as you like however, the number of parameters passed to a function must match the definition of the functions.

Example: Durand-Kerner method on a polynomial f(x)=x^3-3*x^2+3*x-5

Add each line below to the input field and hit the evaluate button after each line. Then type in next() and see the value of the roots for each iteration.

p=(0.4 + 0.9 i)^0, q=(0.4 + 0.9 i)^1, r=(0.4 + 0.9 i)^2

f(x)=x^3-3*x^2+3*x-5

next()={dp=f(p)/((p-q)*(p-r)); p=p-dp; dq=f(q)/((q-p)*(q-r));q=q-dq;dr=f(r)/((r-p)*(r-q));r=r-dr;}

Conditional expression was added in version 1.10. This is the same as the ? operator in the c language. E.g. x = y>10 ? y : y*2;

Vectors and Matrix: Were added in version 2.0. A Vector can be created as a row vector:

v=[1,2,3] or as column vectors as v=[[1],[2],[3]] and a vectors element can be accessed simply by v[1] which selects the number 2 from the vector v. A vector first index 0.

A matrix can be defined using similar notation e.g.

m=[[1,2],[3,4]] which is a 2 by 2 matrix or a 3x2 matrix as in m=[[1,2,3],[4,5,6]]

you can used vector and matrix with the +,-,* and / operator. A matrix element can be accessed using row and column index as in m[1,2] whichs select the element 6. Matrix indexes like Vectors always start with index 0. m[0,0] select the first element 1. A vector or matrix element can also be complex numbers e.g.

v=[1-i,1+i,3]

A few matrix functions have been added. transpose(m) transpose a vector or matrix elements. determinant(m) returns the determinant of the matrix and finally, a new function solveAxb(a,b) has been added. It solved the set of linear equations expressed by Ax=b. c can be a vector or a matrix.

Build-in Vector/Matrix function with the support of vector and matrix in version 2 there is also a specific build-in function supporting vector/matrix operation.

Diagonal, determinant, norm, solveAxb, transpose

Final Note: If you refresh your browser or exit you lose all variables.

The History section keeps track of your previous expression evaluations. Email me if you encounter any problems at hve@hvks.com

 

Build in function/method

Math Functions.
Notice that x or y as an argument indicates only a real argument.
z indicates a complex argument.
... indicates a variable number of arguments

Method

Description

abs(z,...)

Returns the absolute value of z

acos(z)

Returns the arccosine of z, in radians

acosh(z)

Returns the arccosine hyperbolic of z

asin(z)

Returns the arcsine of z, in radians

asinh(z)

Returns the arcsine hyperbolic of z

atan(z)

Returns the arctangent of z as a numeric value between -PI/2 and PI/2 radians

atanh(z)

Returns the arctangent hyperbolic of z

atan2(y, x)

Returns the arctangent of the quotient of its arguments

ceil(x)

Returns the value of x rounded up to its nearest integer

cos(z)

Returns the cosine of z (z is in radians)

cosh(z)

Returns the cosine hyperbolic of z

exp(z)

Returns the value of Ez

floor(x)

Returns the value of x rounded down to its nearest integer

gcd(x,y,...,n)

Returns the greatest common divisor of the numbers

imag(z)

Returns the imaginary part of a complex number

ipow(z,y)

Return the zy, where y is an integer

lcm(x,y,...,n)

Returns the least common multiplier of the numbers

log(z)

Returns the natural logarithm (base E) of z

max(x,y,...,n)

Returns the number with the highest value

min(x,y,...,n)

Returns the number with the lowest value

pow(z, y)

Returns the value of z to the power of y. Notice y can be a complex number as well

random()

Returns a random number between 0 and 1

real(z)

Return the real part of a complex number z

round(x)

Returns the value of x rounded to its nearest integer

sin(z)

Returns the sine of z (z is in radians)

sinh(z)

Returns the sine hyperbolic of z

sqrt(z)

Returns the square root of z

tan(z)

Returns the tangent of z

tanh(z)

Returns the tangent hyperbolic of z

 

Vector/Matrix functions

Method

Description

diagonal(v)

Create and return a diagonal matrix with the diagonal value of vector v

determinant(m)

Returns the determinant of the square matrix m

norm(v,[p-norm])

Returns the norm given by p-norm of the vector v. if p-norm is omitted p-norm defaults to 2

solveAxb(A,b)

Solve the matrix equation Ax=b where A is a square matrix and b is a column vector or a matrix. If b is a column vector x is also a column vector, if b is a matrix then x is returned as a matrix for the solution

transpose(v)

Transpose of the vector or matrix. E.g. a row vector becomes a column vector

Notice there is no direct function for matrix inversion. However, if m is a square matrix then the expression 1/m calculates the inverse matrix.


Rate this page

Click on the stars below to rate this page

Low
a star
a star
a star
a star
a star
High


Corrections:

11-Nov-2019vs 2.3Redesign of GUI
20-Apr-2018vs 2.2Fixed several issues in handling infinity. Also replaced POSITIVE_INFINITY and NEGATIVE_INFINITY with just INFINITY. Fix and overflow for the power function e.g. 2^2^2^2^2^2 yield 1 instead of Infinity and restore the precedence compare to other operators.
14-Apr-2018vs 2.1Fixed several issues in regards to both pre and post increments operators ++,-- when used with vectors. Added constant POSITIVE_INFINITY and NEGATIVE_INFINITY
31-Mar-2018vs 2.0Change the layout and added Panels. Added support for Vector and Matrix expression. Also added the following functions gcd(), lcd(), diagonal(), determinant(), and solveAxb(), see the Help tab for details.
16-Mar-2018vs 1.11More improvements. Now when you hit enter that is the same as pressing the Evaluate button. Also in the operation of x^y if y is >=0 and an integer then an integer version of the function pow(x,y) eliminates rounding errors.
11-Mar-2018vs 1.10More bugs were fixed again thanks to the input from Paul Schlyter. Also, the conditional expression has been added through the expr ? expr : expr; (borrow for the C language) and support of boolean expression with >,<,<=,>=,==,!=,||,&&,|,&, xor operators
4-Mar-2018vs 1.9More bugs were fixed again thanks to the input from Paul Schlyter. Also additional assignment operations like +=, -=, *=, /=, and %= have been added to mimic the same assignment operators available in C
23-Feb-2018vs 1.8Major bugs were fixed thanks to the input from Paul Schlyter. A new built-in function is added for Asinh(), Acosh(), and Atanh() taking both real and complex numbers. Better error message and general improvement of the application. Also, ^ was incorrectly implemented as left-associative making the calculation wrong when cascading the ^ operator. e.g. 2^3^4 was incorrectly calculated as 4096 instead of 2.4178...E+24. Now the & operator is correctly implemented as right-associative. Also, the restriction that the ^ operator could only be an integer has been lifted. Now the ^ operator accepts a complex number as well as a real number.
28-Nov-2015vs 1.7Minor problem corrected
28-Oct-2013vs 1.6Minor problem corrected
28-Oct-2009vs 1.5Minor Exponent parsing problem corrected
18-Jul-2008vs 1.4Works with IE7, Firefox 2 & 3
18-Jun-2008vs 1.3Added Comma expressions, Statements, and compound statements
11-Jun-2008vs 1.2Added support for defining and calling user-defined functions with zero or more parameters
10-Jun-2008vs 1.1Added support for the assignment of variables