CS 205 Intro. Compl. Programming
Symbolic Math
April 13, 1998 ** updated 4/20/98
There is a MATLAB script
ch5_symbolic.m
that is linked into the directory so that you can just use
these examples, now that I've figured out why they did not
run last week.
ch5_symbolic.m
and a diary of running this script
Chapter 5 of our text discusses Symbolic Mathematics. The
presentation doesn't work exactly as described in our textbook.
You need to be sure that the quantities involved have the
type symbolic object before symbolic operations
can be applied to these expressions. You should use the
whos
command to make sure the variables you create are given the
data type "symbolic object". This is how MATLAB know to interpret
these commands, based on the operand, as MAPLE commands. If need
be you can always use
f = sym(f)
to force the identification as a symbolic object.
You can create symbolic expressions (at the MATLAB prompt)
s1 = sym('x^3-1')
s2 = sym'(x-3)^2 + (y-4)^2);
s3 = sym'sqrt(a^4*b^7'));
s4 = sym'14*x/(22*x*y));
factor(s1)
expand(s2)
collect(s2)
colect(s2,'y')
simplify(s3)
simple(s4)
You can apply mathematical operations from Calculus:
diff(s1)
diff(s2,'x') %differentiate w.r.t. x
diff(s2,'y') %differentiate w.r.t. y
diff(s1,2) % return 2nd derivative
int('sin(a)')
int(s1,0.0,2.0) * integrate from x=0 to x=2
taylor(s2)