Evaluate Symbolic Expression in MATLAB Programming
Matlab allows user to create symbolic math expressions. This is useful when user
don't want to immediately compute an answer, or when user have a math "formula" to work on but
don't know how to "process" it.
Matlab allows symbolic operations several areas including:
• Calculus
• Linear Algebra
• Algebraic and Differential Equations
• Transforms (Fourier, Laplace, etc)
These key function in Matlab is used to create a symbolic representation of data is: sym() or
syms if user have multiple symbols to make.
Defining Symbolic Expressions
User can define symbolic functions using the sym function command and syms function command.
Here is an example for creating a symbolic function for (a*X^2) + (b*x) + c:
>> syms a b c x % define the symbolic math variables
>> f = sym('a*x^2 + b*x + c');
Evaluation of Symbolic Expressions
The keyfunction subs (which stands for substitute) is for replacing symbolic variables with
either new symbolic variables or with acutal values. The syntax of the subs function is: subs(
symbolic_function, list_of_symbols, list_of_values). Here is an example:
>> f = sym('a*x^2 + b*x + c');
>> subs(f,x,5)
ans =
25 * a + 5 * b + c
>> subs(f,[x a b c],[5 1 2 3])
ans =
38