Getting Started with Wolfram Mathematica

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)

MMA version used in demonstration

Interface

After installation and activation, create a new notebook to see the following interface:

Basic MMA interface

Quick overview of MMA interface:

MMA interface introduction

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:

help-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

1
(* Comment *)

Comments use (* and *), similar to C/C++ /* */. Examples:

1
2
1 + 1 (*Hello*)
1 + (*World*)1 

Both lines execute as 1 + 1:

comment-test

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:

Parentheses usage

Square Brackets []

Function calls and parameters:

Square bracket usage

Curly Braces {}

Create lists:

Curly brace usage

List operations will be explained later.

Double Brackets [[]]

Access list elements (shorthand for Part function):

Double bracket usage

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 * b1 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:

Numeric and symbolic operations

Expressions combine operations/function calls. MMA automatically reduces fractions and combines like terms but doesn’t expand expressions. Use Simplify or FullSimplify:

Simplification example

Boolean Expressions

Comparisons return True/False:

Equations and inequalities

Use == for equality checks. Single = assigns variables.
Use && for AND and || for OR. Simplify with Simplify, FullSimplify, or solve with Solve/Reduce:

Boolean simplification and solving

Variables and Constants

Declare variables with variable = value:

Variable creation

All declared variables in expressions get substituted. Variables can reference other variables:

Substitution example

Use Clear[variable] to unset variables:

Clear usage

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, ...]:

Function call 1

Single-parameter functions can use postfix notation param // FunctionName:

Function call 2

Supports chaining:

Chained calls

Definition

Define functions with FunctionName[param1_, param2_, ...] := returnValue. Each parameter requires trailing underscore:

Function definition

Extension - Recursive Functions
Fibonacci sequence example:
Fibonacci sequence

Built-in Functions

MMA has nearly 6000 built-in functions2. Common ones include:

Numerical Evaluation N

  • N[expr]: Numerical value
  • N[expr, n]: n-digit precision

N example

Trigonometric Functions

All trigonometric functions use radians. Add Degree for angles:

Trigonometric functions

Equation Solving Solve/Reduce

Solve equations with Solve:

Solve equations

Solve inequalities with Reduce:

Reduce inequalities

Reduce handles complex expressions:

Advanced Reduce usage

Alternative Solvers NSolve/FindInstance

  • NSolve: Numerical solutions
  • FindInstance: Find specific solution instances

FindInstance usage

Optimization Maximize/Minimize

Minimize finds minima with conditions:

Minimize usage

Maximize works similarly.

Differentiation D

  • D[f, x]: First derivative
  • D[f, {x, n}]: nth derivative
  • f'[x]: Shorthand

Symbolic differentiation

Integration Integrate

  • Integrate[f, x]: Indefinite integral
  • Integrate[f, {x, min, max}]: Definite integral
  • Multiple integrals supported

Definite integral example

Expansion Expand/ExpandAll

  • Expand: Expands products and powers
  • ExpandAll: Expands nested expressions

Factorization Factor

Factor[poly]: Factor polynomials over integers.

Plotting Plot/Plot3D

Basic plotting examples:

Plot 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!


  1. 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). ↩︎

  2. https://www.wolfram.com/language/fast-introduction-for-programmers/en/built-in-functions/ ↩︎

Built with Hugo
Theme Stack designed by Jimmy