Matrices with Polynomial Entries functions

16 次查看(过去 30 天)
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 个评论
Maria
Maria 2015-3-10
编辑:Maria 2015-3-10
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.
Andrew Newell
Andrew Newell 2015-3-10
A symbolic expression would probably not be better if that's not your goal. I was just asking for clarification.

请先登录,再进行评论。

回答(2 个)

John D'Errico
John D'Errico 2015-3-10
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 个评论
Maria
Maria 2015-3-10
I need to add that now I am trying to compute only the determinant, and later I will compute the adjoint matrix
John D'Errico
John D'Errico 2015-3-10
编辑:John D'Errico 2015-3-10
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.

请先登录,再进行评论。


Andrew Newell
Andrew Newell 2015-3-10
编辑:Andrew Newell 2015-3-10
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 个评论
Maria
Maria 2015-3-10
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.
Andrew Newell
Andrew Newell 2015-3-10
编辑:Andrew Newell 2015-3-10
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by