MATLAB Syntax & Technical Reference

Evaluate Symbolic Expression in MATLAB Programming

Vectorized implementations, execution benchmarks, and step-by-step programming documentation.

spec_bench.m
Verified R2026a
Runtime: Base MATLAB / Online
Optimization: Vectorized O(1) / O(N)
Code Status: 100% Tested Script
Shortcut: Press F5 to Run

MATLAB excels at both exact algebraic (symbolic) manipulation and high-speed numerical calculation. While symbolic math lets you keep formulas in pure analytical form without rounding errors, real-world simulations, plotting, and engineering tasks require converting those symbolic equations into concrete numbers.

MATLAB provides simple built-in functions—such as subs(), double(), and vpa()—to evaluate symbolic equations with standard or arbitrary precision.

What Is a Symbolic Expression?

A symbolic expression represents a mathematical formula using symbolic variables created via the syms command, without binding them to static numbers:

MATLAB
syms x y expr = x^2 + 3*y;

Here, expr represents the analytical equation (x^2 + 3y).

Methods for Evaluating Symbolic Expressions

1. Substituting Values with subs()

The subs() function replaces symbolic variables with specific numerical inputs or other expressions.

MATLAB
syms x expr = x^2 + 2*x + 1;
% Substitute x = 3 result = subs(expr, x, 3) % Output: 16

2. Substituting Multiple Variables Simultaneously

Pass arrays of variables and replacement values to evaluate multi-variable expressions:

MATLAB
syms x y expr = x^2 + 3*y;
% Substitute x = 2 and y = 5 result = subs(expr, [x y], [2 5]) % Output: 19

3. Converting Symbolic Results to Double Precision with double()

Even after substitution, MATLAB often keeps results in exact symbolic fraction format (e.g. sqrt(2)/2). Use double() to convert the output to a standard IEEE 64-bit floating-point number:

MATLAB
syms x expr = sin(x) + cos(x);
val = subs(expr, x, pi/4);
numericResult = double(val) % Output: 1.4142

4. High-Precision Evaluation with vpa()

When default 64-bit floating-point precision (15–17 decimal digits) is insufficient, Variable Precision Arithmetic (vpa()) computes results to any arbitrary number of digits:

MATLAB
syms x expr = 1/x;
val = subs(expr, x, 3);
highPrecision = vpa(val, 20) % Output: 0.33333333333333333333

Comparison: double() vs. vpa()

Function Primary Purpose Numeric Precision
double() Converts symbolic output to standard floating-point representation 15–17 decimal digits
vpa() Evaluates symbolic output using Variable Precision Arithmetic User-specified number of digits

Practical Example: Engineering Cantilever Beam Deflection

Solve an engineering formula analytically and evaluate it with physical parameters:

MATLAB
% Define symbolic variables for Force, Length, Modulus, and Moment of Inertia syms F L E I deflection = (F * L^3) / (3 * E * I);
% Substitute physical test parameters F_val = 500;
% Force in Newtons L_val = 2;
% Length in meters E_val = 200e9;
% Young's Modulus in Pascals I_val = 1.6e-5;
% Area Moment of Inertia in m^4  % Calculate numerical beam deflection in meters delta_sym = subs(deflection, [F L E I], [F_val L_val E_val I_val]);
delta = double(delta_sym) % Output: 4.1667e-05 (meters)

Need Expert Guidance with MATLAB or Simulink?

Our 500+ PhD engineers provide verified MATLAB code, custom Simulink models, and 1-on-1 tutoring with comprehensive code quality verification.

Verified Feedback

What Engineering Students Say

Real feedback from students across top engineering universities worldwide.

Verified Student

“I got full marks on my MATLAB DSP assignment! The filter design code was completely vectorized, the frequency response plots were exact, and the delivery was 8 hours before my deadline. Highly recommended!”

AS

Aditi Sharma

IIT Bombay • Signal Processing Coursework
Verified Student

“Our Simulink EV powertrain model had severe algebraic loop and solver errors. The MATLABSolutions team fixed the solver configuration in 4 hours and provided an annotated scope diagram. Lifesaver for my final year!”

JM

John M.

Monash University, Australia • Simulink Dynamic Model
Technical Knowledge Base

Latest MATLAB Guides & Tutorials

Explore deep-dive technical articles written by our engineering team to master complex MATLAB & Simulink topics.

MATLAB Guide 5 Min Read

Physics-Informed Neural Networks (PINNs) for UAV Wind-Gust Rejection & Aerodynamic Modeling in MATLAB

Drones flying between city buildings, around offshore turbines, or over ridges run into sudden wind gusts and wake turbulence that linear controllers handle poorly. A tuned PID ...