Solve Quartic Equation using root and deleting complex numbers from row

I have a 4x5 matrix, each row being the coeffecients of a quartic equation. I use the roots function to obtain a 4x4 matrix with the roots solution. Each row has two complex numbers, not always in the same column as another row. What is the best way to delete the complex numbers and keep the solutions on the same row, just reducing the cloumn size. For example taking: [1,2,1i,2i;3,4,3i,4i;5i,6i,5,6;7i,8i,7,8] and getting[1,2;3,4;5,6;7,8]

 採用された回答

Walter Roberson
Walter Roberson 2013 年 6 月 25 日

1 投票

reshape(YourMatrix(imag(YourMatrix == 0)), 2, []) .'

6 件のコメント

Chris Parry
Chris Parry 2013 年 6 月 25 日
I get the following error when I run your code: "Subscript indices must either be real positive integers or logicals."
Any idea what I'm doing wrong?
Matt J
Matt J 2013 年 6 月 25 日
A typo
imag(YourMatrix) == 0
Chris Parry
Chris Parry 2013 年 6 月 25 日
Ok, it gets rid of the complex numbers and generates a 4x2 matrix but instead of [1,2;3,4;5,6;7,8] i get [1,3;2,4;5,7;6,8] placing in column order instead of by rows. Any fixes?
Matt J
Matt J 2013 年 6 月 25 日
Pre-tranpose the matrix.
YourMatrix=YourMatrix.';
reshape(YourMatrix(imag(YourMatrix) == 0), 2, []).'
Better yet, organize your coefficients column-wise instead of row-wise and avoid transposing altogether.
Richard Brown
Richard Brown 2013 年 6 月 25 日
編集済み: Richard Brown 2013 年 6 月 25 日
You need to work with the transpose
At = YourMatrix.';
reshape(At(imag(At) == 0), 2, []).'
edit: Looks like Matt and I were writing the same comment at the same time
Chris Parry
Chris Parry 2013 年 6 月 25 日
Awesome! Thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by