Is there a way to do matrix calculations with unknown variables in the matrix using Matlab?

Viewed 36

For example, if I wanted to multiply the two matrices A and B, where A = [1 x] and B = [2 3], is there a way I can do this in Matlab where the final answer would be in terms of x? So in this case, the desired answer would be given in the form 2 + 3x.

Or if I wanted to find the inverse matrix of C, where C = [1 2; 3 x], is there a way I could do this where the final answer would be in terms of x? So in this case, the desired answer would be given in the form 1/(x-6) [x -3; -2 1].

1 Answers

That's what the Symbolic Toolbox is for:

>> syms x % declare x as a symbolic variable

>> A = [1 x]; B =  [2; 3];
>> A*B
ans =
3*x + 2

>> C = [1 2; 3 x];
>> inv(C)
ans =
[  x/(x - 6), -2/(x - 6)]
[ -3/(x - 6),  1/(x - 6)]
Related