Description
Calcpad uses a simple math language for development of engineering spreadsheets. It represents a mixture of mathematical expressions and text/Html comments. A detailed description is provided in the Calcpad user manual. Bellow, you can find a quick reference guide that highlights the most important features in brief:
Expressions
Constants
Real
All real values are stored in double precision floating point fields. They can range from -1.7976931348623157E+308 to 1.7976931348623157E+308. The smallest nonzero value is 4.94065645841247E-324. Smaller values are considered exactly zero. You can use the following input formats:
Format | Positive | Negative |
---|---|---|
Integer | 34 | -34 |
Decimal | 3.45 | -3.45 |
Fraction | 3/4 | -3/4 |
Exponential | 3.4*10^5 | -3.4*10^5 |
The last two modes are actually simple expressions.
Complex
Complex numbers are represented by a couple of values ±a ± bi, where “a” is the real part, and “bi” is called “imaginary”. The imaginary unit in Calcpad is entered as 1i. It is defined so that (1i)^2 = -1. You must switch to “Complex” mode in order to use complex numbers.
Predefined
There are four predefined constants that are stored as named variables:
e = 2.71828182845905
– the base of the natural logarithms (Euler’s number);
π = 3.14159265358979
– (Pi) the ratio of circumference to diameter of a circle;
g = 9.80665
– the gravitational acceleration on Earth;
i = 1i
– the imaginary unit.
Variables
Variable names can contain Latin and Greek letters, digits, commas and underscores “_”. The first character must be a letter. Use underscore to start a subscript. Variables are created by assigning a value, e.g.:
a_1 = 2
Operators
You can use the following operators with Calcpad:
Type | Symbol | Description |
---|---|---|
arithmetic | ^ | exponent |
/ | division | |
* | multiplication | |
– | subtraction | |
+ | addition | |
integer | \ | integer division |
% | reminder | |
comparison | ≡ | equal |
≠ | unequal | |
< | less than | |
> | greater than | |
≤ | less or equal | |
≥ | greater or equal | |
special | = | assignment |
? | requires input |
Functions
Built-in
The following functions are predefined and can be used directly:
Type | Name | Description |
---|---|---|
abs(x) | absolute value (modulus) |x| | |
trigonometric | sin(x) | sine |
cos(x) | cosine | |
tan(x) | tangent = sin(x)/cos(x), for each x ≠ kπ, k=1, 2, 3… | |
cot(x) | cotangent = cos(x)/sin(x), for each x ≠ π/2 + kπ, k=1, 2, 3… | |
inverse trigonometric | asin(x) | inverted sine, defined for -1 ≤ x ≤ 1 |
acos(x) | inverted cosine, defined for -1 ≤ x ≤ 1 | |
atan(x) | inverted tangent | |
acot(x) | inverted cotangent | |
hyperbolic | sinh(x) | hyperbolic sine = (e^{x} – e^{-x})/2 |
cosh(x) | hyperbolic cosine = (e^{x} + e^{-x})/2 | |
tanh(x) | hyperbolic tangent = (e^{x} – e^{-x})/(e^{x} + e^{-x}) | |
coth(x) | hyperbolic cotangent = (e^{x} + e^{-x})/(e^{x} – e^{-x}), for x ≠ 0 | |
inverse hyperbolic | asinh(x) | inverted hyperbolic sine = ln(x + √(x^{2} + 1)), defined for -∞ ≤ x ≤ +∞ |
acosh(x) | inverted hyperbolic cosine = ln(x + √(x + 1)·√(x – 1)), defined for x ≥ 1 | |
atanh(x) | inverted hyperbolic tangent = 1/2·ln[(1 + x) / (1 – x)], for -1 < x < 1 | |
acoth(x) | inverted hyperbolic cotangent = 1/2·ln[(x + 1) / (x – 1)], for |x| > 1 | |
logarithmic and sq. root | log(x) | decimal logarithm (with base 10), for each x > 0 |
ln(x) | natural logarithm (with base e ≈ 2.7183), for each x > 0 | |
sqr(x) or sqrt(x) | square root (√x), defined for each x ≥ 0 | |
comparison | min(x; y) | the smaller value from x and y |
max(x; y) | the greater value from x and y | |
rounding | round(x) | rounds to the nearest integer |
floor(x) | rounds to the smaller integer | |
ceiling(x) | rounds to the greater integer | |
complex | re(a + bi) | returns the real part only, re(a + bi) = a |
im(a + bi) | returns the imaginary part as a real number, im(a + bi) = b | |
abs(a + bi) | complex number modulus = sqrt(a^2 + b^2) | |
phase(x) | complex number phase (argument) = atan2(a; b) |
Custom
You can define custom functions of multiple arguments:
f(x; y; z; ...) =
Function names are formed by the same rules as for variable names (see above).
Potting
There are several different plotting commands:
$Plot{y(x) @ x = a : b}
– Plots the function y(x) within the interval [a; b].
$Plot{y1(x) & y2(x) & ... @ x = a : b}
– Plots several functions y1(x), y2(x), etc. in a single plot.
$Plot{x(t) | y(t) @ t = a : b}
– Plots a curve where both x(t) and y(t) are functions of a single parameter t.
$Plot{x1(t) | y1(t) & x2(t) | y2(t) & ... @ t = a : b}
– Plots several parametric curves on a single plot.
$Map{f(x; y) @ x = a : b & y = c : d}
– Plots a function of two variables as a color/grayscale map.
Size of plot area
You can specify the size of the plot area in pixels by defining the PlotWidth and PlotHeight variables, e.g.:
PlotWidth = 400 PlotHeight = 250
The above values are actually the default ones.
Numerical and iterative procedures
You can use numerical methods for problems that do not have a closed form solution:
$Root{f(x) @ x = a : b}
– Finds the root of the equation f(x) = 0 within the interval [a; b], using the bisection method.
$Inf{f(x) @ x = a : b}
– Finds the minimum value f_inf of the function f(x), using the golden section search method. The location of minimum on the abscissa is stored in the x_inf variable.
$Sup{f(x) @ x = a : b}
– Finds the maximum value f_sup of the function f(x), using the golden section search method. The location of maximum on the abscissa is stored in the x_sup variable.
$Area{f(x) @ x = a : b}
– Finds the definite integral of the function f(x) in the interval [a; b], using the adaptive Simpson’s method.
$Slope{f(x) @ x = a}
– Finds the slope of the tangent to f(x) at the point x = a.
$Sum{f(k) @ k = a : b}
– Sums the values of f(x) for all integer values of k between a and b.
$Product{f(k) @ k = a : b}
– Multiplies the values of f(x) for all integer values of k between a and b.
You can use this command to define your own function for calculation of factorial and binomial coefficients:
F(n) = $Product{k @ k = 1 : n} C(n; k) = $Product{(i + n - k)/i @ i = 1 : k}
$Repeat{f(k) @ k = a : b}
– Calculates f(x) repeatedly for all integer values of k between a and b.
$Repeat{x = f(x; k) @ k = a : b}
– Similar to the above, but sores the result into a variable to be used for the next iteration.
Units of measurement
Calcpad supports the use of physical units in the calculations. Just write the units next to the respective values. You can also specify target units for the result, separated by a vertical bar at the end:
1.23m + 35cm + 12mm|cm
The above expression will evaluate to 159.2 cm. Version 3.0 supports metric, imperial and US units.
Metric units (SI and compatible):
Physical property | Units of measurement |
---|---|
Mass | g (gram), hg, kg, t, kt, Mt, Gt, dg, cg, mg, μg, ng, pg |
Length | m (meter), km, dm, cm, mm, μm, nm, pm |
Time | s (second), ms, μs, ns, ps, min, h |
Frequency | Hz (Hertz), kHz, MHz, GHz, THz, rpm (rotations per minute) |
Velocity | kmh (km per hour) |
Electric current | A (Ampere), kA, MA, GA, TA, mA, μA, nA, pA |
Temperature | °C (degree Celsius), Δ°C (difference of one °C), K (Kelvin) |
Amount of substance | mol (mole) |
Luminous intensity | cd (candela) |
Area | a (are), daa (decare), ha (hectare) |
Volume | L (liter), mL, cL, dL, hL |
Force | N (Newton), daN, hN, kN, MN, GN, TN |
Moment | Nm (Newton-meter), kNm |
Pressure | Pa (Pascal), daPa, hPa, kPa, MPa, GPa, TPa, Torr |
Energy, work | J (Joule), kJ, MJ, GJ, TJ, mJ, μJ, nJ, pJ, Wh, kWh, MWh, GWh, TWh |
Power | W (Watt), kW, MW, GW, TW, mW, μW, nW, pW |
Electric charge | C (Coulomb), kC, MC, GC, TC, mC, μC, nC, pC, Ah, mAh |
Potential | V (Volt), kV, MV, GV, TV, mV, μV, nV, pV |
Capacitance | F (Farad), kF, MF, GF, TF, mF, μF, nF, pF |
Resistance | Ω (Ohm), kΩ, MΩ, GΩ, TΩ, mΩ, μΩ, nΩ, pΩ |
Conductance | S (Siemens), kS, MS, GS, TS, mS, μS, nS, pS |
Magnetic flux | Wb (Weber), kWb, MWb, GWb, TWb, mWb, μWb, nWb, pWb |
Magnetic flux density | T (Tesla), kT, MT, GT, TT, mT, μT, nT, pT |
Inductance | H (Henry), kH, MH, GH, TH, mH, μH, nH, pH |
Luminous flux | lm (lumen) |
Illuminance | lx (lux) |
Radioactivity | Bq (Becquerel) |
Absorbed dose | Gy (Gray), mGy, μGy |
Equivalent dose | Sv (Sievert), mSv, μSv |
Catalytic activity | kat (katal) |
Imperial/USCS units:
Physical property | Units of measurement |
---|---|
Mass | gr (grain), dr (drachm), oz (ounce), lb (pound), kip (kilopound), st (stone), qr (quarter), cwt (hundredweight), ton, slug |
Length | th (thou), in (inch), ft (foot), yd (yard), ch (chain), fur (furlong), mi (mile), ftm (fathom), cable, nmi (nautical mile), li (link), rod, pole, perch, lea (league) |
Velocity | mph (miles per hour) |
Temperature | °F (degree Fahrenheit), Δ°F (difference of one °F), R (Rankine) |
Area | rood, ac (acre) |
Volume (fluid) | fl_oz (fluid), gi (gill), pt (pint), qt (quart), gal (gallon), bbl (barrel) |
Force | ozf (ounce-force), lbf (pound-force), kipf (kilopound-force), tonf (ton-force) |
Pressure | psi (pounds per sq. inch), ksi (kilopounds per sq. inch) |
Comments
Everything inside a Calcpad script is considered to be math expressions unless it is enclosed by quotes. Then it is treated as comments and it is simply passed to the output. You can use comments to add other contents to your calculation notes, such as titles, text, images, tables etc.
You can use double (“) or single (‘) quotes. Double quotes are used for “titles” and single quotes for ‘normal text’. You can mix several expressions, separated by comments on a single line. The closing quote is not required if there is nothing else on the line.
Comments can contain plain text as well as Html, CSS, JS (jQuery), SVG<, etc. for providing rich formatting and user experience for your calculation notes.
For example, you can use Html to fold part of the content:
'<div class="fold"> "This is a folded content 'This line is hidden unit you unfold it. '</div>
Program flow control
You can split the flow of your calculation notes depending on certain intermediate values. It will not only use different formulas for calculations, but it can also display different text and images in your report.
You can use the following patterns:
Conditions
#If ◄condition1► ◄code if condition1 is true► #Else If ◄condition1► ◄code if condition2 is true► #Else If ◄condition3► ... #Else ◄code if non of the conditions is true► #end if
Shorter forms are also possible:
#If ◄condition► ◄code if condition is true► #Else ◄code if conditions is false► #end if
or:
#If ◄condition► ◄code if condition is true► #end if
Loops
Simple:
#Repeat n ◄Put some code here.► #Loop
Here n is the number of iterations and not the counter. If you need a counter, you have to define it as follows:
i = 0 #Repeat n i = i + 1 ◄Put some code here.► #Loop
With conditional break:
#Repeat ◄Put some code here.► #If ◄condition► #Break #End if #Loop
Output control
You can control the visibility of your code in the output using the following keywords:
#Hide
– hide the contents after the current line;
#Pre
– show the contents in input form mode only (see “Input forms” bellow) and hide it otherwise;
#Post
– show the contents in calculated mode only and hide it in input form mode;
#Show
– always show the contents (revoke all other commands);
You can also modify the rendering style of the calculations as follows:
#Val
– shows only the answer as a single value;
#Equ
– shows the whole expression.
The next two keywords allows you to select the default units for angles inside your calculation notes:
#deg
– assumes that angles are in degrees: sin(90) = 1;
#rad
– assumes that angles are in radians: sin(π/2) = 1;
These settings affect all the calculations after the current line.