Finding real roots of cubic polynomial

조회 수: 3 (최근 30일)
S. R. S.
S. R. S. 2020년 11월 17일
댓글: S. R. S. 2020년 11월 18일
I want to find the only one real roots of the equation and wrote the following code:
e = 0.3; gama = 0.8; damp = 0.0031; A = 12; M = 2*10^-4; mu = 0.05/M; St = 0.2; %parameters
Ur = 4:0.1:6;
for i = 1:size(Ur,2)
del(i) = 1/(St*Ur(i));
p(i,:)=roots([1 (-(1+2*del(i)^2-(2*damp*del(i)+(gama/mu))^2)+A*M) (-(-2*del(i)^2+(2*damp*del(i)+(gama/mu))^2-del(i)^4)-A*M*del(i)^2) (-del(i)^4)]);
r = p;
r = r(imag(r) == 0 );
end
Only one real root corresponding to each 'del(i)' is required but in some iteration, 'del(i)' leads to all three real roots of 'p'. (If all the three roots are real, max value of roots out of three would be considered)
How can I improve my code?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2020년 11월 17일
e = 0.3;
gama = 0.8;
damp = 0.0031;
A = 12;
M = 2*10^-4;
mu = 0.05/M;
St = 0.2;
AM = A*M;
%parameters
Ur = (4:0.1:6)';
n = numel(Ur);
del = 1./(St*Ur);
del2 = del.^2;
B = 2*del2-(2*damp*del+gama/mu).^2;
X = [ones(n,1) , AM-1-B , B+del2.^2-AM*del2 ,-del2.^2];
r = zeros(n,1);
for i = 1:n
p = roots(X(i,:));
r(i) = max(p(imag(p) == 0 ));
end
  댓글 수: 1
S. R. S.
S. R. S. 2020년 11월 18일
Thank you so much Andrei Bobrov for your brilliant work. The code served my purpose.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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