Page 497 - Applied Numerical Methods Using MATLAB
P. 497
486 SYMBOLIC COMPUTATION
one closest (alphabetically) to ‘x’ as the independent variable by default only if
it has been declared as a symbolic variable and is contained as an input argument
of the function f.
(cf) One should use the MATLAB command “sym2poly()” if he wants to extract the
coefficients from the Taylor series expansion obtained as a symbolic expression.
G.3 LINEAR ALGEBRA
Several MATLAB commands and functions can be used to manipulate the vec-
tors or matrices consisting of symbolic expressions as well as those consisting
of numerics.
>>syms a11 a12 a21 a22
>>A = [a11 a12; a21 a22];
>>det(A)
ans = a11*a22 - a12*a21
>>AI=A^-1
AI = [ a22/(a11*a22 - a12*a21), -a12/(a11*a22 - a12*a21)]
[ -a21/(a11*a22 - a12*a21), a11/(a11*a22 - a12*a21)]
>>A*AI
ans = [ a11*a22/(a11*a22 - a12*a21)-a12*a21/(a11*a22 - a12*a21), 0]
[ 0, a11*a22/(a11*a22 - a12*a21) - a12*a21/(a11*a22 - a12*a21)]
>>simplify(ans) %simplify an expression
ans=[1, 0]
[0, 1]
>>syms x t;
>>G = [cos(t) sin(t); -sin(t) cos(t)] %The Givens transformation matrix
G = [ cos(t), sin(t)]
[ -sin(t), cos(t)]
>>det(G), simple(ans)
ans = cos(t)^2 + sin(t)^2
ans=1
>>G2 = G^2, simple(G2)
G2 = [ cos(t)^2 - sin(t)^2, 2*cos(t)*sin(t)]
[ -2*cos(t)*sin(t), cos(t)^2 - sin(t)^2]
ans = [ cos(2*t), sin(2*t)]
[ -sin(2*t), cos(2*t)]
>>GTG = G.’*G, simple(GTG)
GTG = [ cos(t)^2 + sin(t)^2, 0]
[ 0, cos(t)^2 + sin(t)^2]
ans=[1,0]
[0,1]
>>simple(G^ - 1) %inv(G) for the inverse of Givens transformation matrix
G = [ cos(t), -sin(t)]
[ sin(t), cos(t)]
>>syms b c
>>A = [0 1; -c -b];
>>[V,E] = eig(A)
V = [ -(1/2*b + 1/2*(b^2 - 4*c)^(1/2))/c, -(1/2*b - 1/2*(b^2 - 4*c)^(1/2))/c]
[ 1, 1]
E = [ -1/2*b + 1/2*(b^2 - 4*c)^(1/2), 0]
[ 0, -1/2*b - 1/2*(b^2 - 4*c)^(1/2)]
>> solve(poly(A))%another way to get eigenvalues(characteristic roots)
ans = [ -1/2*b+1/2*(b^2 - 4*c)^(1/2)]
[ -1/2*b-1/2*(b^2 - 4*c)^(1/2)]

