Home | Overview | Download | Syntax | Math | Text | Code Samples | Forum | Contact
Let's have a look at Agena's functions for:
As you will see, you actually do not have to know much about the interpreter to do some undergraduate math.
Define a function, for example f(x) = sin(x):
> f := << x -> sin(x) >> |
Print a table of values:
> for x from -1 to 1 by 0.5 do > print(x, f(x)) > od; -1 -0.8414709848079 -0.5 -0.4794255386042 0 0 0.5 0.4794255386042 1 0.8414709848079 |
Same, with a little formatting:
> for x from -0.5 to 0.5 by 0.25 do > printf('%+05.2f %+10.6f\n', x, f(x)) > od; -0.50 -0.479426 -0.25 -0.247404 +0.00 +0.000000 +0.25 +0.247404 +0.50 +0.479426 |
Determine all the zeros over [-5, 5]:
> calc.zeros(f, -5, 5): seq(-3.1415926535898, 0, 3.1415926535898) |
Differentiate f at point 0:
> calc.differ(f, 0): 1 |
Evaluate the third derivative of f at point 0:
> calc.differ(f, 0, deriv=3): -0.99999999999983 |
Compute the minimum and maximum values on the interval [-10, 10]:
> calc.minimum(f, -10, 10): seq(-7.8539815784491, -1.5707963196727, 4.7123889665853) > calc.maximum(f, -10, 10): seq(-4.7123889665853, 1.5707963196727, 7.8539815784491) |
Integrate f over [0, Pi]:
> calc.integ(f, 0, Pi): 2 |
Compute the series `Sum(1/n!, n=0 .. 100)` to return an approximation of Euler's number:
> calc.fsum(<< n -> 1/fact(n) >>, 0, 100): 2.718281828459 |
Define two vectors in different fashions: In the simple form, just
pass all components explicitly; or pass only the non-zero components:
> a := < 1, 2, 3 >: < 1, 2, 3 > > b := vector(3, [1 ~ 2]): < 2, 0, 0 > |
Check whether a and b are parallel and have the same direction:
> abs(a+b) = abs(a) + abs(b): false |
Set a vector component by indexing:
> b[3] := 1; |
Now read the modified vector and its rightmost component - a
negative integral index n depicts the |n|-th element from the right::
> b: < 2, 0, 1 > > b[3], b[-1]: 1 1 |
Addition and subtraction:
> a + b: < 3, 2, 4 > > a - b: < -1, 2, 2 > |
Scalar, dot and cross product:
> 2 * a: < 2, 4, 6 > > a * a: 14 > linalg.crossprod(a, b): < 2, 5, -4 > |
Find the vector x which satisfies the matrix equation A x = b. The
matrix constructor expects row vectors.
> A := < < 1, 2, -4 >, < 2, 1, 3 >,
< -3, 1, 6 > >: [ 1, 2, -4 ] [ 2, 1, 3 ] [ -3, 1, 6 ] > b := < -6, 5, -2 >: < -6, 5, -2 > > linalg.linsolve(A, b): < 2, -2, 1 > |
The determinant:
> linalg.det(A): -59 |
First we define a distribution:
> s := seq(10, 8, 1, 6, 5, 2, 9, 7, 3, 4): seq(10, 8, 1, 6, 5, 2, 9, 7, 3, 4) |
Minimum and maximum values in one result:
> stats.minmax(s): seq(1, 10) |
Minimum and maximum observations along with their position in the
distribution:
> stats.min(s): 1 3 > stats.max(s): 10 1 |
Arithmetic mean:
> stats.amean(s): 5.5 |
The median:
> stats.median(s): 5.5 |
For the first quartile, the median and the third quartile of a distribution, along with the minimum, the maximum observation, and the arithmetic mean, in this order, enter:
> stats.fivenum(s): seq(2.75, 5.5, 8.25, 1, 10, 5.5) |
Standard and absolute deviation:
> stats.sd(s): 2.872281323269 > stats.ad(s): 2.5 |
Outliers:
> s := seq(-100, 8, 10, 1, 6, 5, 2, 9, 7, 3, 4, 1000): seq(-100, 8, 10, 1, 6, 5, 2, 9, 7, 3, 4, 1000) > stats.chauvenet(s): seq(1000, -100) |
The Cartesian product:
> combinat.cartprod([[1, 2, 3], [30], [50, 100]]): [[1, 30, 50], [1, 30, 100], [2, 30, 50], [2, 30, 100], [3, 30, 50], [3, 30, 100]] |
Combinations and number of combinations:
> combinat.chosse(3, 2): [[1, 2], [1, 3], [2, 3]] > combinat.numbcomb(3, 2): 3 |
Permutations and number of permutations:
> combinat.permute([1, 2, 3], 3): [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] > combinat.numbperm(3, 2): 6 |
+ |
Addition |
^ |
Exponentiation with rational power |
- |
Subtraction |
** |
Exponentiation with integral power |
* |
Multiplication |
% |
Modulus |
/ |
Division |
\ |
Integer division |
sin(x) |
Sine |
sinh(x) |
Hyperbolic sine |
cos(x) |
Cosine |
cosh(x) |
Hyperbolic cosine |
tan(x) |
Tangent |
tanh(x) |
Hyperbolic tangent |
sec(x) |
Secant |
arcsinh(x) |
Inverse hyperbolic sine |
csc(x) |
Cosecant |
arccosh(x) |
Inverse hyperbolic cosine |
cot(x) |
Cotangent |
arctanh(x) |
Inverse hyperbolic tangent |
arcsin(x) |
Inverse sine |
sinc(x) |
Cardinal sine |
arccos(x) |
Inverse cosine |
cosc(x) |
Cardinal cosine |
arctan(x) |
Inverse tangent |
tanc(x) |
Cardinal tangent |
exp(x) |
Exponentiation e^x |
sqrt(x) |
Square root |
ln(x) |
Natural logarithm |
cbrt(x) |
Cubic root |
log(x, b) |
Logarithm of x to base b |
root(x, n) |
Non-principal n-th root of x |
hypot(x, y) |
Hypotenuse |
proot(x, n) |
Principal n-th root of x |
gamma(x) |
Gamma function |
fact(n) |
Factorial |
lngamma(x) |
Logarithmic Gamma function |
erf(x) |
Error function |
abs(x) |
Absolute value/magnitude |
int(x) |
Rounds to the nearest integer towards zero |
sign(x) |
Sign |
frac(x |
Fractional part |
entier(x) |
Rounds downwards to the nearest integer |
round(x, d) |
Rounds x to d-th digit |
floor(x) |
Rounds downwards to the nearest integer (same as entier) |
even(x) |
Checks for even number |
ceil(x) |
Rounds upwards to the nearest integer |
odd(x) |
Checks for odd number |
Eps |
Equals 1.4901161193847656e-08 |
infinity |
Infinity |
DoubleEps |
Equals 1.084202172485504434e-19 |
undefined |
An expression stating that it is undefined, e.g. a singularity |
degrees |
180/Pi to convert radians to degrees |
Pi |
3.14159265358979323846 |
radians |
Factor Pi/180 to convert degrees to radians |
Exp |
e = exp(1) = 2.71828182845904523536 |
I |
Imaginary unit |
Phi |
Golden ratio (1+ sqrt(5))/2 |