VACalculator is a scientific calculator written in JavaScript with a large number of built-in functions. It is optimized for Onyx M92 but it should work in any modern browser.

You can define your own variables for later use. Simple 2D plots are possible in the current window. To be able to access this help file while running the calculator, please put the files vacalculator.htm and vacalculator-doc.htm in the same folder.

The usage is very simple: just press the buttons to construct the expression in the input box and then hit [Compute]; the result appears in the same box. Use [LExpr] to retrieve the last introduced string.

The last (computed) result is stored in the special variable _ and can be used to construct other expressions (useful if you did not store the result in a variable).

The input box may contain several valid expressions separated by ";". They will be all evaluated but only the result of the last one will be displayed.
E.g. the input a=10; b=20; (a+b)*(a-b) produces -300 and the variables a, b remain assigned.

When the expression in the input box contains a sytactical error, no result is given and the user must correct it deleting characters (with [C]) or the whole expression (with [AC]). Using the arrow buttons [←] [→] a cursor can be moved inside the input box.



Operators

The arithmetic operators are the usual   +    -    *   /   and the modulus operator   %

The assignment operator is   =

Arithmetic assignment operators:   +=   *=    -=    can used for variables: v += expr is a shortcut for v = v + expr etc

Relation operators:  ==    !=    <    <=    >    >=

Boolean operators (and, or, not):  &&    ||    !

Bitwise operators (and, or, not, xor):  &    |    ~   ^

The + operator is also used for string concatenation.
Example:
e1="exp(log(5))+1"
e2="exp(log(5))+2"
"(" + e1 + ")*(" + e2 + ")"
A first simplification using the [Compute] button returns
(exp(log(5))+1)*(exp(log(5))+2)
and a second simplification returns 42.



Buit-in variables

pi = π = 3.14159...

e = 2.71828... (=exp(1))

deg = π/180

epssolve = 1e-15

epsint = 1e-10

_ = the last computed expression

Note that you may redefine any of these, but be careful! E.g. the assignment pi=3 is possible but of course not recommended.



Buit-in functions

Algebraic: abs(x), sqrt(x), pow(x,y), fact(x), gamma(x) (=fact(x-1)), max(x,y), min(x,y), floor(x), ceil(x), round(x).

Note that x^y is not a valid expression; use pow(x,y) instead.

Transcendental: exp(x), log(x), ln(x), log10(x), log2(x)

Trigonometric: sin(x), cos(x), tan(x), cot(x), sec(x), csc(x)

Notice that the argument x is in radians; if you want degrees, use the variable deg; e.g. sin(30*deg) returns 0.5 (actually 0.49999999999999994 due to the inherent roundoff errors).

Inverse Trigonometric: asin(x), acos(x), atan(x), acot(x), asec(x), acsc(x). The result is in radians; use deg to obtain degrees, e.g. atan(1)/deg returns 45.

Hyperbolic: sinh(x), cosh(x), tanh(x), coth(x), sech(x), csch(x)

Inverse Hyperbolic: asinh(x), acosh(x), atanh(x), acoth(x), asech(x), acsch(x)

Other: random() (=random number in the interval [0,1)), atan2(y,x) = the angle (in radians, ∈ (−π,π]) between the real axis and the vector OA, where A(x,y).
hex(n) = the hexadecimal expression of n. E.g. hex(255) equals "ff". Note that a hexadecimal number can be entered with the 0x prefix: 0x20 + 5 equals 37.
Note also that e.g. 056 represents an octal number and returns 5*8+6=46.

If you know JavaScript, you can use many other elements of this language.



Evaluation

To evaluate a function given by a string "f" depending on x at the point x=a you can use ev("f", "x", a).

E.g. ev("x*x + x", "x", 10) and ev("z*z + z", "z", 10) return 110.

The same result can be obtained using an assignment first:

fnc="x*x + x"

ev(fnc, "x", 10)

Note that if the variable is x or t you may use the simplified commands evx("f",a) and evt("f",a) respectively, which are a bit faster.



Vectors

You can define vectors (lists) using the syntax v=[v0, v1, ...];

E.g.

v=[1,10,100,1000]

v[0]+v[2] returns 101 



Equations

solve("f", "x", a, b) solves the equation f(x)=0 for x ∈ [a,b]. Here "f" must be a string (delimited by simple or double quotes) depending only on the variable x.

The condition f(a)f(b) < 0 must be satisfied.

E.g. to solve the equation sin(t)=1/2 for t ∈ (0,π/2) use solve("sin(t)-1/2", "t", 0, pi/2); you will obtain t=0.5235987755982989 i.e. ≈ π/6.
Pressing now [Compute] t will contain the solution; you can store it in a new variable e.g. mysol = t.



Sums and products

To compute ∑k=ab f(k) use sum("f", "k", a, b). Here, "f" must depend on k only.
Similarly, to compute ∏k=ab f(k) use prod("f", "k", a, b).
Both commands accept a fifth argument h for the step (which is 1 by default); h must be negative if a>b. E.g. to compute ∑i=110 i2, use sum("i*i","i",1,10) or sum("i*i","i",10,1,-1).



Integrals

To compute ∫ab f(x) dx use int("f", "x", a, b). Here again, "f" must depend on x only.

E.g. int("sin(x)","x",0,pi) will return 2.0000000000157474.
Warning: This function is recursive and uses an adaptive Simpson method in order to obtain high precision but may take a very long time to complete if the function has irregularities or is integrated on large intervals e.g. ∫05001π sin(x) dx. If you want to exit the calculator, just keep pressed the "back" hardware button. You may also change the built-in variable epsint which is set to 1e-10.



Graphics

To plot the graph of the function f(x) for x ∈ [a,b] use plotx("f", a,b,c,d). E.g. plotx("sin(x)",0,2*pi,-1,1)

The graph will appear in a rectangular window [0,w]×[0,h] where the default values for the width and height are w=800, h=400. Note that the rectangle [a.b]×[c,d] is mapped onto [0,w]×[0,h], and only the part of the graph inside [a.b]×[c,d] will be visible. To keep the aspect ratio one must have w/h=(b-a)/(d-c).

Several plotx commands will produce superposed plots, but you may clear the window first, using the [ClrPlot] button.

To draw a m×n grid in the graphic window use grid(m,n).

To draw a parametric curve x=f(t), y=g(t), t ∈ [t1,t2], use plott("f", "g", t1, t2, dt, a, b, c, d).

Here "f", "g" must depend on t only; dt is the step needed for evaluation and a,b,c,d define a rectangle as above.

plott("t*cos(t)","t*sin(t)",0,6*pi,pi/100,-20,20,-20,20) will draw the spiral having the equation r=θ in polar coordinates.


V.A. - Cluj-Napoca (Romania), November 2012