how to solve many polynomial equations listed in a matrix?

조회 수: 8 (최근 30일)
Rikke
Rikke 2019년 3월 24일
댓글: Rikke 2019년 3월 25일
I have a matrix where each row is a polynomial equation:
A=[0.01 620.085 -3750
0.01 620.082 -3750
0.01 620.079 -3750
0.01 620.076 -3750];
I want to solve every row of matrix A. How can i do that, I tried:
for i=1:length(A)
I(i)=roots(A(i,:))';
end
I want to get the answer as follows:
I= [I(1,1) I(1,2)
I(2,1) I(2,2)
I(3,1) I(3,2)
I(4,1) I(4,2)];

채택된 답변

madhan ravi
madhan ravi 2019년 3월 24일
Roots = arrayfun( @(x) roots( A( x, : ) ), 1 : 4, 'un', 0 );
[ Roots{ : } ].'

추가 답변 (1개)

Matt J
Matt J 2019년 3월 24일
편집: Matt J 2019년 3월 24일
Here's a method withoutt loops,
[a,b,c]=deal(A(:,1),A(:,2),A(:3));
D=sqrt(b.^2-4.*a.*c);
I=[-b-D, -b+D]./(2.*a);

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by