Finding real roots of cubic polynomial

3 次查看(过去 30 天)
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