Matlab has a powerful symbolic math ability. Rather than making calculations on known numbers, we can make calculations on symbolic expressions. For example, what is the limit as x approaches inf of 1 + 1/2^1 + 1/2^2 + 1/2^3...+1/2^n ? Matlab can tell us. What is the integral of x^3 for any x? Matlab can tell us.
Symbolic Math in Matlab
Matlab allows you to create symbolic math expressions. This is useful when you don't want to immediately compute an answer, or when you 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)
The key function in Matlab to create a symbolic representation of data is: sym() or syms if you have multiple symbols to make.
Below is an example of creating some symbolic fractions and square roots:
>> sqrt(2) ans = 1.4142 >> sqrt( sym(2) ) ans = 2^(1/2) >> 2 / 5 ans = 0.4 >> 2/5 + 1/3 ans = 0.7333 >> sym(2) / sym(5) ans = 2/5 >> sym(2) / sym(5) + sym(1) / sym(3) ans = 11/15
Defining Symbolic Expressions
We can define symbolic functions using the sym command and syms command. Here is an example of creating a symbolic function for (a*X^2) + (b*x) + c: >> syms a b c x % define symbolic math variables >> f = sym('a*x^2 + b*x + c');
From now on we can use the f symbol to represent the given function.
Evaluation of Symbolic Expressions
The keyfunction subs (which stands for substitute) is used to replace symbolic variables with either new symbolic variables or with acutal values.