Matrices with Polynomial Entries functions

Hi,
I was wondering if Matlab has routines in order to compute the inverse of a Matrix with Polynomial Entries. I have not found any functions till now.
Does anyone know?
Best,
Maria

3 Comments

Do you want a symbolic expression? It would help if you gave an example of the matrix you're interested in.
Maria
Maria on 10 Mar 2015
Edited: Maria on 10 Mar 2015
For example, I have a matrix that is in this form
B=[b1 b2 b3; c1 c2 c3; d1 d2 d3];
where the entries form the polynomials, in the form
b1*s^2+b2*s+b3
Right now, I am not using a symbolic expression, but my algorithms starts to suffer in case of big matrices. So, if a symbolic expression would be better, it would be fine for me.
A symbolic expression would probably not be better if that's not your goal. I was just asking for clarification.

Sign in to comment.

Answers (2)

People are always looking for the magic solution. Sadly, magic only happens in Harry Potter books.
You say that your algorithm "suffers" now. Your algorithm will also suffer if you try to compute symbolic inverse matrices. Expect a HUGE mess of terms, so it will be quite slow to do anything.
However, in theory, the symbolic toolbox can do what you want. Why not try it? Just don't expect to be terribly happy with the result, but then nothing you will do here will be wonderful.
syms x a1 a2 a3 a4 a5 a6 a7 a8 a9
A = [a1*x + a2,a3*x^2 + a4*x + a5;a6*x^2 + a7,a8*x + a9];
inv(A)
ans =
[ -(a9 + a8*x)/(a5*a7 - a2*a9 - a1*a9*x - a2*a8*x + a4*a7*x - a1*a8*x^2 + a3*a7*x^2 + a3*a6*x^4 + a4*a6*x^3 + a5*a6*x^2), (a3*x^2 + a4*x + a5)/(a5*a7 - a2*a9 - a1*a9*x - a2*a8*x + a4*a7*x - a1*a8*x^2 + a3*a7*x^2 + a3*a6*x^4 + a4*a6*x^3 + a5*a6*x^2)]
[ (a6*x^2 + a7)/(a5*a7 - a2*a9 - a1*a9*x - a2*a8*x + a4*a7*x - a1*a8*x^2 + a3*a7*x^2 + a3*a6*x^4 + a4*a6*x^3 + a5*a6*x^2), -(a2 + a1*x)/(a5*a7 - a2*a9 - a1*a9*x - a2*a8*x + a4*a7*x - a1*a8*x^2 + a3*a7*x^2 + a3*a6*x^4 + a4*a6*x^3 + a5*a6*x^2)]
And that was only a 2x2 matrix. A 3x3 problem will be much longer.

3 Comments

I am trying now to do another thing, since the symbolic toolbox is suggested. I explain it with an example.
I have a cell structure called M, that has as entries arrays of numbers, that are the coefficient of a polynomial, for example
M{1,1}=[m1 m2 m3 m4];
I want to convert each entry in a symbolic polynomial and then I want to compute the determinant of this new symbolic polynomial matrix. For example, if M is 2 x 2, I put
p1=poly2sym(M{1,1});
p2=poly2sym(M{1,2});
p3=poly2sym(M{2,1});
p4=poly2sym(M{2,2});
I will have a final symbolic polynomial matrix as
P=[p1 p2; p3 p4];
Then
D=det(P);
D_new=sym2poly(D);
Now, in order to extent this way for any matrices M of generic dimension n x n, I tried to do
Mtest=cellfun(@poly2sym,M);
and I get the error
Error using cellfun sym output type is not supported.
I tried to do
Mtest=cellfun(@poly2sym,M,'UniformOutput',0);
but then, when I want to compute the determinant, I get the error
Dtest=det(Mtest);
Undefined function 'det' for input arguments of type 'cell'.
This way seems not sooo bad to me if I fix this error, do you have any suggestions?
Best,
Maria
I need to add that now I am trying to compute only the determinant, and later I will compute the adjoint matrix
You need to understand that a cell array is NOT something that the symbolic toolbox can work with. In general, cell arrays are never supported for any computations, since they can contain anything.
I'm not sure why are you trying to use a cell array, when I showed you how to do this with a regular array? If you insist on the use of cell arrays here, then you will need to convert them to a normal symbolic array. Sadly, cell2mat seems not to work here, nor does arrayfun work with uniformoutput set to true. When all else fails, god gave us the loop.

Sign in to comment.

Maria, is the matrix inverse your goal, or are you using it for some other purpose? A common mistake is to solve a linear equation like A*x = y, where x and y are vectors and A is a matrix, by computing the inverse Ainv and multiplying:
x = Ainv * y
This is very inefficient. In MATLAB, a far more efficient method is to do this:
x = A\y
This tells MATLAB to solve A*x = y using whatever method is most appropriate (see mldivide). Here is an example of the performance:
y = rand(3,1); A = rand(3);
tic % tic/toc does the timing
Ainv = inv(A);
x = Ainv*y;
toc
tic
x = A\y;
toc
On my computer, the first calculation took 1.33 seconds. The second took only 0.0003 seconds, so it was about 4000 times faster!

2 Comments

I see, and normally I always try to avoid the inv() command, preferring the \ . I don't have this kind of problem now though, and I need the inverse. Or, what I am currently trying right now, the determinant and the adjoin matrix.
In one of your comments above, you start with the coefficients of a polynomial (which will always be components of a vector), and then you switch to a 2x2 matrix. Is your polynomial the characteristic polynomial of a matrix? What, ultimately, are you trying to do?

Sign in to comment.

Products

Asked:

on 6 Mar 2015

Edited:

on 10 Mar 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!