Finding real roots of cubic polynomial

3 Ansichten (letzte 30 Tage)
S. R. S.
S. R. S. am 17 Nov. 2020
Kommentiert: S. R. S. am 18 Nov. 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?

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by