Topic: Expressions
Online Help
Functions
Library (built-in) functions
Calcpad includes a library with common math functions, ready to use. All library function names are lower case. Like variables, function names are case sensitive, so "sin(x)" is the library sine function, but "Sin(x)" and "SIN(x)" are not. The available library functions are:
- Trigonometric:
sin(x)- sine;cos(x)- cosine;tan(x)- tangent =sin(x)/cos(x), for each x ≠ kπ, k=1, 2, 3…;csc(x)- cosecant =1/sin(x), for each x ≠ kπ, k=1, 2, 3…;sec(x)- secant =1/cos(x), for each x ≠ π/2 + kπ, k=1, 2, 3…;cot(x)- cotangent =cos(x)/sin(x), for each x ≠ π/2 + kπ, k=1, 2, 3…;
- Hyperbolic:
sinh(x)- hyperbolic sine =(ex - e-x)/2;cosh(x)- hyperbolic cosine =(ex + e-x)/2;tanh(x)- hyperbolic tangent =(ex - e-x)/(ex + e-x);csch(x)- hyperbolic cosecant =1/sinh(x);sech(x)- hyperbolic secant =1/cosh(x);coth(x)- hyperbolic cotangent =(ex + e-x)/(ex - e-x), for x ≠ 0;
- Inverse trigonometric:
asin(x)- inverse sine, defined for -1 ≤ x ≤ 1;acos(x)- inverse cosine, defined for -1 ≤ x ≤ 1;atan(x)- inverse tangent;atan2(x; y)- the angle whose tangent is the quotient of y and x;acsc(x)- inverse cosecant =asin(1/x);asec(x)- inverse secant =acos(1/x);acot(x)- inverse cotangent;
- Inverse hyperbolic:
asinh(x)- inverse hyperbolic sine =ln(x + √x2 + 1), defined for -∞ ≤ x ≤ +∞;acosh(x)- inverse hyperbolic cosine =ln(x + √x + 1·√x - 1), defined for x ≥ 1;atanh(x)- inverse hyperbolic tangent =1/2·ln[(1 + x)/(1 - x)], for -1 < x < 1;acsch(x)- inverse hyperbolic cosecant =atanh(1/x);asech(x)- inverse hyperbolic secant =acosh(1/x);acoth(x)- inverse hyperbolic cotangent =1/2·ln[(x + 1)/(x - 1)], for |x| > 1;
- Logarithmic, exponential and roots:
log(x)- decimal logarithm (with base 10), for each x > 0;ln(x)- natural logarithm (with base e ≈ 2.7183), for each x > 0;log_2(x)- binary logarithm (with base 2), for each x > 0;log1p(x)- decimal logarithm of 1 + x, for each x > -1. Unlikelog(1 + x), it is accurate also for small |x|, where the digits of x are lost in the sum 1 + x;ln1p(x)- natural logarithm of 1 + x, for each x > -1, accurate also for small |x|;exp(x)- exponential function = e ˣ;sqr(x)orsqrt(x)- square root (√x ), defined for each x ≥ 0;cbrt(x)- cubic root ( 3√x );root(x; n)- n-th root ( n√x );
- Rounding:
round(x)- rounds to the nearest integer;floor(x)- rounds to the smaller integer (towards -∞);ceiling(x)- rounds to the greater integer (towards +∞);trunc(x)- rounds to the smaller integer (towards zero);
- Integer:
mod(x; y)- the remainder of an integer division;gcd(A; ⃗b; c…)- the greatest common divisor of several integers;lcm(A; ⃗b; c…)- the least common multiple of several integers;
- 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 modulus = sqrt(a2 + b2);phase(a + bi)- complex number phase (argument) = atan2(a; b);conj(a + bi)- complex number conjugate = a - bi.
- Aggregate and interpolation:
min(A; ⃗b; c…)- the smallest of multiple values;max(A; ⃗b; c…)- the greatest of multiple values;sum(A; ⃗b; c…)- sum of multiple values;sumsq(A; ⃗b; c…)- sum of squares;srss(A; ⃗b; c…)- square root of sum of squares;average(A; ⃗b; c…)- average of multiple values (alias: mean);product(A; ⃗b; c…)- product of multiple valuesgeomean(A; ⃗b; c…)- geometric mean;take(n; A; ⃗b; c…)- the n-th element from the list;line(x; A; ⃗b; c…)- performs linear interpolation among the specified values for parameter x;spline(x; A; ⃗b; c…)- performs Hermite spline interpolation;
- Conditional and logical:
if(cond; value-if-true; value-if-false)- if the condition cond is satisfied, the function returns the first value, otherwise it returns the second value. The condition is satisfied when it evaluates to any non-zero number;switch(cond1; value1; cond2; value2;…; default-value)- returns the value for which the respective condition is satisfied. Conditions are checked from left to right. If none is satisfied, it returns the default value in the end;not(x)- logical "not";and(A; ⃗b; c…)- logical "and";or(A; ⃗b; c…)- logical "or";xor(A; ⃗b; c…)- logical "xor";
- Vector:
- Creational:
vector(n)- creates an empty vector with length n;vector_hp(n)- creates an empty high performance (hp) vector with length n;range(x1; xn; s)- creates a vector with values spanning from x1 to xn with step s;range_hp(x1; xn; s)- creates a high performance (hp) vector from a range of values;
- Structural:
len(⃗v)- returns the length of vector ⃗v;size(⃗v)- the actual size of vector ⃗v (the index of the last non-zero element);resize(⃗v; n)- sets a new length n of vector ⃗v;fill(⃗v; x)- fills vector ⃗v with value x;join(A; ⃗b; c…)- creates a vector by joining the arguments in the list - matrices, vectors and scalars;slice(⃗v; i1; i2)- returns the part of vector ⃗v, bounded by indexes i1 and i2, inclusively;first(⃗v; n)- the first n elements of vector ⃗v;last(⃗v; n)- the last n elements of vector ⃗v;extract(⃗v; ⃗i)- extracts the elements from ⃗v which indexes are contained in ⃗i;
- Data:
sort(⃗v)- sorts the elements of vector ⃗v in ascending order;rsort(⃗v)- sorts the elements of vector ⃗v in descending order;order(⃗v)- the indexes of vector ⃗v, by ascending order of its elements;revorder(⃗v)- the indexes of vector ⃗v, by descending order of its elements;reverse(⃗v)- a vector containing the elements of ⃗v in reverse order;count(⃗v; x; i)- number of elements of vector ⃗v, after the i-th incl., that are equal to x;search(⃗v; x; i)- the index of the first element in ⃗v, after the i-th incl., that is equal to x;find(⃗v; x; i)orfind_eq(⃗v; x; i)- the indexes of all elements in ⃗v, after the i-th incl., that are = x;find_ne(⃗v; x; i)- the indexes of all elements in ⃗v, after the i-th incl. that are ≠ x;find_lt(⃗v; x; i)- the indexes of all elements in ⃗v, after the i-th incl., that are < x;find_le(⃗v; x; i)- the indexes of all elements in ⃗v, after the i-th incl., that are ≤ x;find_gt(⃗v; x; i)- the indexes of all elements in ⃗v, after the i-th incl., that are > x;find_ge(⃗v; x; i)- the indexes of all elements in ⃗v, after the i-th incl., that are ≥ x;lookup(⃗a; ⃗b; x)orlookup_eq(⃗a; ⃗b; x)- all elements in ⃗b for which the corresponding elements in ⃗a are = x;lookup_ne(⃗a; ⃗b; x)- all elements in ⃗b for which the corresponding elements in ⃗a are ≠ x;lookup_lt(⃗a; ⃗b; x)- all elements in ⃗b for which the corresponding elements in ⃗a are < x;lookup_le(⃗a; ⃗b; x)- all elements in ⃗b for which the corresponding elements in ⃗a are ≤ x;lookup_gt(⃗a; ⃗b; x)- all elements in ⃗b for which the corresponding elements in ⃗a are > x;lookup_ge(⃗a; ⃗b; x)- all elements in ⃗b for which the corresponding elements in ⃗a are ≥ x;
- Math:
norm_1(⃗v)- L1 (Manhattan) norm of vector ⃗v;norm(⃗v)ornorm_2(⃗v)ornorm_e(⃗v)- L2 (Euclidean) norm of vector ⃗v;norm_p(⃗v; p)- Lp norm of vector ⃗v;norm_i(⃗v)- L∞ (infinity) norm of vector ⃗v;unit(⃗v)- the normalized vector ⃗v (with L2 norm = 1);dot(⃗a; ⃗b)- scalar product of two vectors ⃗a and ⃗b;cross(⃗a; ⃗b)- cross product of two vectors ⃗a and ⃗b (with length 2 or 3);polyroots(⃗a)- finds all real roots of the polynomial: a₁ + a₂·x + a₃·x² + ... + aₙ₊₁·xⁿ;
- Creational:
- Matrix:
- Creational:
matrix(m; n)- creates an empty matrix with dimensions m⨯n;identity(n)- creates an identity matrix with dimensions n⨯n;diagonal(n; d)- creates a diagonal n⨯n matrix and fills the diagonal with value d;column(m; c)- creates a column matrix with dimensions m⨯1, filled with value c;utriang(n)- creates an upper triangular matrix with dimensions n⨯n;ltriang(n)- creates a lower triangular matrix with dimensions n⨯n;symmetric(n)- creates a symmetric matrix with dimensions n⨯n;matrix_hp(m; n)- creates a high-performance empty matrix with dimensions m⨯n;identity_hp(n)- creates a high-performance identity matrix with dimensions n⨯n;diagonal_hp(n; d)- creates a high-performance n⨯n diagonal matrix filled with value d;column_hp(m; c)- creates a high-performance m⨯1 column matrix filled with value c;utriang_hp(n)- creates a high-performance n⨯n upper triangular matrix;ltriang_hp(n)- creates a high-performance n⨯n lower triangular matrix;symmetric_hp(n)- creates a high-performance n⨯n symmetric matrix;vec2diag(⃗v)- creates a diagonal matrix from the elements of vector ⃗v;vec2row(⃗v)- creates a row matrix from the elements of vector ⃗v;vec2col(⃗v)- creates a column matrix from the elements of vector ⃗v;join_cols(⃗c1; ⃗c2; ⃗c3…)- creates a new matrix by joining column vectors;join_rows(⃗r1; ⃗r2; ⃗r3…)- creates a new matrix by joining row vectors;augment(A; ⃗b; c…)- creates a new matrix by appending matrices A; ⃗b; c… side by side;stack(A; ⃗b; c…)- creates a new matrix by stacking matrices A; ⃗b; c… one below the other;
- Structural (matrices and tables):
n_rows(M)- number of rows in matrix M;n_cols(M)- number of columns in matrix M;mresize(M; m; n)- sets new dimensions m and n for matrix M;mfill(M; x)- fills matrix M with value x;fill_row(M; i; x)- fills the i-th row of matrix M with value x;fill_col(M; j; x)- fills the j-th column of matrix M with value x;copy(A; B; i; j)- copies all elements from A to B, starting from indexes i and j of B;add(A; B; i; j)- adds all elements from A to those of B, starting from indexes i and j of B;row(M; i)- extracts the i-th row of matrix M as a vector;col(M; j)- extracts the j-th column of matrix M as a vector;extract_rows(M; ⃗i)- extracts the rows from matrix M whose indexes are contained in vector ⃗i;extract_cols(M; ⃗j)- extracts the columns from matrix M whose indexes are contained in vector ⃗j;diag2vec(M)- extracts the diagonal elements of matrix M to a vector;submatrix(M; i1; i2; j1; j2)- extracts a submatrix of M, bounded by rows i1 and i2 and columns j1 and j2, incl.;
- Data (matrices and tables):
sort_cols(M; i)- sorts the columns of M based on the values in row i in ascending order;rsort_cols(M; i)- sorts the columns of M based on the values in row i in descending order;sort_rows(M; j)- sorts the rows of M based on the values in column j in ascending order;rsort_rows(M; j)- sorts the rows of M based on the values in column j in descending order;order_cols(M; i)- the indexes of the columns of M based on the ordering of the values from row i in ascending order;revorder_cols(M; i)- the indexes of the columns of M based on the ordering of the values from row i in descending order;order_rows(M; j)- the indexes of the rows of M based on the ordering of the values in column j in ascending order;revorder_rows(M; j)- the indexes of the rows of M based on the ordering of the values in column j in descending order;mcount(M; x)- number of occurrences of value x in matrix M;msearch(M; x; i; j)- vector with the two indexes of the first occurrence of x in matrix M, starting from indexes i and j;mfind(M; x)ormfind_eq(M; x)- the indexes of all elements in M equal to x;mfind_ne(M; x)- the indexes of all elements in M not equal to x;mfind_lt(M; x)- the indexes of all elements in M less than x;mfind_le(M; x)- the indexes of all elements in M less than or equal to x;mfind_gt(M; x)- the indexes of all elements in M greater than x;mfind_ge(M; x)- the indexes of all elements in M greater than or equal to x;hlookup(M; x; i1; i2)orhlookup_eq(M; x; i1; i2)- the values from row i2 of M, for which the elements in row i1 are equal to x;hlookup_ne(M; x; i1; i2)- the values from row i2 of M, for which the elements in row i1 are not equal to x;hlookup_lt(M; x; i1; i2)- the values from row i2 of M, for which the elements in row i1 are less than x;hlookup_le(M; x; i1; i2)- the values from row i2 of M, for which the elements in row i1 are less than or equal to x;hlookup_gt(M; x; i1; i2)- the values from row i2 of M, for which the elements in row i1 are greater than x;hlookup_ge(M; x; i1; i2)- the values from row i2 of M, for which the elements in row i1 are greater than or equal to x;vlookup(M; x; j1; j2)orvlookup_eq(M; x; j1; j2)- the values from column j2 of M, for which the elements in column j1 are equal to x;vlookup_ne(M; x; j1; j2)- the values from column j2 of M, for which the elements in column j1 are not equal to x;vlookup_lt(M; x; j1; j2)- the values from column j2 of M, for which the elements in column j1 are less than x;vlookup_le(M; x; j1; j2)- the values from column j2 of M, for which the elements in column j1 are less than or equal to x;vlookup_gt(M; x; j1; j2)- the values from column j2 of M, for which the elements in column j1 are greater than x;vlookup_ge(M; x; j1; j2)- the values from column j2 of M, for which the elements in column j1 are greater than or equal to x;
- Math:
hprod(A; B)- Hadamard product of matrices A and B;fprod(A; B)- Frobenius product of matrices A and B;kprod(A; B)- Kronecker product of matrices A and B;mnorm_1(M)- L1 norm of matrix M;mnorm(M)ormnorm_2(M)- L2 norm of matrix M;mnorm_e(M)- Frobenius norm of matrix M;mnorm_i(M)- L∞ norm of matrix M;cond_1(M)- condition number of M based on the L1 norm;cond(M)orcond_2(M)- condition number of M based on the L2 norm;cond_e(M)- condition number of M based on the Frobenius norm;cond_i(M)- condition number of M based on the L∞ norm;det(M)- determinant of matrix M;rank(M)- rank of matrix M;trace(M)- trace of matrix M;transp(M)- transpose of matrix M;adj(M)- adjugate of matrix M;cofactor(M)- cofactor matrix of M;eigenvals(M; ne)- the first ne eigenvalues of matrix M (or all if omitted);eigenvecs(M; ne)- the first ne eigenvectors of matrix M (or all if omitted);eigen(M; ne)- the first ne eigenvalues and eigenvectors of matrix M (or all if omitted);cholesky(M)- Cholesky decomposition of a symmetric, positive-definite matrix M;lu(M)- LU decomposition of matrix M;qr(M)- QR decomposition of matrix M;svd(M)- singular value decomposition of M;inverse(M)- inverse of matrix M;lsolve(A; ⃗b)- solves the system of linear equations A⃗x = ⃗b using LDLT decomposition for symmetric matrices, and LU for non-symmetric;clsolve(A; ⃗b)- solves the linear matrix equation A⃗x = ⃗b with symmetric, positive-definite coefficient matrix A using Cholesky decomposition;slsolve(A; ⃗b)- solves the linear matrix equation A⃗x = ⃗b with high-performance symmetric, positive-definite matrix A using preconditioned conjugate gradient (PCG) method;msolve(A; B)- solves the generalized matrix equation AX = B using LDLT decomposition for symmetric matrices, and LU for non-symmetric;cmsolve(A; B)- solves the generalized matrix equation AX = B with symmetric, positive-definite coefficient matrix A using Cholesky decomposition;smsolve(A; B)- solves the generalized matrix equation AX = B with high-performance symmetric, positive-definite matrix A using preconditioned conjugate gradient (PCG) method;matmul(A; B)- fast multiplication of square hp matrices using parallel Winograd algorithm. The multiplication operator A*B uses it automatically for all square hp matrices of size 10 and larger;fft(M)- performs fast Fourier transform of row-major matrix M. It must have one row for real data and two rows for complex;ift(M)- performs inverse Fourier transform of row-major matrix M. It must have one row for real data and two rows for complex;
- Double interpolation:
take(x; y; M)- returns the element of matrix M at indexes x and y;line(x; y; M)- double linear interpolation from the elements of matrix M based on the values of x and y;spline(x; y; M)- double Hermite spline interpolation from the elements of matrix M based on the values of x and y.
- Creational:
- Special (Pro only):
- Gamma and beta functions:
gamma(x)- gamma function Γ(x);gammaln(x)- natural logarithm of the absolute value of the gamma function ln|Γ(x)|;digamma(x)- digamma function ψ(x) = Γ′(x)/Γ(x);polygamma(n; x)- polygamma function ψ⁽ⁿ⁾(x), the n-th derivative of the digamma function;gammainc_(s; x)- lower incomplete gamma function γ(s, x);gammainc‾(s; x)- upper incomplete gamma function Γ(s, x);beta(a; b)- beta function B(a, b);betainc(x; a; b)- regularized incomplete beta function Iₓ(a, b);
- Error function and Fresnel integrals:
erf(x)- error function erf(x);erfc(x)- complementary error function erfc(x) = 1 − erf(x);erfinv(x)- inverse error function erf⁻¹(x);erfcinv(x)- inverse complementary error function erfc⁻¹(x);dawsonf(x)- Dawson's integral F(x) = exp(−x²)∫₀ˣ exp(t²) dt;fresnelc(x)- Fresnel cosine integral C(x) = ∫₀ˣ cos(t²) dt;fresnels(x)- Fresnel sine integral S(x) = ∫₀ˣ sin(t²) dt;
- Exponential, logarithmic, sine and cosine integrals:
ei(x)- exponential integral Ei(x);li(x)- logarithmic integral li(x);si(x)- sine integral Si(x);ci(x)- cosine integral Ci(x);shi(x)- hyperbolic sine integral Shi(x);chi(x)- hyperbolic cosine integral Chi(x);
- Elliptic integrals:
elliptick(m)- complete elliptic integral of the first kind K(m);elliptice(m)- complete elliptic integral of the second kind E(m);ellipticp(n; m)- complete elliptic integral of the third kind Π(n|m);ellipticf(φ; m)- incomplete elliptic integral of the first kind F(φ|m);ellipticei(φ; m)- incomplete elliptic integral of the second kind E(φ|m);ellipticpi(n; φ; m)- incomplete elliptic integral of the third kind Π(n; φ|m);
- Jacobi elliptic functions:
jacobiam(u; m)- Jacobi amplitude am(u|m);jacobisn(u; m)- Jacobi elliptic function sn(u|m);jacobicn(u; m)- Jacobi elliptic function cn(u|m);jacobidn(u; m)- Jacobi elliptic function dn(u|m);jacobics(u; m)- Jacobi elliptic function cs(u|m);jacobicd(u; m)- Jacobi elliptic function cd(u|m);jacobidc(u; m)- Jacobi elliptic function dc(u|m);jacobisc(u; m)- Jacobi elliptic function sc(u|m);jacobisd(u; m)- Jacobi elliptic function sd(u|m);jacobids(u; m)- Jacobi elliptic function ds(u|m);jacobins(u; m)- Jacobi elliptic function ns(u|m);jacobinc(u; m)- Jacobi elliptic function nc(u|m);jacobind(u; m)- Jacobi elliptic function nd(u|m);
- Bessel functions:
besselj0(x)- Bessel function of the first kind J₀(x);besselj1(x)- Bessel function of the first kind J₁(x);bessely0(x)- Bessel function of the second kind Y₀(x);bessely1(x)- Bessel function of the second kind Y₁(x);besseljn(n; x)- Bessel function of the first kind Jₙ(x) of integer order n;besselyn(n; x)- Bessel function of the second kind Yₙ(x) of integer order n;besseljv(ν; x)- Bessel function of the first kind J_ν(x) of real order ν;besselyv(ν; x)- Bessel function of the second kind Y_ν(x) of real order ν;besseljv′(ν; x)- derivative J′_ν(x) of the Bessel function of the first kind;besselyv′(ν; x)- derivative Y′_ν(x) of the Bessel function of the second kind;besseljs(n; x)- spherical Bessel function of the first kind jₙ(x);besselys(n; x)- spherical Bessel function of the second kind yₙ(x);besseljs′(n; x)- derivative j′ₙ(x) of the spherical Bessel function of the first kind;besselys′(n; x)- derivative y′ₙ(x) of the spherical Bessel function of the second kind;
- Modified Bessel functions:
besseli0(x)- modified Bessel function of the first kind I₀(x);besseli1(x)- modified Bessel function of the first kind I₁(x);besselk0(x)- modified Bessel function of the second kind K₀(x);besselk1(x)- modified Bessel function of the second kind K₁(x);besselin(n; x)- modified Bessel function of the first kind Iₙ(x) of integer order n;besselkn(n; x)- modified Bessel function of the second kind Kₙ(x) of integer order n;besseliv(ν; x)- modified Bessel function of the first kind I_ν(x) of real order ν;besselkv(ν; x)- modified Bessel function of the second kind K_ν(x) of real order ν;besseliv′(ν; x)- derivative I′_ν(x) of the modified Bessel function of the first kind;besselkv′(ν; x)- derivative K′_ν(x) of the modified Bessel function of the second kind;
- Airy functions:
ai(x)- Airy function Ai(x);bi(x)- Airy function Bi(x);ai′(x)- derivative Ai′(x) of the Airy function;bi′(x)- derivative Bi′(x) of the Airy function;
- Zeta and Lambert W functions:
zeta(s)- Riemann zeta function ζ(s);eta(s)- Dirichlet eta function η(s);lambertw(x)- Lambert W function (principal branch W₀);
In complex mode, all special functions also accept complex arguments, except that the orders of Bessel functions must be real, and the orders n of polygamma and the Bessel functions of integer order must be integers. All arguments must be unitless, except for the amplitude φ of elliptic integrals, which is an angle and follows the current angle units. jacobiam also returns an angle.
- Gamma and beta functions:
- Statistical (Pro only):
- Descriptive statistics:
median(A; ⃗b; c…)- median of multiple values;quantile(A; ⃗b; c…; p)- sample quantile for probability p (the last argument), linearly interpolated between the sorted values (as Excel QUANTILE.INC);stdev(A; ⃗b; c…)- sample standard deviation;variance(A; ⃗b; c…)- sample variance;skew(A; ⃗b; c…)- sample skewness (as Excel SKEW);kurt(A; ⃗b; c…)- sample excess kurtosis (as Excel KURT);
- Two samples and ranks:
covar(⃗a; ⃗b)- sample covariance of vectors ⃗a and ⃗b;correl(⃗a; ⃗b)- Pearson correlation coefficient of vectors ⃗a and ⃗b. Spearman's rank correlation is correl(ranks(⃗a); ranks(⃗b));linreg(⃗x; ⃗y)- least squares line y = a + b·x, returned as the vector [a; b];ranks(⃗v)- ranks of the elements of vector ⃗v in ascending order. Equal values get the average of their ranks;frequency(⃗v; ⃗b)- counts of the elements of vector ⃗v in the bins with upper bounds in vector ⃗b (as Excel FREQUENCY). The last count is for the values above the last bound;
- Combinatorics:
combin(n; k)- number of combinations of n items taken k at a time;permut(n; k)- number of permutations of n items taken k at a time;
- Probability distributions:
normpdf(x; μ; σ)- probability density function of the normal distribution with mean μ and standard deviation σ;normcdf(x; μ; σ)- cumulative distribution function of the normal distribution with mean μ and standard deviation σ;norminv(p; μ; σ)- quantile (inverse cumulative distribution function) of the normal distribution with mean μ and standard deviation σ;lognpdf(x; μ; σ)- probability density function of the lognormal distribution, where ln x has mean μ and standard deviation σ;logncdf(x; μ; σ)- cumulative distribution function of the lognormal distribution, where ln x has mean μ and standard deviation σ;logninv(p; μ; σ)- quantile (inverse cumulative distribution function) of the lognormal distribution, where ln x has mean μ and standard deviation σ;tpdf(t; ν)- probability density function of Student's t-distribution with ν degrees of freedom;tcdf(t; ν)- cumulative distribution function of Student's t-distribution with ν degrees of freedom;tinv(p; ν)- quantile (inverse cumulative distribution function) of Student's t-distribution with ν degrees of freedom;chi2pdf(x; k)- probability density function of the χ² distribution with k degrees of freedom;chi2cdf(x; k)- cumulative distribution function of the χ² distribution with k degrees of freedom;chi2inv(p; k)- quantile (inverse cumulative distribution function) of the χ² distribution with k degrees of freedom;gumbelpdf(x; μ; β)- probability density function of the Gumbel distribution (of maxima) with location μ and scale β;gumbelcdf(x; μ; β)- cumulative distribution function of the Gumbel distribution (of maxima) with location μ and scale β;gumbelinv(p; μ; β)- quantile (inverse cumulative distribution function) of the Gumbel distribution (of maxima) with location μ and scale β;wblpdf(x; λ; k)- probability density function of the Weibull distribution with scale λ and shape k;wblcdf(x; λ; k)- cumulative distribution function of the Weibull distribution with scale λ and shape k;wblinv(p; λ; k)- quantile (inverse cumulative distribution function) of the Weibull distribution with scale λ and shape k;binopdf(k; n; p)- probability of k successes in n trials with success probability p (binomial distribution);binocdf(k; n; p)- probability of at most k successes in n trials with success probability p (binomial distribution);poisspdf(k; λ)- probability of k events with mean number λ (Poisson distribution);poisscdf(k; λ)- probability of at most k events with mean number λ (Poisson distribution);
The descriptive statistics accept lists of values, vectors and matrices, like sum and average. The probability p of quantile is its last argument. The variance, standard deviation, skewness, kurtosis and covariance are for a sample (with n − 1), as in Excel. The normal, Gumbel and Weibull distributions accept a variable and parameters with consistent units. Statistical functions require real arguments, also in complex mode, except for t of tpdf and tcdf, which can be complex.
- Descriptive statistics:
- Financial (Pro only):
pv(rate; nper; pmt; fv; type)- present value of an investment;fv(rate; nper; pmt; pv; type)- future value of an investment;pmt(rate; nper; pv; fv; type)- periodic payment of a loan or an annuity;nper(rate; pmt; pv; fv; type)- number of periods of an investment;rate(nper; pmt; pv; fv; type; guess)- interest rate per period of an annuity;ipmt(rate; per; nper; pv; fv; type)- interest part of the payment for period per;ppmt(rate; per; nper; pv; fv; type)- principal part of the payment for period per;npv(rate; A; ⃗b; c…)- net present value of cash flows at the end of each period;irr(A; ⃗b; c…)- internal rate of return of cash flows;mirr(A; ⃗b; c…; fr; rr)- modified internal rate of return of cash flows with finance rate fr and reinvestment rate rr;
The financial functions follow Excel and accept their arguments in the same order. The last arguments of pv, fv, pmt, nper, rate, ipmt and ppmt after the third one (the fourth one for ipmt and ppmt) can be omitted: fv and pv are 0 by default, type is 0 for payments at the end of each period (default) and 1 for payments at the beginning, and guess is 10% by default. Rates can be given in %, and amounts of money can have any consistent units. Cash paid out is negative and cash received is positive.
- String (Pro only):
str(x)- converts x to text, as it is displayed in the output;val(s)- converts the text s to a number with optional units;val(M)- converts the string elements of a vector or matrix M to numbers, e.g. to parse the result of split;len(s)- the number of characters in the text s;join(s₁; s₂; s₃…)- joins texts and values into a single text;join(M; colsep; rowsep)- joins the elements of a vector or matrix into a text, with columns separated by colsep and rows by rowsep;left(s; n)- the first n characters of the text s;right(s; n)- the last n characters of the text s;mid(s; i; n)- n characters of the text s, starting from position i;trim(s)- the text s without leading and trailing spaces;ltrim(s)- the text s without leading spaces;rtrim(s)- the text s without trailing spaces;ucase(s)- the text s in upper case;lcase(s)- the text s in lower case;tcase(s)- the text s in title case (the first letter of each word is capital);scase(s)- the text s in sentence case (the first letter of each sentence is capital);instr(s; t; i)- the position of the text t in s, starting from i, or 0 if not found;replace(s; a; b)- the text s with all occurrences of a replaced by b;split(s; sep)- splits the text s at each sep into a vector of strings;split(s; colsep; rowsep)- splits the text s into a matrix of strings, with columns separated by colsep and rows by rowsep;table(M; nhrows; nhcols)- displays the matrix M as a table, with nhrows header rows and nhcols header columns (1 and 0 by default);
Strings and the rules for working with them are described in the "Strings" section.
- CoolProp (Pro only):
CP.Props(Output; Name1; Prop1; Name2; Prop2; Fluid)- property Output of the fluid Fluid at the state given by the state variables Name1 = Prop1 and Name2 = Prop2;CP.Props1(Fluid; Output)- property Output of the fluid Fluid that does not depend on the state, e.g. "Tcrit";CP.HAProps(Output; Name1; Prop1; Name2; Prop2; Name3; Prop3)- property Output of humid air at the state given by Name1 = Prop1, Name2 = Prop2 and Name3 = Prop3;CP.Phase(Name1; Prop1; Name2; Prop2; Fluid)- phase of the fluid Fluid at the given state, as text, e.g. "liquid";CP.SaturationAncillary(Fluid; Output; Q; Input; Value)- saturation property Output of the fluid Fluid from the ancillary equation for Input = Value, for liquid (Q = 0) or vapor (Q = 1);CP.GetFluidParamString(Fluid; Param)- information about the fluid Fluid as text, e.g. Param = "aliases", "CAS" or "ASHRAE34";CP.GetGlobalParamString(Param)- CoolProp information as text, e.g. Param = "version" or "FluidsList";CP.GetParamIndex(Name)- index of the CoolProp parameter Name;CP.GetParameterInformationString(Key; Info)- information about the parameter Key as text, for Info = "IO", "short", "long" or "units";CP.SetReferenceStateD(Fluid; T; RhoMolar; h0; s0)- sets the reference state of the fluid Fluid by temperature T, molar density RhoMolar, molar enthalpy h0 and molar entropy s0;CP.SetReferenceStateS(Fluid; ReferenceState)- sets the reference state of the fluid Fluid: ReferenceState = "IIR", "ASHRAE", "NBP", "DEF" or "RESET";
The thermophysical properties of more than 100 pure fluids, of mixtures and of humid air are calculated by the CoolProp library (CoolProp.dll), which is included with Calcpad. The function names start with "CP." and are case sensitive. Typing "CP." in the editor shows the list of the functions. The fluids, the outputs and the state variables are specified as strings, e.g.
CP.Props("D"; "T"; 25°C; "P"; 1atm; "Water")returns the density of water. The available fluids and parameters are listed in the CoolProp documentation. Inputs with units are converted to the SI units that CoolProp uses, e.g. 25 °C to 298.15 K, and inputs without units are taken in SI units. The results are returned in SI units, which you can convert as usual, e.g.h = CP.Props("H"; "T"; T; "P"; p; "Water")|kJ/kg. Humid air has its own parameters, e.g. "W" is the humidity ratio, "R" is the relative humidity and "D" is the dew point temperature:CP.HAProps("D"; "T"; 25°C; "P"; 1atm; "R"; 50%). The reference state changes the values of enthalpy and entropy in all calculations that follow it. If CoolProp cannot calculate a property, its error message is displayed. - Other:
abs(x)- absolute value (modulus) of a real number | x |;sign(x)- sign of a number = -1, if x < 0; 1, if x > 0; 0, if x = 0;random(x)- a random number between 0 and x;getunits(x)- gets the units of x without the value. Returns 1 if x is unitless;setunits(x; u)- sets the units u to x, where x can be scalar, vector or matrix;clrunits(x)- clears the units from a scalar, vector or matrix x;hp(x)- converts x to its high-performance (hp) equivalent type;ishp(x)- checks if the type of x is a high-performance (hp) vector or matrix;
Arguments must be enclosed by round brackets. They can be constants, variables or any valid expression. Multiple arguments must be separated by semicolons ";". When arguments are out of range, the function returns "Undefined". Exceptions from this rule are "cot(0)" and "coth(0)", which return "+∞".
Arguments of trigonometric functions can be in degrees, radians or grades. The units for angles can be specified in three different ways:
1. By the radio buttons above the output window (🔘D, 🔘R, 🔘G).
2. By compiler switches inside the code. You have to insert a separate line containing: #deg for degrees, #rad for radians or #gra for grades. This will affect all expressions after the current line to the end or until an alternative directive is found.
3. By attaching native units to the value itself: deg, °, ′, ″, rad, grad, rev (see the “Units” section, further in this manual).
Native units are of highest priority, followed by compiler switches in source code. Both override radio buttons settings, which are of lowest priority.
All functions are also defined in the complex domain, except for mod(x; y), gcd(x; y), lcm(x; y), min(x; y) and max(x; y).
Logical functions accept numerical values and return “0” for “false” and “1” for “true”. The results for two arguments (one for “not”) are presented in the following tables:
|
|
|
|
Any numerical value, different from 0, is treated as 1 (true). Multiple arguments are evaluated sequentially from left to right, according to the above tables. We start with the first and the second. Then, the obtained result and the next value are evaluated in turn, and so on.
Rounding of midpoint values with round() evaluates to the nearest integer away from zero. The floor() function rounds to the smaller value (towards -∞). The ceiling() function rounds in the opposite direction to the larger value (towards +∞). Unlike floor(), trunc() rounds towards zero, which is equivalent to simply truncating the fractional part. Some examples for rounding of negative and positive numbers are provided in the table below:
|
Positive
|
Negative
|
Rounding of complex numbers affects both real and imaginary parts.
Custom (user defined) functions
You can define your own functions and use them further in the calculations. Custom functions can have unlimited number of parameters. They are specified after the function name, enclosed in brackets "(" … ")" and separated by semicolons ";". Each function is defined, using the following format: "f ( A; ⃗b; c…; … ) = expression", where "f" is the function name and "x", "y" and "z" are function parameters. On the right side you can have any valid expression including constants, operators, variables and even other functions, e.g.:
f(x) = x^2 + 2*x*sin(x)g(x; y) = f(x)/(y - 4)
Once defined, you can use a function in any expression by inserting a function call. Just write the function name and then specify the arguments in brackets, e. g. b = g(a + 2; 3) + 3. Function names must conform to the same rules as variable names and are also case sensitive. Arguments can be any valid expressions. You have to provide as many arguments as the number of function parameters. The life cycle of a function is from the place of definition to the end of the code. If you define a new function with the same name, the old one will be replaced. You cannot redefine a library function. For example, sin(x) = x^2 will return an error. However, Sin(x) = x^2 is a valid custom function, because its name differs by case.
It is not necessary to pre-define the variables that are used for parameters. However, if other variables are used inside the function body, they must be defined before the first call to the function. Parameters work as local level variables inside the function body. If a variable with the same name exists outside the function, a call to that function will not rewrite the value of the global variable. For example:
- If you have a variable "x = 4"
- and a function "f(x) = x2".
- When you call "f(2)", it will evaluate to x2 = 22 = 4, because local x = 2
- If you call "x2" after that, it will return x2 = 42 = 16, because global x remains 4.
User defined functions support both real and complex numbers.