Matlab Fundamentals: Symbolic Math
The Symbolic Math package, included in the Student Edition of Matlab, allows us
to easily do symbolic manipulations on equations, such as factoring, solving,
root finding, integrating, differentiating and solving differential equations.
- For all variables in the Symbolic Math Package, use single lower
case letters (a,b,c,...z) and not upper case letters,
numbers or multicharacter strings. The package sometimes has problems parsing
strings with more complicated variable names.
- To define a mathematical function, put quotes around it, such as: 'a*x^2
+ b*x + c=0' or 'p*v = n*r*t'
- You can store a function in a character string, such as QuadEqn
= 'a*x^2 + b*x + c=0'
- The solve command will find the solution (either symbolic
or numeric) for a single equation or a system of equations. Try some of
the examples below:
- solve(QuadEqn,'x') % This will solve symbolically for the
variable x
- solve(QuadEqn,'a=3','c=-1','x=-1') % will find the value of
b which makes this true
- solve(QuadEqn,'a=sqrt(c)','b=2','x=-1') % A more complicated
example
- solve('y=m*x+b','y=n*x+c','m=1','b=2','n=3','c=4') % Will find
intersection of two lines
- solve('y=sin(log(x+y))','y=cos(exp(x^y))') % Try this one
on your calculator!
- To quickly plot some equation with a single variable over some range,
use ezplot
- ezplot('sin(x)/x',[-10 9.9]) % (I used 9.9 so it wouldn't
evaluate it at zero, which gives a divide by zero error)
- ezplot('sin(x)^3+x+sin(x)', [-20 20])
- For a complete discussion, see the "Symbolic Math Toolbox Tutorial"
in the Student Edition of Matlab manual.
Electronic Copy: http://physics.gac.edu/~huber/matlab/mtlabsym.htm
Revised: 28-JAN-97 by Tom
Huber, Physics Department, Gustavus
Adolphus College.