Blog has moved! Please go to http://gqqnbig.me/?p=120 to read this article.using previous results
%
: Last Result
%%
: Last Result
- % % ? k : First k Results
%n
: Out[n] Results of output
The official name of% is out. You can find this information by entering% in the Mathematica help browser.
Defining Variables
x=value
: Assigns value to the variable x.
x=y=value
: Assigns value to the variable x and Y.
x=.
Or Clear[x]
: Clears the variable x from memory.
Keep in mind that variables are permanent unless you clear them. It is recommended that you run out of variables and remove them manually.
Variable name is not limited in length, but cannot start with a number because 2x means 2 times x. After testing, the variable name can be Chinese, grammar hints are also supported.
Mathematica's built-in functions use the Uppercamel naming method (first letter capitalized). To avoid conflicts with built-in functions, we recommend that the user function begin with a lowercase letter.
Please note the following points:
x y
Represents x multiplied by Y.
xy
Represents the XY variable.
5 x
Represents 5 times X.
x^2 y
Represents (x^2) Y.
symbol substitution is a number
Transform rule x->3
means that the symbol x is substituted for the number 3. The expression can be applied to transform rules, the syntax is expr/. Rule
(where expr is an expression, rule is a variation,/.) is called replace operator ).
The transformation rule itself is an expression, or it can be assigned to a variable, which is then involved in the transformation process.
Or
This uses the% function in the previous section.
expr /. {x->xval, y->yval}
Used to perform multiple substitutions.
If you want X to always be replaced with a value, then use the assignment syntax, such as x=3, x=fibonacci[10].
Mathematica uses lazy evaluation strategies, and if a variable (symbol) is an expression or a number, it is replaced with a number when evaluated, and if the variable is not defined, it is a symbol, "forget it." Therefore, it is important to define whether a variable is already defined. Remember to use x= often for "garbage collection."
four kinds of brackets
(term)
: Parentheses are used to group
f[x]
: square brackets substituting symbols into functions
{a,b,c}
: Curly braces Construct list
v[[i]]
: Both brackets take the list element
Multiple Actions
- EXPR1;EXPR2;EXPR3: Performs multiple operations to output the return value of the last operation.
- EXPR1;EXPR2: Performs multiple operations and does not output.
- EXPR;: Executes expr, not output.
Even if the previous operation ends with a semicolon, its return value is saved in out, i.e. we can get its value in%.
in[2]:= x=67-5;in[3]:= %out[3]= 62
The first chapter of MATHEMATICA CORE Language: Learning to calculate