Finding real roots of cubic polynomial

8 visualizaciones (últimos 30 días)
S. R. S.
S. R. S. el 17 de Nov. de 2020
Comentada: S. R. S. el 18 de Nov. de 2020
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?

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 17 de Nov. de 2020
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 comentario
S. R. S.
S. R. S. el 18 de Nov. de 2020
Thank you so much Andrei Bobrov for your brilliant work. The code served my purpose.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by