Wolfram Mathematica
- Appeared in:
- 1988
- Influenced by:
- Paradigm:
- Typing discipline:
- File extensions:
- .nb, .m
- Versions and implementations (Collapse all | Expand all):
Wolfram Mathematica is a computational software program widely used in all domains which require technical computations.
It was created by Stephen Wolfram and is developed by Wolfram Research. The first version was released on June 23rd, 1988.
Mathematica provides a huge set of tools and capabilities:
- a variety of tools for numeric and symbolic computations.
- libraries of mathematical (both elementary and special) and statistical functions, functions of group theory and number theory.
- graphics-processing tools, including visualization and animation, image processing and image recognition libraries.
- specialized tools for financial computations, data mining and text mining etc.
- a database of mathematical, scientific and socio-economic information.
- built-in programming language with support for procedural, functional and object-oriented paradigms.
- tools for creating applications and user interfaces, parallel programming, using external DLLs, SQL and lots of others languages.
Elements of syntax:
Non-nestable comments | (* ... *) |
---|---|
Case-sensitivity | yes |
Variable identifier regexp | [_a-zA-Z][_a-zA-Z0-9]* |
Function identifier regexp | [_a-zA-Z][_a-zA-Z0-9]* |
Variable assignment | <varname> = <value> |
Variable declaration | implicit |
Variable declaration with assignment | <varname> = <value> |
Grouping expressions | ( ... ) |
Block | [ ... ] |
Physical (shallow) equality | == |
Physical (shallow) inequality | != |
Comparison | < > >= <= |
Function definition | f[x_, y_, z_] := (x + y + z) |
Function call | f[x, y, z] |
Function call with no parameters | f[] |
Sequence | ; |
If - then | If[condition, trueBlock] |
If - then - else | If[condition, trueBlock, falseBlock] |
Loop forever | While[1<2, loopBody] |
While condition do | While[condition, loopBody] |
For each value in a numeric range, 1 increment | For[i = 0, i < 10, i++, loopBody] |
For each value in a numeric range, 1 decrement | For[i = 10, i > 0, i--, loopBody] |
Examples:
Factorial:
Example for versions Wolfram Mathematica 8.0.4This example uses recursive factorial definition. The first line defines Fact
function. Note that the names of function arguments must have an underscore _
appended to them.
Fact[n_] := If[n == 0, 1, Fact[n - 1]*n];
For[i = 0, i <= 16, i++, Print[i, "! = ", Fact[i]]];
Quadratic equation:
Example for versions Wolfram Mathematica 8.0.4After accepting user input we define variable y
which is a quadratic equation with the given coefficients. Since x
is not defined yet, it stays a variable — for example, Print[y]
will output the notation of the equation c + b x + a x^2
(with c, b and a replaced with values entered by the user). Reduce
calculates the values of the variables which satisfy the condition “equation value equals zero”.
a = Input["Input a", 0];
b = Input["Input b", 0];
c = Input["Input c", 0];
y = a*x^2 + b*x + c;
Print[Reduce[y == 0]];
Hello, World!:
Example for versions Mathics 0.5, Wolfram Mathematica 8.0.4Evaluation of this expression results in a string “Hello, World!” itself; since it is not followed by a semicolon, it will be printed as a separate Out
, which is not always convenient.
"Hello, World!"
Hello, World!:
Example for versions Mathics 0.5, Wolfram Mathematica 8.0.4Print
function outputs its argument(s) to the main output stream. Streams can nest, so for convenience it’s recommended to to use a single stream for all output throughout the program.
Print["Hello, World!"];
Factorial:
Example for versions Mathics 0.5, Wolfram Mathematica 8.0.4This example uses built-in factorial function !
.
Do
is one of the ways to run a loop — it evaluates its first argument for a sequence of numbers defined by the second argument. In this case it’s all values of i
from 0 to 16, inclusive, with step of 1.
Do[Print[i, "! = ", i!] , {i, 0, 16, 1}]
Fibonacci numbers:
Example for versions Mathics 0.5, Wolfram Mathematica 8.0.4Print
always outputs a newline after the output, so to prints the numbers in a single line, one has to accumulate them into a string and print it. <>
is concatenation operator, it works only on strings, so the result of Fibonacci
call must be converted to string explicitly using ToString
function.
msg = "";
Do[msg = msg <> ToString[Fibonacci[i]] <> ", " , {i, 16} ];
Print[msg, "..."];
Fibonacci numbers:
Example for versions Mathics 0.5This example uses Riffle
function which in this case alternates elements of the array containing Fibonacci numbers and the separator string “,”.
StringJoin[Riffle[Map[ToString, Table[Fibonacci[i], {i,16}]], ", "]] <> "..."
Comments
]]>blog comments powered by Disqus
]]>