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.
A symbolic expression represents a mathematical formula using symbolic variables created via the syms command, without binding them to static numbers:
syms x y expr = x^2 + 3*y;Here, expr represents the analytical equation (x^2 + 3y).
The subs() function replaces symbolic variables with specific numerical inputs or other expressions.
syms x expr = x^2 + 2*x + 1;
% Substitute x = 3 result = subs(expr, x, 3) % Output: 16Pass arrays of variables and replacement values to evaluate multi-variable expressions:
syms x y expr = x^2 + 3*y;
% Substitute x = 2 and y = 5 result = subs(expr, [x y], [2 5]) % Output: 19Even 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:
syms x expr = sin(x) + cos(x);
val = subs(expr, x, pi/4);
numericResult = double(val) % Output: 1.4142When default 64-bit floating-point precision (15–17 decimal digits) is insufficient, Variable Precision Arithmetic (vpa()) computes results to any arbitrary number of digits:
syms x expr = 1/x;
val = subs(expr, x, 3);
highPrecision = vpa(val, 20) % Output: 0.33333333333333333333| 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 |
Solve an engineering formula analytically and evaluate it with physical parameters:
% 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)Real feedback from students across top engineering universities worldwide.
“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!”
“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!”
Explore deep-dive technical articles written by our engineering team to master complex MATLAB & Simulink topics.
Operating a modern microgrid is an ongoing balancing act. Between changing solar output, shifting wind speeds, volatile electricity pricing, and unpredictable consumer demand, a...
Modern microgrids operate with low physical inertia, rapid inverter switching dynamics, and intermittent renewable power generation. Simulating these systems requir...