Wolfram: Mathematica Notation Basics
Here's a list of the most commonly used Mathematica (Wolfram language) syntax.
Arithmetic Operator
x ^ ymeans x raised to power of y.- space is implicit multiplication. e.g.
a bmeansa * b.
Brackets
- Square brackets means function argument. e.g.
Sin[x] - Parenthesis means order of operation. e.g.
(3 + 5) * 2 - Curly braces means list. e.g.
{a,b,c}, also for vector. Nested list represent a matrx or tree. - Double Square brackets means getting an element from a list. e.g.
{x,y,z}[[1]]returnsx.
Vector and Matrix
{a,b}is a 2D vector.{a,b,c}is 3D vector.{{a,b},{c,d}}is a matrix, with 1st row{a,b}, second row{c,d}.
{a,b} . {x,y}means dot product.{{a,b},{c,d}} . {x,y}means matrix multiplication with the vector{x,y}.
{a,b} + {x,y}means vector addition{a + x, b + y}.{a,b} + cmeans{a + c, b + c}.{x,y} * cmeans{x c, y c}.{x,y} / cmeans{x/z, y/z}.
Norm[v]is the length of a vector v.Normalize[v]is the unit vector of v.
Function
f[x]is a function f applied on x.f@xis the prefix notation forf[x]. e.g.Cos@xmeansCos[x].x//fis the postfix notation forf[x]. e.g.x//CosmeansCos[x].
Function Definition
Function[{x},x+1]is a lambda function, adding 1 to arg.Function[{x,y},x+y]is a lambda function, sum of the args.
#the hash sign stand for parameter of a function.#or#1is first parameter,#2second, etc. For example,Function[#1+#2]is equivalent toFunction[{x,y},x+y].&(ampersand) means the expression before is a function, with hash sign#meaning its parameters. e.g.(#1 + #2 &)is the same asFunction[ {x, y}, x + y ]
f[x_,y_] := x + yis a definition of function using pattern matching. Here it is a sum of 2 args.
Complex Number
I(Capital letter I) is the imaginary number.