Symbolic Calculations in Matlab

By admin No comments

These techniques will allow you to use Matlab to carry out algebraic calculations, instead of doing them by hand.

>> syms a b real 
>> x = (a+b)^2

We can use follwing to expand polynomials:

>> expand(x)

ans = 
a^2 + 2*a*b + b^2

Another command can be used to simplify the formula:

>> z = sin(a)^2 + cos(a)^2
>> simplify(z)

ans = 

Matrix operation is also work:

>> A = [a 0 b; 0 -a 0; 0 1 0];
>> B = [2*a b exp(a); cos(a) 0 0; -a b/a 0];

>> A*B

then we obtained the result of multiplication of A and B.

Moreover, we can calculate the transpose of the a matrix and eigenvalues of the matrix:

>> A'
>> [V,D] = eig(A)

Here the eigenvalues of the matrix a are along the diagonal of this matrix D. And the corresponding eigenvectors are in the columns of the matrix V.

And we can find the inverse and determinant:

>> inv(B)
>> det(B)

Ref: Supplementary Material: Symbolic Calculations in Matlab