Lesson 10-Symbolic Computing and Mathematical Formula Derivation

Introduction: When Numbers Aren’t Enough

Here’s a confession: For most of my engineering career, I ignored MATLAB’s Symbolic Math Toolbox. I thought, “I can compute numerically just fine. Why do I need symbols?”

Then I tried to derive the transfer function of a control system by hand. And then I tried to compute the Jacobian of a 6-degree-of-freedom robot arm. And then I tried to verify my analytical solution to a partial differential equation.

That’s when I realized: Numerical computing is for getting answers. Symbolic computing is for getting insights.

Here’s the fundamental difference: Numerical computing gives you numbers — “The integral is 3.14159.” Symbolic computing gives you formulas — “The integral is π.” One tells you what; the other tells you why.

In this article, we’re going to explore MATLAB’s Symbolic Math Toolbox. We’ll learn how to:

  • Create and manipulate symbolic variables and expressions
  • Perform calculus operations (differentiation, integration, limits, series expansions) symbolically
  • Solve equations and differential equations symbolically
  • Compute Laplace and Z-transforms (essential for control systems and signal processing)
  • Convert symbolic expressions to numeric functions (for fast numerical evaluation)
  • Use variable-precision arithmetic (when double precision isn’t enough)

But more importantly, we’re going to develop intuition for when to use symbolic computing vs. numeric computing. They’re not interchangeable — they’re complementary. Knowing when to use each is a superpower.

Symbolic vs Numeric: A Philosophical Divide

Before we dive into syntax, let’s talk about philosophy. When should you use symbolic computing, and when should you use numeric computing?

The Case for Numeric Computing

Numeric computing is what we’ve been doing in the previous articles. You have numbers, you perform operations on them, you get numbers back.

% Numeric computing
A = [1, 2; 3, 4];
b = [5; 6];
x = A \ b;  % Solve Ax = b numerically
% x = [-4; 4.5]

Numeric computing is:

  • Fast: Operations are optimized at the CPU level.
  • Memory-efficient: A double is just 8 bytes.
  • The only option for measured data: Your sensor data is numeric, not symbolic.

Use numeric computing when: You have numbers, you want numbers, and speed matters.

The Case for Symbolic Computing

Symbolic computing treats variables as symbols, not numbers. You can add x and y without knowing their values, and the result is x + y.

% Symbolic computing
syms x y;
expr = x + y;
expanded = expand(expr^2);
% expanded = x^2 + 2*x*y + y^2

Symbolic computing is:

  • Exact: No floating-point errors. The integral of 1/(1+x^2) from 0 to 1 is exactly pi/4, not 0.7853981633974483.
  • Insightful: You get formulas, not just numbers. You can see how the solution depends on parameters.
  • Powerful for derivation: You can derive transfer functions, compute Jacobians, solve differential equations analytically.

Use symbolic computing when: You want to derive formulas, verify analytical solutions, or gain insights into how a system behaves.

The Hybrid Approach: Symbolic Derivation, Numeric Evaluation

Here’s the pro move: Use symbolic computing to derive a formula, then convert it to a numeric function for evaluation.

% Step 1: Derive symbolically
syms x a b;
f = a*x^2 + b*x + 1;
df = diff(f, x);  % Symbolic derivative: 2*a*x + b

% Step 2: Convert to numeric function
f_numeric = matlabFunction(f, 'Vars', {x, a, b});
df_numeric = matlabFunction(df, 'Vars', {x, a, b});

% Step 3: Evaluate numerically (fast!)
result = f_numeric(2, 3, 4);  % Evaluate at x=2, a=3, b=4
% result = 21

This is the best of both worlds: the insight of symbolic computing, and the speed of numeric computing.

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here

Share your love