Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
Preface
Wolfram Mathematica (abbreviated as MMA) is a scientific computing software developed by Wolfram Research. This article introduces Mathematica’s interface, syntax, and basic applications. Similar software includes MATLAB and Maple.
Official MMA website: https://www.wolfram.com/mathematica/
Installation and activation guide: Mathematica Installation and Activation Tutorial - 科研小飞 (Zhihu)
This article is suitable for readers with basic programming knowledge. However, you can skip programming-related sections if needed. All screenshots are taken from Windows 11, Mathematica 13.3. (The latest version 14.0 was released in December 2023 with backward compatibility)
Interface
After installation and activation, create a new notebook to see the following interface:
Quick overview of MMA interface:
Key points:
- Enter creates new lines; use Shift+Enter to execute code.
- The red triangle on the left palette also executes code; the gray square stops computations.
- MMA’s Notebook feature is primarily for computation rather than note-taking. Refer to official documentation for details.
Use Ctrl+Shift+I to show input form (code) and Ctrl+Shift+N for mathematical form. Detailed explanations follow.
Syntax
Mathematica is essentially a Wolfram Language (WL) interpreter. Let’s explore basic syntax and common commands.
Help Documentation
Query function documentation using ? Solve
:
The ?
operator displays brief help for any function. Click the i
icon for detailed documentation (prioritizes offline docs, falls back to online docs). Access full documentation via Help -> Wolfram Documentation.
Comments
|
|
Comments use (*
and *)
, similar to C/C++ /* */
. Examples:
|
|
Both lines execute as 1 + 1
:
Brackets
Master bracket usage before learning functions!
Official reference: Using Brackets and Braces Correctly
Four bracket types in MMA:
Parentheses ()
Group expressions and set operation precedence:
Square Brackets []
Function calls and parameters:
Curly Braces {}
Create lists:
List operations will be explained later.
Double Brackets [[]]
Access list elements (shorthand for Part
function):
Operations and Expressions
MMA supports basic mathematical operations:
Name | Symbol | Function Form | Math Form |
---|---|---|---|
Addition | a + b |
Plus[a, b] |
$a+b$ |
Subtraction | a - b |
Subtract[a, b] |
$a-b$ |
Multiplication | a * b 1 |
Times[a, b] |
$a\times b$ |
Division | a / b |
Divide[a, b] |
$\frac ab$ |
Power | a ^ b |
Power[a, b] |
$a^b$ |
Modulo | - | Mod[a, b] |
$a\bmod b$ |
Examples with numbers and symbols:
Expressions combine operations/function calls. MMA automatically reduces fractions and combines like terms but doesn’t expand expressions. Use Simplify
or FullSimplify
:
Boolean Expressions
Comparisons return True
/False
:
Use
==
for equality checks. Single=
assigns variables.
Use&&
for AND and||
for OR. Simplify withSimplify
,FullSimplify
, or solve withSolve
/Reduce
:
Variables and Constants
Declare variables with variable = value
:
All declared variables in expressions get substituted. Variables can reference other variables:
Use Clear[variable]
to unset variables:
Built-in constants:
Constant | Name | Approx. Value | Math Form |
---|---|---|---|
Pi |
Pi | 3.141592654 | $\pi$ |
E |
Euler’s number | 2.718281828 | $\mathrm e$ |
I |
Imaginary unit | - | $i$ |
Infinity |
Infinity | - | $\infty$ |
Degree |
Degree | - | $\degree$ |
Functions
Invocation
Call functions using FunctionName[param1, param2, ...]
:
Single-parameter functions can use postfix notation param // FunctionName
:
Supports chaining:
Definition
Define functions with FunctionName[param1_, param2_, ...] := returnValue
. Each parameter requires trailing underscore:
Extension - Recursive Functions
Fibonacci sequence example:
Built-in Functions
MMA has nearly 6000 built-in functions2. Common ones include:
Numerical Evaluation N
N[expr]
: Numerical valueN[expr, n]
: n-digit precision
Trigonometric Functions
All trigonometric functions use radians. Add Degree
for angles:
Equation Solving Solve/Reduce
Solve equations with Solve
:
Solve inequalities with Reduce
:
Reduce
handles complex expressions:
Alternative Solvers NSolve/FindInstance
NSolve
: Numerical solutionsFindInstance
: Find specific solution instances
Optimization Maximize/Minimize
Minimize
finds minima with conditions:
Maximize
works similarly.
Differentiation D
D[f, x]
: First derivativeD[f, {x, n}]
: nth derivativef'[x]
: Shorthand
Integration Integrate
Integrate[f, x]
: Indefinite integralIntegrate[f, {x, min, max}]
: Definite integral- Multiple integrals supported
Expansion Expand/ExpandAll
Expand
: Expands products and powersExpandAll
: Expands nested expressions
Factorization Factor
Factor[poly]
: Factor polynomials over integers.
Plotting Plot/Plot3D
Basic plotting examples:
Conclusion
When learning MMA, I struggled with fragmented tutorials online. This guide consolidates essential syntax and common pitfalls into one resource. Originally intended as a concise tutorial, it grew to 8000+ characters. Thanks for reading!
Future articles may explore Mathematica applications in mathematics and real-world problems. Stay tuned!
-
Multiplication can be written as
a b
(with space). Most spaces are optional in MMA, but multiplication spaces are mandatory (ab
would be a single variable). ↩︎ -
https://www.wolfram.com/language/fast-introduction-for-programmers/en/built-in-functions/ ↩︎