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 Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by