Symbolic Math in Matlab
Symbolic Math in Matlab
Matlab was designed for numerical computation, i.e. computation performed using standard arithmetic operations (addition, subtraction, division, multiplication) on floating point representations of numbers, with a focus on numerical linear algebra. In numerical mathematics, variable names always represent specific numerical (floating point) values. Floating point numbers approximate real numbers, and round off errors may accumulate during computation. The Symbolic Toolbox1 adds the ability to perform symbolic computation, in which a variable may truly represent unknown values and arithmetic is performed with infinite precision, e.g. 1/3 and 2 are represented as is rather than being replaced by a floating point approximation. Other popular symbolic computational tools are Maple and Mathematica. In fact, the Matlab Symbolic Toolbox uses the Maple kernel.
To check installed toolboxes, use the ver command. The standard Clemson install of Matlab includes the symbolic toolbox.
R. Groff ECE409 09/22/2009
Some Useful Symbolic Commands diff symbolic differentiation diff(f) % derivative of f with respect to a variable diff(g,x) % derivative specifying with respect to which variable gd=diff(g,w) int symbolic integration int(f) % indefinite integral of f int(g,w) %indefinite integral, specifying variable of integration int(g,w,a,b) % definite int w/ respect to w, going from a to b pretty print result in an easier to read format pretty(f) simplify simplify an expression. Try a limited number of methods to simply an expression simplify( (s^2+2*s+1)/(s+1) ) simple try a more extensive search to find the simplest expression simple(gd) solve solve algebraic equations solve('a*x^2+b*x+c=0',x) % solve equation for x [x,y] = solve('x^2+2*x+5+y^2=0','y^2+3*y-4+x^2=0') % Simultaneously solve pair of equations for x and y dsolve solve ordinary differential equations, using D to represent time differentiation dsolve('Dx = -a*x') dsolve('D2x = -a*x','x(0)=3,Dx(0)=4') subs substitute symbolic expressions in other symbolic expressions syms s M g L kd p=solve('a*s^2+b*s+c=0','s') subs(p,{a,b,c},{M*L^2,kd,M*g*L}) laplace Laplace transform of a function (assumes function is zero for t less than zero) syms a t laplace(exp(a*t)) ilaplace inverse Laplace transform of a function syms s ilaplace( (3*s+1)/(s^2+2*s+5)) vpa, double commands for converting a symbolic expression (involving only numbers) into a numerical value.
Partial fraction expansion The partial fraction expansion of a rational function F is given by diff(int(F)). The symbolic toolbox does not include a command for directly determining the partial fraction expansion, but this trick works because the partial fraction expansion is used to integrate a rational function. diff(int( (s+2)/(s+4)/(s+5) ) )