Is it possible to avoid symbolic math for below query

1 回表示 (過去 30 日間)
Sakshi
Sakshi 2011 年 6 月 8 日
I have two matrices a and b. I need to find the value of x such that the determinant of (a + bx) is 0. The size of the matrices is 4x4. So in effect I need the roots of 4th order polynomial in variable x.
I did it by using the symbolic math tool box and below code :
syms l; char_matrix=a + l*b; determinant=det(char_matrix); R=solve(determinant);
This code is working but its taking too long for solving . Is there any way I can avoid symbolic math in such a situation as I think symbolic math takes longer than numerical math. Thank you for your time.

採用された回答

Andrew Newell
Andrew Newell 2011 年 6 月 8 日
As long as B has a nonzero determinant, you could recast it as an eigenvalue problem:
det(A+Bx) = det(B)*det(inv(B)*A+Ix) = 0,
where I is the identity, and you could use the following code:
x = -eig(B\A)
  2 件のコメント
Sakshi
Sakshi 2011 年 6 月 9 日
Thank you so much. If I understood correctly you have eliminated the need to use symbolic math toolbox for this case. It has saved several hours of my programming. Profusely thank you !!
Andrew Newell
Andrew Newell 2011 年 6 月 9 日
Glad to help.

サインインしてコメントする。

その他の回答 (2 件)

Jan
Jan 2011 年 6 月 8 日
You can do it numerically:
R = fzero(@(x) det(a + x * b), x0)
with a suiting initial value x0.
  1 件のコメント
Sakshi
Sakshi 2011 年 6 月 9 日
Thank you sir. However, I would not be able to give an initial value of x0. I will keep both the solutions in mind for future. Thank you once again for your time.

サインインしてコメントする。


John D'Errico
John D'Errico 2011 年 6 月 9 日
If A and B are known, then this is a simple problem using roots. I'll use my sympoly toolbox to show what is happening, and a way to solve it. Pick two arbitrary matrices.
>> A = magic(4)
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
>> B = round(rand(4)*5)
B =
1 2 2 3
4 3 3 3
5 2 2 1
0 2 4 5
See that the determinant is a polynomial of 4th degree in x.
>> det(A+B*x)
ans =
1125*x^2 + 406*x^3 + 4*x^4
>> roots(det(A+B*x))
ans =
0
0
-98.649
-2.851
There are 4 solutions here as you would expect. They need not all be real.

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by